Skip to content

Instantly share code, notes, and snippets.

@tayhsn
Created October 20, 2021 01:19
Show Gist options
  • Save tayhsn/a3628707027ff82b986710294f6cf91f to your computer and use it in GitHub Desktop.
Save tayhsn/a3628707027ff82b986710294f6cf91f to your computer and use it in GitHub Desktop.
Complexidade de algoritmo
const a = [1, 2, 3, 4, 2, 1]
const b = [3, 2, 5, 3]
function intersection(a, b) {
let numbers = new Set()
let contador =0;
for(var i=0; i < a.length -1; i++) {
for(var j=0; j < b.length -1; j++) {
contador++
if(a[i] == b[j]) {
numbers.add(a[i])
}
}
}
console.log(contador)
return numbers
}
// a compĺexidade do algoritmo é N*M
// onde n é o tamanho da lista a
// m é o tamanho da lista b
intersection(a, b)
----------------------
const c = [1, 2, 3, 4, 5, 8]
const d = 6
function findMatch(c, d){
let match = false;
let contador = 0;
// return a.includes(b) ? true : false
for(var i=0; i < a.length; i++){
contador++;
if(a[i] == b) {
match = true
}
}
console.log(contador)
return match;
}
//a complexidade é Y, onde y é o tamanho da lista c.
console.log(findMatch(c, d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment