Data Structures & AlgorithmsHardGATE CS · ICPC regional
Which data structure supports inserting values and reporting the k-th smallest value in O(log n) time each?
- A. Order-statistic tree or Fenwick tree over compressed values
- B. Plain singly linked list
- C. Stack
- D. Hash set alone
Correct answer: A. Order-statistic tree or Fenwick tree over compressed values
A Fenwick tree (or order-statistic tree) keeps counts per value and descends to locate the k-th element in logarithmic time. A hash set has no order information.
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 algorithm counts occurrences of a pattern p inside a text t in O(|t| + |p|) time?
- Which algorithm finds the longest palindromic substring of a string in linear time?
- Which technique detects whether an array contains a non-empty subarray with sum zero in O(n) expected time?
- An array of 200000 integers may contain negative values, and you must count its contiguous subarrays whose sum equals K in near-linear…
- For a string of length 10^6 and a pattern of 20 letters, you need the shortest substring containing every pattern letter with…
- Given an array of 10^6 values and window size k, you need the maximum over all windows of the window minimum. What is the most suitable…