Suppose you want to implement a function that takes an array of integers and returns the maximum. Which sorting algorithm would you use in the following two scenarios - bubble sort or merge sort?
When the length of the array is less than 1000 , we can use bubble sort because the worst case running time for bubble sort is \( O(n^{2}) \) with memory usage \( O(1) \).
When the length of the array is greater than 1000 , we can use merge sort because this is very stable with the worst case running time \( O(nlogn) \).