Optimizing Code With And Without Big O


Exercises for Chapter #5 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 Selection 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 Selection 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 Selection Sort would take on the array.
  2. How many comparisons occurred?
  3. How many swaps occurred?

Exercise #4

How would you describe in Big O Notation:

  1. An algorithm that takes 2N steps?
  2. An algorithm that takes log(N / 2) steps?
  3. An algorithm that always takes 2,532 steps?

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.