Exercises
The following exercises provide you with the opportunity to practice with algorithms in practical situations. The solutions to these exercises are found in the section Chapter 7.
-
Use Big O notation to describe the time complexity of the following function. The function returns true if the array is a 100-sum array, and false if it is not.
A 100-sum array meets the following criteria:
- Its first and last numbers add up to 100.
- Its second and second-to-last numbers add up to 100.
- Its third and third-to-last numbers add up to 100, and so on.
Here’s the function:
function oneHundredSum(array) { if (array.length % 2 !== 0 || array.length === 0) { return false; } let leftIndex = 0; let rightIndex = array.length - ...
Get A Common-Sense Guide to Data Structures and Algorithms in JavaScript, Volume 1 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.