December 2023
Intermediate to advanced
504 pages
11h 43m
English
The following exercises provide you with the opportunity to practice with space constraints. The solutions to these exercises are found in the section Chapter 19.
Following is the word builder algorithm we encountered in Word Builder. Describe its space complexity in terms of Big O:
| | def word_builder(array): |
| | collection = [] |
| | |
| | for index_i, i in enumerate(array): |
| | for index_j, j in enumerate(array): |
| | if index_i != index_j: |
| | collection.append(i + j) |
| | |
| | return collection |
Following is a function that reverses an array. Describe its space complexity in terms of Big O:
| | def reverse(array): |
| | new_array = [] |
| | |
| | for value in array: |
| | new_array.insert(0, value) |
| | |
| | return new_array |
Create a new function ...
Read now
Unlock full access