Skip to content

Commit 1d8bbd9

Browse files
author
Nilton Lopes
committed
Complexidade O(n)
1 parent 596e9d0 commit 1d8bbd9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Um algoritmo de complexidade O(n) terá sua complexidade aumentada a medida que n (entrada) for aumentando.
3+
*/
4+
5+
function sequentialSearch(array, value) {
6+
let cost = 0
7+
for (let i = 0; i < array.length; i++) {
8+
cost++
9+
if (value === array[i]) {
10+
console.log(
11+
`Cost for sequencialSearch with input size ${array.length} is ${cost}`
12+
)
13+
return i
14+
}
15+
}
16+
17+
console.log(
18+
`Cost for sequencialSearch with input size ${array.length} is ${cost}`
19+
)
20+
return -1
21+
}
22+
23+
const arr = require("./data")
24+
25+
sequentialSearch(arr, 991452)

src/js/complexity-of-algorithms/data.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)