Optimizing For Optimistic Scenarios


Exercises for Chapter #6 of A Common-Sense Guide To Data Structures and Algorithms

Get The Book!

Chapter Exercises


Exercise #1

Regarding the array [50, 60, 70, 20, 30, 10]:

  1. Describe the exact steps that Insertion Sort would take on the array.
  2. How many comparisons occurred?
  3. How many swaps occurred?

Exercise #2

Regarding the array [10, 20, 30, 40, 50, 60]:

  1. Describe the exact steps that Insertion Sort would take on the array.
  2. How many comparisons occurred?
  3. How many swaps occurred?

Exercise #3

Regarding the array [60, 50, 40, 30, 20, 10]:

  1. Describe the exact steps that Insertion Sort would take on the array.
  2. How many comparisons occurred?
  3. How many swaps occurred?

Exercise #4

Describe in the following cases whether Bubble Sort is more efficient, or Insertion Sort is more efficient.

  1. The best-case scenario.
  2. An average-case scenario.
  3. The worst-case scenario.

Let's Get In Touch!


Join the forum on The Pragmatic Programmers website to join in on the conversation about this book, or email Jay Wengrow, author of the book and this website directly.