let firstArr = ["Haresh"]
let secArr = ["Haresh","Hitesh","Jay"]
let bigArr = new Array(1000000).fill("Haresh Lakhwani")
/*
Linear Time O(n) : Number of operation grows with number of inputs : THE MORE NUMBER OF INPUT THE MORE TIME IT WILL TAKE TO PERFORM
THOSE OPERATION : EX
*/
// Time Complexity O(1) => 1 input 1 operation => O(n)
for(let i=0 ; i < firstArr.length ; i++){
if(firstArr[i] === "Haresh"){
console.log("Found Haresh")
}
}
// Time Complexity O(3) => 3 input 3 operation => O(n)
for(let i=0 ; i < secArr.length ; i++){
if(firstArr[i] === "Jay"){
console.log("Found Jay")
}
}
// Time Complexity O(1000000) => 1000000 input 1000000 operation => O(n)
for(let i=0 ; i < bigArr.length ; i++){
if(firstArr[i] === "Hitesh"){
console.log("Found Hitesh")
}
}
/*
O(1) Constant time : Number of operations are not depended on number of inputs so no matter how big or small inputs get number of operations are
always going to fix
*/
const boxes = [0,1,2,3,4,5,6,7,8]
// Number of operation O(1) => O(1) => CONSTANT TIME BECAUSE NUMBER OF OPERATION DOES NOT DEPENDS ON INPUTS
function findFirstBox(){
console.log(boxes[0])
}
// Number of operation O(2) => O(1) => CONSTANT TIME BECAUSE NUMBER OF OPERATION DOES NOT DEPENDS ON INPUTS
function findFirstAndSecBox(){
console.log(boxes[0])
console.log(boxes[1])
}
// Number of operation O(2) => O(1) => CONSTANT TIME BECAUSE NUMBER OF OPERATION DOES NOT DEPENDS ON INPUTS
function findFirstAndLastBox(){
console.log(boxes[0])
console.log(boxes[boxes.length -1])
}
findFirstBox()
findFirstAndSecBox()
findFirstAndLastBox()