Exercises
The following exercises provide you with the opportunity to practice with arrays. The solutions to these exercises are found in the section .
- For an array containing 100 elements, provide the number of steps the following operations would take:
- Reading
- Searching for a value not contained within the array
- Insertion at the beginning of the array
- Insertion at the end of the array
- Deletion at the beginning of the array
- Deletion at the end of the array
- For an array-based set containing 100 elements, provide the number of steps the following operations would take:
- Reading
- Searching for a value not contained within the set
- Insertion of a new value at the beginning of the set
- Insertion of a new value at the end of the set
- Deletion at the beginning of the set
- Deletion at the end of the set
- Normally the search operation in an array looks for the first instance of a given value. But sometimes we may want to look for every instance of a given value. For example, say we want to count how many times the value “apple” is found inside an array. How many steps would it take to find all the “apple”s? Give your answer in terms of N.
Copyright © 2024, The Pragmatic Bookshelf.