Created
October 20, 2021 01:19
-
-
Save tayhsn/a3628707027ff82b986710294f6cf91f to your computer and use it in GitHub Desktop.
Complexidade de algoritmo
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
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