Ask Question
29 June, 05:44

What unit of time does the variable n refer to if an algorithm has O (n) time complexity?

+1
Answers (1)
  1. 29 June, 06:53
    0
    Input size.

    Explanation:

    When we measure the time complexity of an algorithm we always find it in big-oh notation like O (n). The n always represents the input size.

    Suppose the size of an array is 64 and we have to find an element in this array using binary search and linear. As we know the worst case time complexity of the binary search is O (logn).

    t (n) = O (log64)

    t (n) = O (6).

    So the loop will run maximum of 6 times.

    The worst case time complexity of linear search is O (n).

    t (n) = O (n)

    t (n) = O (64).

    So the loop will run maximum of 64 times.

    In both the cases n is the size of the array.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What unit of time does the variable n refer to if an algorithm has O (n) time complexity? ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers