Topics:
- Linked Lists
- Queues
- Doubly Linked Lists
- Binary Search Trees
- Heaps
- Should have the methods:
addToTail,removeHead,contains, andgetMax.addToTailreplaces the tail with a new value that is passed in.removeHeadremoves and returns the head node.containsshould search through the linked list and return true if a matching value is found.getMaxreturns the maximum value in the linked list.
- The
headproperty is a reference to the first node and thetailproperty is a reference to the last node. Build your nodes with objects.
- Should have the methods:
enqueue,dequeue,isEmptyand alengthgetter.enqueueshould add an item to the back of the queue.dequeueshould remove and return an item from the front of the queue.isEmptyshould returntrueif the queue contains no elements,falseotherwise.- A
lengthgetter that returns the number of items in the queue.
-
Consists of a
DoublyLinkedListclass and aListNodeclass. -
The
ListNodeclass has the methodsinsertAfter,insertBefore, anddelete.insertAfterinserts a new node with the input value after the calling node.insertBeforeinserts a new node with the input value before the calling node.deleteshould remove the calling node from the list (think about what that means).
-
The
DoublyLinkedListclass, like theLinkedListclass, holds references to theheadof the list as well as thetail; it has the methodsaddToHead,removeFromHead,addToTail,removeFromTail,moveToFront,moveToBack, anddeleteaddToHeadcreates a new node with the input value and adds the new node as the new head of the list.addToTailcreates a new node with the input value and adds the new node as the new tail of the list.removeFromHeadremoves the current head of the list; the current head's next node should be designated as the new head.removeFromTailremoves the current tail of the list; the current tail's previous node should be designated as the new tail.moveToFrontreceives a node and moves that node (if it exists in the list) to the front of the list as the new head.moveToBackreceives a node and moves that node (if it exists in the list) to the back of the list as the new tail.deletereceives a node as input and deletes that node from the list.
- Should have the methods
insert,contains,getMax,depthFirstForEach, andbreadthFirstForEach.insertadds the input value to the binary search tree, adhering to the rules of the ordering of elements in a binary search tree.containssearches the binary search tree for the input value, returning a boolean indicating whether the value exists in the tree or not.getMaxreturns the maximum value in the binary search tree.depthFirstForEachshould iterate over the binary search tree in depth-first order, applying the supplied callback function to each tree element in turn.breadthFirstForEachshould iterate over the binary search tree in breadth-first order, applying the supplied callback function to each tree element in turn.
- Should have the methods
insert,delete,getMax,bubbleUp, andsiftDown.insertadds the input value into the heap; this method should ensure that the inserted value is in the correct spot in the heapdeleteremoves and returns the 'topmost' value from the heap; this method needs to ensure that the heap property is maintained after the topmost element has been removed.getMaxreturns the maximum value in the heap in constant time.bubbleUpmoves the element at the specified index "up" the heap by swapping it with its parent if the parent's value is less than the value at the specified index.siftDowngrabs the indices of this element's children and determines which child has a larger value. If the larger child's value is larger than the parent's value, the child element is swapped with the parent.
-
Set up your repository by running
npm installin your root directory to install all necessary dependencies. -
Implement each data structure, starting with the linked list data structure. Run
npm testto run the tests and check your progress. Get all the tests passing for each data structure.