Rule 2 of Big O | Remove the Constants

Run Settings
LanguageJavaScript
Language Version
Run Command
function printFirstItemThenFirstHalfThenSayHi100Times(items) { console.log(items[0]); var middleIndex = Math.floor(items.length / 2); var index = 0; while (index < middleIndex) { // middleindex is halved in the previous step console.log(items[index]); index++; } for (var i = 0; i < 100; i++) { // here we don't care about the items input cz the constant length is give that 100 console.log('hi'); } } O(1 + n/2 + 100) = O(101 + n/2) = O(1 + n/2) // RULE 2 for Big O states to REMOVE THE CONSTANTS O(n + 1) = O(n)
Editor Settings
Theme
Key bindings
Full width
Lines