Recursion
In what scenario would merge sort be preferred over quicksort when dealing with arrays?
If random access speed is critical since merge sort has better cache performance due to sequential access patterns versus quicksort’s scattered accesses.
When working with extremely small datasets where overhead becomes negligible compared to quicksort's complexity advantages.
Merge sort would be preferred for arrays that need stable sorting or are partially sorted since its performance does not degrade like quicksort's might due to poor pivot choices.
If minimizing code length is essential because merge sort implementations typically require fewer lines than quicksort variants do.
For recursively searching for an item within an unbalanced binary tree where node distribution is skewed heavily on one side, what would be primarily affected compared to a balanced binary tree?
Search complexity remains unchanged as each node still has only two children maximum regardless of balance status.
Average-case search complexity increases due to fewer opportunities for early termination of recursion on one side of the tree.
Space complexity improves as potential stack overflow risk declines due to reduced depth in heavily populated branches compared with evenly distributed nodes over all levels in balanced trees.
The necessity for using tail recursion diminishes since stack size becomes less predictable with skewness in node distribution.
When implementing binary search recursively, what happens at each step if the target is not found?
The range within which to search is halved.
The entire collection gets sorted again before searching continues.
All elements in the collection are compared with the target again.
An element is added to the collection being searched through.
What value do the search algorithms return when an item is not found?
null
-1
0
Error message
What does it mean when a sorting algorithm is stable?
Its performance doesn't change with different input sizes
Equal elements retain their relative order after sorting
It uses minimal additional memory during its operation
It can sort any type of data
Which sorting algorithm typically uses recursion?
Quick sort.
Bubble sort.
Selection sort.
Insertion sort.
What is the space complexity of iterative mergesort on an array with 'n' distinct elements?

How are we doing?
Give us your feedback and let us know how we can improve
In the recursive binary search algorithm, what is the base case when the item is not found?
n == array.get(middle)
n < array.get(middle)
left > right
middle == 0
What type of algorithm uses divide-and-conquer by dividing into two halves at each step?
Selection sort
Merge sort
Insertion sort
Bubble sort
Which of these scenarios would most likely result in a stack overflow error when using a recursive binary search on an array?
The array being searched is already sorted before applying the binary search algorithm.
The search space is halved on each recursive call with proper termination conditions.
An iterative version of binary search is used instead of a recursive one.
The base case is improperly defined, causing infinite recursion.