Search Menu

Review of Sorting

Sorting Review

Table of Contents

How to Cite This SparkNote

1. Consider the following consecutive configurations of a list while it it being sorted:
  • (4, 5, 3, 1)
  • (4, 5, 3, 1)
  • (4, 3, 5, 1)
  • (4, 3, 1, 5)
What sorting algorithm is being used?

2. What is the best case running time of Bubble Sort?

3. Why is log(n) often a term in the efficiency expressions for divide and conquer algorithms?

4. What sort might you use if you know that your data will be pretty much in order to begin with and why would you use that sort?

5. Imagine that we run quick sort on an already ordered list, picking the pivot by taking the first element. What problem do we run into?

6. Why are merge sort and quick sort known as "divide and conquer" algorithms?

7. Why might it seem counterintuitive that heap sort can run so efficiently?

8. Merge sort is O(nlog(n)) . Where does the n term come from?

9. Which of the following is a proper heap?

10. For merge sort to merge the following two arrays: (1, 4, 5, 8) and (3, 7, 9, 13), what comparisons have to take place?

11. Consider a sorting algorithm that checks all possible configurations of a list until it finds one that is in order. This algorithm will sort a list correctly, but is very inefficient. What is its big-O notation?

12. In what case is the algorithm described above as efficient as bubble sort?

13. In what case is the algorithm described above more efficient than selection sort?

14. Consider the intermediate configurations of an array being sorted below. What sort is being used?
  • (4, 5, 2, 1, 7)
  • (1, 5, 2, 4, 7)
  • (1, 2, 5, 4, 7)

15. What sorting algorithm might you choose for the following list? Why? (1, 2, 3, 6, 5, 9)

16. True of false: merge sort and quick sort can only be used on lists whose length is a power of 2.

17. How many comparisons would it take merge sort to merge the following lists: (1, 2, 3, 4, 5) and (6, 7, 8, 9, 10)?

18. True or false: selection sort can sometimes run as fast as O(n) .

19. The intermediate configurations below are characteristic of which sorting algorithm?
  • (5, 1, 4, 8, 2)
  • (1, 5, 4, 8, 2)
  • (1, 4, 5, 8, 2)
  • (1, 4, 5, 2, 8)

20. Why would it be a bad idea to implement heap sort using a heap data structure that didn't support random access?

21. Imagine the following strategy for picking a pivot in quick sort: scan through half the data set, and use the median value as the pivot. Why is this a bad strategy?

22. Imagine the following specification of a comparison function. If the two numbers passed in have an equal number of digits, they are equal. Otherwise, the one with the larger number of digits is greater. Which of the following lists are sorted with respect to this comparison function?

23. Why are we so concerned with the efficiencies of sorting algorithms?

24. Imagine a comparison function for complicated objects. Why might efficiency calculations for a sort using this comparison function be misleading?

25. Consider the following intermediate configurations of a list being sorted. What sorting algorithm is being used?
  • (5, 2, 8, 1, 9)
  • (1, 5, 2, 8, 9)
  • (1, 2, 5, 8, 9)

26. What is the first swap insertion sort would make on the following list? (5, 3, 4, 9, 1)

27. What is the first swap selection sort would make on the following list? (5, 3, 4, 9, 1)

28. What kind of data structure would make insertion sort particularly inefficient?

29. Imagine a situation where most of the data to be sorted starts in roughly reverse order. Why would this not be a good situation to use bubble sort?

30. What simple modification could be made to bubble sort to make it efficient in the situation described above?

31. Why would bubble sort be more efficient on the list (1, 2, 3, 4, 5, 6, 7) than selection sort?

32. When using quick sort, why is it common to switch to another sort when the lists being sorted are small?

33. In what situation might heap sort be useful?

34. What makes heap sort attractive as opposed to quick sort?

35. Why is quick sort's name misleading?

36. True or false: bubble sort gains efficiency by splitting the data in half.

37. Why is sorting important to the process of searching?

38. True or false: for some data sets, quick sort will be slower than bubble sort.

39. How long does re-heaping take?

40. True or false: selection sort's efficiency is independent of the data being sorted.