Last active
January 25, 2020 10:54
-
-
Save hi2rashid/c4a27a229775dee367a011405bb59391 to your computer and use it in GitHub Desktop.
Big O(N^2) with simple For loop - Colored console output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let N = 10; | |
let ispace = ""; | |
let jspace = ""; | |
let counter = 0; | |
for(let i=0; i<N;i++){ | |
ispace += " "; | |
console.log("%c i is " + ispace + i,'background: #222; color: #bada55') | |
for(let j=0; j<i;j++) { | |
jspace += " "; | |
console.log("j is " + jspace + j) | |
counter++; | |
} | |
} | |
console.log("Total Executions of i+j counter "+ counter) | |
//https://jsbin.com/jaguhebeyu/edit?js,console,output |
let N = 10;
let ispace = "";
let jspace = "";
let counter = 0;
for(let i=0; i<N;i++){
ispace += " ";
console.log("%c i is " + ispace + i,'background: #222; color: #bada55')
for(let j=0; **j<N**;j++) {
jspace += " ";
console.log("j is " + jspace + j)
counter++;
}
}
console.log("Total Executions of i+j counter "+ counter)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output will look like