When can an algorithm have square root(n) time complexity?

前端 未结 6 981
攒了一身酷
攒了一身酷 2021-02-01 15:11

Can someone give me example of an algorithm that has square root(n) time complexity. What does square root time complexity even mean?

6条回答
  •  失恋的感觉
    2021-02-01 15:44

    This link provides a very basic beginner understanding of O(\sqrt{n}) i.e., O(sqrt n) time complexity. It is the last example in the video, but I would suggest that you watch the whole video.

    https://www.youtube.com/watch?v=9TlHvipP5yA&list=PLDN4rrl48XKpZkf03iYFl-O29szjTrs_O&index=6

    The simplest example of an O(\sqrt{n}) i.e., O(sqrt n) time complexity algorithm in the video is:

    p = 0;
    
    for(i = 1; p <= n; i++)
    {
        p = p + i;
    }
    

    Mr. Abdul Bari is reknowned for his simple explanations of data structures and algorithms.

提交回复
热议问题