Which sorting algorithm bubble sort or merge sort to find the maximum element in an array
  • bubblesort
  • mergesort
  • array
  • sorting
  •   
  • Posted: 5 years ago
  • Updated: 4 years ago
  • Edit
  • answers (1)
  • views (2731)

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
  • When the length of the array is greater than 1000


Posted Answers

  • 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) \).
  • You need to Sign In to post your solution.