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
/*---- | |
Best Case:1 | |
Worst Case:logn | |
Average Case:logn | |
Unsuccessful:logn | |
----- | |
*/ | |
arr=[1,2,3,4,5],val=5; | |
function binary_search(array,value){ |
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
function linear_search(array,value){ | |
for (var i in array) | |
{ | |
if(array[i]==value) | |
{ | |
console.log(i) ; | |
return; | |
} | |
} | |
} |
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
/* | |
---- | |
Best Case:1 | |
Worst Case:√n(karekök n) | |
Average Case:log(logn) | |
Unsuccessful:√n | |
----- | |
mid = Lo + ((Hi - Lo) / (A[Hi] - A[Lo])) * (X - A[Lo]) | |
where − |
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
/* | |
Worst Case:N^2 | |
Average Case:N^2 | |
Best Case:N | |
*/ | |
function bubble_sort(list){ | |
for(let i=0;i<list.length-1;i++){ | |
let swapped = false; | |
for(let j=0;j<list.length-1-i;j++){ | |
comparisons++; |
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
/* | |
Best Case:N | |
Average Case:N^2 | |
Worst Case:N^2 | |
*/ | |
(function(){ | |
let comparisons=0; | |
let arr2=[28, 31, 43, 97, 49, 11, 33, 71, 41, 80, 86, 38, 53, 54, 7, 67, 96, 52, 29, 25, 56, 77, 73, 42, 62, 84, 21, 68, 2, 44, 9, 94, 66, 78, 6, 57, 20, 89, 1, 55, 65, 85, 51, 23, 70, 32, 12, 27, 18, 90, 4, 82, 5, 35, 58, 69, 22, 83, 37, 61, 79, 34, 81, 30, 72, 95, 91, 48, 88, 46, 3, 26, 60, 39, 17, 24, 74, 99, 10, 16, 87, 98, 76, 13, 36, 45, 59, 100, 50, 93, 19, 75, 92, 40, 8, 47, 14, 15, 63, 64]; | |
let arr=[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, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]; | |
function insertion_Sort(A){ |
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
/* | |
Best Case:n^2 | |
Average Case:n^2 | |
Worst Case:n^2 | |
*/ | |
(function(){ | |
let comparison=0; | |
let arr2=[28, 31, 43, 97, 49, 11, 33, 71, 41, 80, 86, 38, 53, 54, 7, 67, 96, 52, 29, 25, 56, 77, 73, 42, 62, 84, 21, 68, 2, 44, 9, 94, 66, 78, 6, 57, 20, 89, 1, 55, 65, 85, 51, 23, 70, 32, 12, 27, 18, 90, 4, 82, 5, 35, 58, 69, 22, 83, 37, 61, 79, 34, 81, 30, 72, 95, 91, 48, 88, 46, 3, 26, 60, 39, 17, 24, 74, 99, 10, 16, 87, 98, 76, 13, 36, 45, 59, 100, 50, 93, 19, 75, 92, 40, 8, 47, 14, 15, 63, 64]; | |
let arr=[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, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]; |
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
/* | |
Best Case:n*logn | |
Average Case:n*logn | |
Worst Case:n^2 | |
*/ | |
(function(){ | |
let comparison=0; | |
let arr2=[28, 31, 43, 97, 49, 11, 33, 71, 41, 80, 86, 38, 53, 54, 7, 67, 96, 52, 29, 25, 56, 77, 73, 42, 62, 84, 21, 68, 2, 44, 9, 94, 66, 78, 6, 57, 20, 89, 1, 55, 65, 85, 51, 23, 70, 32, 12, 27, 18, 90, 4, 82, 5, 35, 58, 69, 22, 83, 37, 61, 79, 34, 81, 30, 72, 95, 91, 48, 88, 46, 3, 26, 60, 39, 17, 24, 74, 99, 10, 16, 87, 98, 76, 13, 36, 45, 59, 100, 50, 93, 19, 75, 92, 40, 8, 47, 14, 15, 63, 64]; | |
let arr=[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, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]; |
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
/* | |
Best Case:N | |
Average Case:n*(logn)^2 OR (n)^(1.5) | |
Worst Case:(n)^(1.5) | |
*/ | |
(function(){ | |
let comparison=0; | |
let arr2=[28, 31, 43, 97, 49, 11, 33, 71, 41, 80, 86, 38, 53, 54, 7, 67, 96, 52, 29, 25, 56, 77, 73, 42, 62, 84, 21, 68, 2, 44, 9, 94, 66, 78, 6, 57, 20, 89, 1, 55, 65, 85, 51, 23, 70, 32, 12, 27, 18, 90, 4, 82, 5, 35, 58, 69, 22, 83, 37, 61, 79, 34, 81, 30, 72, 95, 91, 48, 88, 46, 3, 26, 60, 39, 17, 24, 74, 99, 10, 16, 87, 98, 76, 13, 36, 45, 59, 100, 50, 93, 19, 75, 92, 40, 8, 47, 14, 15, 63, 64]; | |
let arr=[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, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]; |
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
/* | |
Best Case:n*logn | |
Average Case:n*logn | |
Worst Case:n*logn | |
Space Complexity:N | |
*/ | |
(function(){ | |
let comparison=0; | |
let arr2=[28, 31, 43, 97, 49, 11, 33, 71, 41, 80, 86, 38, 53, 54, 7, 67, 96, 52, 29, 25, 56, 77, 73, 42, 62, 84, 21, 68, 2, 44, 9, 94, 66, 78, 6, 57, 20, 89, 1, 55, 65, 85, 51, 23, 70, 32, 12, 27, 18, 90, 4, 82, 5, 35, 58, 69, 22, 83, 37, 61, 79, 34, 81, 30, 72, 95, 91, 48, 88, 46, 3, 26, 60, 39, 17, 24, 74, 99, 10, 16, 87, 98, 76, 13, 36, 45, 59, 100, 50, 93, 19, 75, 92, 40, 8, 47, 14, 15, 63, 64]; | |
let arr=[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, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]; |
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
console.log(Date()); |
OlderNewer