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
/* | |
Complexity Analysis: | |
Time complexity: O(n). | |
Only one traversal of the loop is needed. | |
Auxiliary Space: O(1). | |
*/ | |
detectLoop() { | |
let isLoopPresent = false; |
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
// structure of node | |
class Node { | |
constructor(data) { | |
this.data = data; | |
this.next = null; | |
this.visited = false; | |
} | |
} | |
/* |
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
/* | |
Complexity Analysis: | |
Time complexity: O(n). | |
Only one traversal of the loop is needed. | |
Auxiliary Space: O(n). | |
n is the space required to store the value in hashmap. | |
*/ | |
detectLoop() { |
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
createLoop(nNode) { | |
let temp = null; | |
let current = this.head; | |
let count = 1; | |
while(count < nNode) { | |
current = current.next; | |
count++ | |
} | |
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
// structure of node | |
class Node { | |
constructor(data) { | |
this.data = data; | |
this.next = null; | |
} | |
} | |
class LinkedList { | |
constructor() { |
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
let arr = [38, 27, 43, 3, 9, 82, 10]; | |
const customSort = function(arr) { | |
if(arr.length <= 1) return arr; | |
let mid = Math.ceil(arr.length/2); | |
let firstHalf= customSort(arr.splice(0, mid)); | |
let secondHalf = customSort(arr.splice(-mid)); | |
return merge(firstHalf, secondHalf); |
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
let arr= [64,25,12,22,11]; | |
const selectionSort = function(arr) { | |
if(arr.length=== 0) { | |
return arr; | |
}else { | |
for(let i = 0; i < arr.length-1; i++) { | |
let min = i; | |
for(let j = i+1; j < arr.length; j++) { | |
if(arr[j] < arr[min]) { |
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
let arr = [1, 3, 5, 7, 8, 9]; | |
const binarySearch = function(arr, ele, start, end) { | |
if(start > end) { | |
return false; | |
} | |
let mid = Math.floor((start+end)/2); | |
console.log(mid); |
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
/** | |
**** | |
Priority Queue is an extension of queue with following properties:- | |
1. Every item has a priority associated with it. | |
2. An element with high priority is dequeued before an element with low priority. | |
3. If two elements have the same priority, they are served according to their order in the queue. | |
**** | |
**/ |
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
{ | |
"javascript.updateImportsOnFileMove.enabled": "always", | |
"workbench.colorTheme": "One Dark+ (Sublime)", | |
"explorer.confirmDragAndDrop": false, | |
"explorer.confirmDelete": false, | |
"workbench.startupEditor": "newUntitledFile", | |
"typescript.updateImportsOnFileMove.enabled": "always", | |
"git.enableSmartCommit": true, | |
"workbench.iconTheme": "vscode-icons", | |
"workbench.statusBar.visible": true, |
NewerOlder