CS Data Structures and Algorithms
Data structures and Algorithms implemented in Javascript.
Author
Tomas Perez - tom@0x101.com
Installation
$ npm install
Run the tests
If you want to run the tests, you need to install mocha globally:
$ npm install -g mocha
Then you can run the tests:
$ npm test
BinaryOperator
getBit
β Returning bits
setBit
β Setting bits
clearBit
β Clearing bits
Insertion sort
β Trivial cases
β Non trivial cases
Merge sort
β Already sorted array
β Non trivial cases
Quick sort
β Partition method
β Already sorted array
β Non trivial cases
Two Sum
β Basic tests
BFS
Solve algorithm
β BFS simple search
Closest leaf
Solve algorithm
β Determine the closest leaf in a binary tree
DFS
Solve algorithm
β DFS simple search, iterative version
β DFS simple search, recursive version
Dijkstra
Error handling
β Empty graph
Solve algorithm
β Single source path search: one vertex
β Single source path search: multiple nodes
LargestCommonSubstring
The algorithm works as expected
β Basic cases
LargestOfTwoNumbers
The algorithm works as expected
β Basic cases
Min Height in binary trees
Solve
β Empty BinaryTrees
β Basic cases
SortedArrayToBST
The algorithm works as expected
β Basic cases
β Edge cases
TreeTraverse
In Order
β Traverses properly a binary tree in-order
β Traverses properly a binary tree post-order
β Traverses properly a binary tree in-order
BinaryTree
Creation
β Empty BinarySearchTree
β Simple BinarySearchTree
Inserting elements in a Binary Search Tree
β Basic insertion
Get largest element in a Binary Search Tree
β Construct the BST and search for the largest
BinaryTree
Creation
β Empty BinaryTrees
β Leave values must be BinaryTreeNode
β Simple creation
DoubleLinkedList
Insertion
β Simple insertion
β Can not insert an invalid a value
β Can insert multiples values
HashTable
The data structure works as expected
β Keys validation
β Insertion
β Hash function
List
isEmpty
β Checking if a list is empty
Insertion
β Simple insertion
β Can not insert an invalid a value
β Can insert multiples values
MinHeap
The data structure works as expected
β Basic cases
Node
Creation and initialization
β Simple creation
β Can not initialize a node without a value
Handling previous node
β Can assign a value to the previous node
β Can not assign invalid values to the previous node
Handling next node
β Can assign a value to the next node
β Can not assign invalid values to the next node
SuffixTree
Inserting words in a suffix tree
β Simple insertion and retrieval
Application of a suffix tree for computing common substrings
β Is q a substring of S
β How many times does q appear in S
β Longest common substring of S and q
Tree
Creation
β Empty trees
β isLeaf
β Leave values must be TreeNode
β Simple creation
Trie
Inserting and retrieval
β Simple insertion and retrieval of words
60 passing (98ms)
License
Public Domain.
No warranty expressed or implied. Use at your own risk.