Data Structures & AlgorithmsEasyCognizant · Capgemini pattern
What is the worst-case time complexity of binary search on a sorted array of n elements?
- A. O(n log n)
- B. O(1)
- C. O(log n)
- D. O(n)
Correct answer: C. O(log n)
Each comparison halves the search range, so at most about log₂ n + 1 comparisons are needed: O(log n). O(n) is linear search.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Which of these sorting algorithms is stable in its standard implementation?
- What is the time complexity of inserting a new node at the head of a singly linked list of n nodes?
- With a good hash function and a bounded load factor, what is the average time to search for a key in a hash table?
- What is the postfix form of the infix expression A + B C?
- What is the value of the postfix expression 6 2 3 + − 3 8 2 / + ?
- A circular queue is implemented in an array of size 10 and one slot is always kept empty so that 'full' and 'empty' can be told apart. How…