Why Data Structures Matter


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

Get The Book!

Chapter Exercises


Exercise #1

For an array with a size of 100 elements, provide the number of steps that the following operations would take for:

  1. Reading
  2. Searching
  3. Insertion at the very beginning of the array
  4. Insertion at the very end of the array
  5. Deletion at the very beginning of the array
  6. Insertion at the very end of the array

Exercise #2

For an array-based set with a size of 100 elements, provide the number of steps that the following operations would take for:

  1. Reading
  2. Searching
  3. Insertion at the very beginning of the set
  4. Insertion at the very end of the set
  5. Deletion at the very beginning of the set
  6. Insertion at the very end of the set

Exercise #3

For a regular array, how many steps would it take to search for all of a certain item. For example, we want to search for every 55 contained within an array to determine how many times it appears. Give your answer in terms of N.

Exercise #4

How many steps would it take to delete all the 72’s from the following array: [72, 44, 66, 2019, 72, 55, 101, 72, 99, 2]. (The array would become [44, 66, 2019, 55, 101, 99, 2].)

Exercise #5

How many steps would it take to insert a 44 at both the beginning and end of the following array: [5, 6, 7, 8, 9, 10]. (The insertions would turn the array into: [44, 5, 6, 7, 8, 9, 10, 44].)

Exercise #6

Use your favorite object-oriented programming language to create a class that represents an array-based set. It should include functions/methods that serve as the key operations: Read, search, insert, and delete. Ensure that the insert operation will not insert duplicate values.

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.