-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerformance.js
More file actions
55 lines (52 loc) · 2.18 KB
/
Performance.js
File metadata and controls
55 lines (52 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { binarySearch } = require("./Binary Search/BinarySearch")
const { bogoSort } = require("./BogoSort/BogoSort")
const { bucketSort } = require("./Bucket Sort/BucketSort")
const { countingSort } = require("./Counting Sort/CountingSort")
const { Tree } = require("./Fun with trees/tree")
const { Heap } = require("./Heap/Heap")
const { insertionSort } = require("./Insertion Sort/InsertionSort")
const { linearSearch } = require("./Linear Search/LinearSearch")
const { mergeSort } = require("./Merge Sort/MergeSort")
const { pidgeonHoleSort } = require("./PidgeonHole Sort/PidgeonHoleSort")
const { quickSort } = require("./Quick Sort/QuickSort")
const { selectionSort } = require("./Selection sort/SelectionSort")
const { runSort, runNotInPlaceSort, randomArray, randomValueInsideArray, runSearch } = require("./_Miscellaneous/misc")
console.log("==== SORTING ====")
console.log("Inserion Sort O(n^2)")
//runSort(512000, insertionSort)
console.log("Selection Sort O(n^2)")
//runSort(512000, selectionSort)
console.log("Merge Sort 𝚯(nlog(n))")
//runNotInPlaceSort(1024000, mergeSort)
console.log("Quick Sort 𝚯(nlog(n)) | O(n^2)")
runSort(1024000, quickSort)
console.log("Heap Sort 𝚯(nlog(n))")
runNotInPlaceSort(128000, Heap.heapSort)
console.log("PidgeonHole Sort O(n)")
runSort(10000000, pidgeonHoleSort)
console.log("Bucket Sort O(n)")
runSort(10000000, bucketSort)
console.log("Counting Sort O(n)")
runSort(10000000, countingSort)
console.log("BogoSort O(n!)")
runSort(10, bogoSort, 50)
console.log("==== SEARCHING ====")
let a = randomArray(512000, 512000)
let key = randomValueInsideArray(a)
console.log("Linear Search O(n)")
runSearch(a, key, linearSearch)
a = randomArray(1024000, 1024000)
key = randomValueInsideArray(a)
quickSort(a)
console.log("Binary Search O(log(n))")
runSearch(a, key, binarySearch)
console.log("==== TREES ====")
let tree = new Tree(10, 5, false)
Tree.map(tree, (x) => {return x*2})
console.log("Sum:" + Tree.reduce(tree, (x) => {return x}))
let max = Tree.max(tree)
console.log("Max:" + max)
let min = Tree.min(tree)
console.log("Min:" + min)
console.log("Search:" + Tree.search(max))
console.log(`Path from ${max} to ${min}: ` + Tree.printPath(Tree.pathFromXtoY(tree, max, min)))