Computer Science EngineeringHard
Quicksort that always picks the first element as pivot runs in what time on an already sorted array?
- A. O(n log n)
- B. O(n)
- C. O(n^2)
- D. O(log n)
Correct answer: C. O(n^2)
Each partition splits into sizes 0 and n-1, giving n + (n-1) + ... = O(n^2).
Practise more Algorithms, Data Structures & Programming (ISRO CS) questionsAlgorithms, Data Structures & Programming (ISRO CS): notes and key points
More Algorithms, Data Structures & Programming (ISRO CS) questions
- Dijkstra's algorithm using a binary heap and adjacency lists runs in
- For n a power of 2, what is the Theta bound of the loop: x=0; for(i=1;i<=n;i=2) for(j=0;j<i;j++) x++;
- How many leaf nodes does a binary heap stored in an array of 15 elements have?
- A table of size 7 uses h(k) = k mod 7 with linear probing. After inserting 15, 22, 8 and 1 in that order, at which index does key 1 reside?
- The Bellman-Ford single-source shortest path algorithm has running time
- What is the Theta bound of: for(i=1;i<=n;i++) for(j=i;j<=n;j+=i) count++;