Skip to content

Instantly share code, notes, and snippets.

@hi2rashid
Last active January 25, 2020 10:54
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 hi2rashid/c4a27a229775dee367a011405bb59391 to your computer and use it in GitHub Desktop.
Save hi2rashid/c4a27a229775dee367a011405bb59391 to your computer and use it in GitHub Desktop.
Big O(N^2) with simple For loop - Colored 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<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
@hi2rashid
Copy link
Author

Output will look like

image

@hi2rashid
Copy link
Author

hi2rashid commented Jan 25, 2020

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)

@hi2rashid
Copy link
Author

j<N

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment