Data Structures & AlgorithmsModerateGATE CS · Product placement
For the sorted array [1, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10, 11] (0-based), what are lower_bound(9) (first index with value ≥ 9) and upper_bound(9) (first index with value > 9), and hence how many times does 9 occur?
- A. 8 and 9; count 1
- B. 7 and 9; count 2
- C. 7 and 10; count 3
- D. 7 and 8; count 1
Correct answer: B. 7 and 9; count 2
lower_bound is the first 9 at index 7; upper_bound is one past the last 9, index 9. Their difference 2 is the count — both found by O(log n) binary searches.
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
- Keys 13, 14, 24, 27, 70, 76, 91, 15 are inserted in this order into an empty hash table of size 13 with h(k) = k mod 13 and linear…
- Keys 55, 63, 47, 69, 16, 97, 39, 99, 77, 43 are inserted in this order into a chained hash table with 7 buckets, h(k) = k mod 7, and each…
- Floyd's cycle detection on a list whose last node links back into the list. What does this print (meeting value, cycle-start value, cycle…
- What does this loop-counting code print? (Python) python n, c = 70000, 0 i = 2 while i <= n: c += 1 i = i i print(c)
- In the binary array [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0] you may flip at most 2 zeros to ones. What is the length of the longest run…
- Evaluate an infix expression of single digits with two stacks (operands and operators, usual precedence, left-associative). What is…