Data Structures & AlgorithmsModerateTCS Digital · Infosys SP
Assertion (A): Binary search runs in O(log n) time on a sorted singly linked list. Reason (R): Binary search halves the search range in each step.
- A. A is true, but R is false
- B. Both A and R are true, and R is the correct explanation of A
- C. A is false, but R is true
- D. Both A and R are true, but R is not the correct explanation of A
Correct answer: C. A is false, but R is true
Halving the range is true, but reaching the middle of a linked list takes a linear walk, so the total is Θ(n) (n/2 + n/4 + …). A is false.
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
- Two strings are isomorphic if characters can be replaced one-to-one to turn one into the other. Version A checks both directions; version…
- A monotonic deque reports the maximum of every window of size 3 in [0, 13, 9, 1, 2, 18, −1, −3, 17]. What is the SUM of all reported…
- An array of 8 zeros (indices 0–7) receives range updates with a difference array (diff[l] += v, diff[r + 1] −= v, then prefix-sum): add 5…
- What is the minimum number of swaps (of any two elements) needed to bring all the 1s of [1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0] together into…
- Reverse the order of words, collapsing multiple spaces. What is printed? python s = " new the is oil " w = s.split() print("|" + "…
- You must answer many queries 'sum of A[l..r]' while also updating single elements, on an array of n elements. Which choice gives O(log n)…