Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,045 changes: 1,045 additions & 0 deletions modulo8/complexidade-de-algoritmos/package-lock.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions modulo8/complexidade-de-algoritmos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "complexidade-algoritmos",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"linear": "clear && tsnd --transpile-only --ignore-watch node_modules ./src/linear",
"polynomial": "clear && tsnd --transpile-only --ignore-watch node_modules ./src/polynomial",
"logarithmic": "clear && tsnd --transpile-only --ignore-watch node_modules ./src/logarithmic",
"exponential": "clear && tsnd --transpile-only --ignore-watch node_modules ./src/exponential"
},
"author": "Labenu",
"license": "ISC",
"devDependencies": {
"@types/node": "^15.3.0",
"ts-node-dev": "^1.1.6",
"typescript": "^4.2.4"
}
}
15 changes: 15 additions & 0 deletions modulo8/complexidade-de-algoritmos/src/exponential/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { login } from "./login"

const crackPassword = (
passwordLength: number
) => {

for (let i = 0; i < 10 ** passwordLength; i++) {
console.count()

const token = login(i)
if (token) return token
}
}

crackPassword(4)
5 changes: 5 additions & 0 deletions modulo8/complexidade-de-algoritmos/src/exponential/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const login = (
password: number
) => password === 12345678
? "token"
: undefined
7 changes: 7 additions & 0 deletions modulo8/complexidade-de-algoritmos/src/linear/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const printUntil = (n: number) => {
for (let i = 0; i < n; i++) {
console.log({ i })
}
}

printUntil(100)
26 changes: 26 additions & 0 deletions modulo8/complexidade-de-algoritmos/src/logarithmic/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const binarySearch = (arr: number[], n: number) => {

let start = 0, end = arr.length - 1;

while (start <= end) {
console.count();

let mid = Math.floor((start + end) / 2);

if (arr[mid] === n) return n;

else if (arr[mid] < n)
start = mid + 1;
else
end = mid - 1;
}
}

const item = binarySearch(
[
1, 2, 3, 4, 5, 6, 7, 8,
],
9
)

console.log(item);
20 changes: 20 additions & 0 deletions modulo8/complexidade-de-algoritmos/src/polynomial/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const insertionSort = (array: number[]) => {

for (let j = 1; j < array.length; j++) {
const value = array[j];
let i = j - 1;
while (i >= 0 && array[i] >= value) {
array[i + 1] = array[i];
i--;
}
array[i + 1] = value
}
};

const numbers = [
8, 7, 6, 5, 4, 3, 2, 1,
]

insertionSort(numbers)

console.log(numbers);
14 changes: 14 additions & 0 deletions modulo8/complexidade-de-algoritmos/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"sourceMap": true,
"outDir": "./build",
"rootDir": "./src",
"removeComments": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}