Given that merge sort splits the array into 2, performs a recursive call on each of the 2 arrays, and repeats until the base case of 1 or less items in an array is reached, how many levels of recursion are there and why?
Given that merge sort splits the array into 2, performs a recursive call on each of the 2 arrays, and repeats until the base case of 1 or less items in an array is reached, how many levels of recursion are there and why?
Answer:
log₂n levels.
Each level results in a split of an array n into arrays of size n/2.
The number of levels equals the number of times you split n/2 until you reach 1 or less.
The definition of log₂n is the number of times n is divided by two (split) until it reaches a value of 1 or less.