Skip to content

Instantly share code, notes, and snippets.

@tcelovsky
Last active July 9, 2021 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcelovsky/a62b16ed73af772b7180d03e98ce5f4c to your computer and use it in GitHub Desktop.
Save tcelovsky/a62b16ed73af772b7180d03e98ce5f4c to your computer and use it in GitHub Desktop.
O(n) Example
const numbers = [1, 2, 3, 4, 5]
function logTwice(numbers) {
for (let i = 0; i < numbers.length; i++) { //O(n) --> linear time (run time increases at the same pace as the input)
console.log(numbers[i]); //O(1) --> constant time (basic operation)
}
for (let i = 0; i < numbers.length; i++) { //O(n) --> linear time (run time increases at the same pace as the input)
console.log(numbers[i]); //O(1) --> constant time (basic operation)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment