August 2024
Intermediate to advanced
516 pages
11h 47m
English
Imagine you’re writing a program that allows customers to order fast food from a restaurant, and you’re implementing a menu of foods with their respective prices. You could, technically, use an array:
| | menu = [ |
| | ["french fries", 0.75], |
| | ["hamburger", 2.5], |
| | ["hot dog", 1.5], |
| | ["soda", 0.6] |
| | ] |
This array contains several subarrays, and each subarray contains two elements. The first element is a string representing the food on the menu, and the second element represents the price of that food.
As you learned in Chapter 2, Why Algorithms Matter, if this array were unordered, searching for the price of a given food would take O(N) steps since the computer would have to perform a linear ...
Read now
Unlock full access