Question 1
EasyWhat is the worst-case time complexity of bubble sort?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the worst-case time complexity of bubble sort?
O(n log n)
O(n²)
O(log n)
O(n)
Answer: B
Each of up to n passes compares adjacent pairs across the array.
Which sorting algorithm repeatedly selects the minimum of the unsorted part and puts it in place?
Quick sort
Selection sort
Insertion sort
Merge sort
Answer: B
Selection sort always makes O(n²) comparisons but at most n − 1 swaps.
What is the time complexity of merge sort in every case?
O(n)
O(n log n)
O(n²)
O(log n)
Answer: B
It always splits in half and merges in linear time, whatever the input order.
Which sort works like sorting playing cards in your hand?
Heap sort
Quick sort
Insertion sort
Radix sort
Answer: C
Each new card (element) is inserted into its correct place among the already sorted ones.
What is a stable sorting algorithm?
One that uses O(1) memory
One that keeps equal elements in their original relative order
One that runs in O(n)
One that never crashes
Answer: B
Stability matters when sorting records by one key after another, e.g. by name then by department.
What is the output of this code?
print(sorted([5, 2, 8, 1, 9]))
[5, 2, 8, 1, 9]
[1, 5, 2, 8, 9]
Answer: C
sorted() returns a new list in ascending order.
What is the best-case time complexity of insertion sort (already sorted input)?
O(n log n)
O(1)
O(n²)
O(n)
Answer: D
Each element is compared once with its predecessor and stays put.
Which sorting algorithm repeatedly swaps neighbouring elements that are in the wrong order?
Heap sort
Merge sort
Bubble sort
Quick sort
Answer: C
Large elements 'bubble' to the end, one pass at a time.
Which sorting algorithm splits the array into halves, sorts each half and then merges them?
Counting sort
Selection sort
Bubble sort
Merge sort
Answer: D
It is the classic divide-and-conquer sort.
Which sorting algorithm chooses a pivot and partitions the array around it?
Radix sort
Quick sort
Insertion sort
Merge sort
Answer: B
Smaller elements go to one side of the pivot and larger ones to the other.
[1, 2, 5, 8, 9]
[9, 8, 5, 2, 1]