August 2024
Intermediate to advanced
516 pages
11h 47m
English
Here’s some typical JavaScript code that prints all the items from a list:
| | let things = ['apples', 'baboons', 'cribs', 'dulcimers']; |
| | |
| | for (const thing of things) { |
| | console.log(`Here's a thing: ${thing}`); |
| | } |
How would we describe the efficiency of this algorithm in Big O notation?
The first thing to realize is that this is an example of an algorithm. While it may not be fancy, any code that does anything at all is technically an algorithm—it’s a particular process for solving a problem. In this case, the problem is that we want to print all the items from a list. The algorithm we use to solve this problem is a for loop containing a console.log statement.
To break this down, we need to analyze how many ...
Read now
Unlock full access