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
#user nobody; | |
worker_processes 1; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
#pid logs/nginx.pid; | |
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 findLocalMin(array, start, end){ | |
var mid = Math.floor( (start + end)/2 ); | |
if (((mid - 1) < 0) || ((mid + 1) >= array.length)) return null; | |
if (array[mid - 2] > array[mid - 1] && array[mid - 1] < array[mid]){ | |
return array[mid-1]; | |
} else if ( (array[mid-1] >= array[mid-2])){ | |
return findLocalMin(array, start, mid); | |
} else { |
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 breadthFirstSearch(node){ | |
// build a queue | |
var q = []; | |
// initialize q | |
q.push(node); | |
var currentNode = null; | |
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 depthFirstSearch(node){ | |
if (node === null) return; | |
// visit node | |
console.log(node.value); | |
node.visited = true; | |
for (var i = 0; i < node.children.length; i++){ | |
if (node.children[i].visited === false){ | |
depthFirstSearch(node.children[i]); |
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 quickSort(array, start, end){ | |
var leftIndex = partition(array, start, end); | |
if (start < leftIndex-1){ | |
quickSort(array, start, leftIndex-1); | |
} | |
if (start > leftIndex){ | |
quickSort(array, leftIndex, end); |
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 covers(root, node){ | |
if (root === null ) return false; | |
if (root === node ) return true; | |
return covers(root.left, node) || covers(root.right, node); | |
} | |
function commonAncestorHelper(root, node1, node2){ | |
if (root === null ) return false; | |
if (root === node1 || root === node2 ) return root; | |
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 createMinimalBST(array, start, end){ | |
if (end < start){ | |
return null; | |
} | |
var mid = Math.floor( (start + end) / 2 ); | |
var node = {val: array[mid], left: null, right: null}; | |
node.left = createMinimalBST(array, start, mid-1); | |
node.right = createMinimalBST(array, mid+1, end); |
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 containTrees(tree1, tree2){ | |
if (tree2 === null){ | |
return true; | |
} | |
return subTree(tree1, tree2); | |
} | |
function subTree(tree1, tree2){ |
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 checkBST(node){ | |
lastVisited = null; | |
function checkBSTRecurse (node){ | |
if (node === null) return true; | |
if ( !checkBSTRecurse(node.left) ) return false; | |
if (node.val < lastVisited) return 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
//1,2,3,4,4,4,4,4,5,6,7 | |
function findFrequency(array, target){ | |
var first, last; | |
var result = -1; | |
first = findFirst(array, target, 0, array.length-1); | |
if (first !== -1){ | |
last = findLast(array, target, 0, array.length-1); |
NewerOlder