Big-θ (Big-Theta) notation
We'll cover the following...
Let's look at a simple implementation of linear search (in the language of your choice):
var doLinearSearch = function(array, targetValue) {for (var guess = 0; guess < array.length; guess++) {if (array[guess] === targetValue) {return guess; // found it!}}return -1; // didn't find it};
Let's denote the size of the array by array[guess]
with targetValue
; possibly return the value of guess
; and increment guess
. Each of these little computations takes a constant amount of time each time it executes. If the for-loop iterates
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy