Topics:
- Tree
- Graph
- Binary Search Tree
- Should have the methods:
addChild, andcontains - Each node on the tree should have a
valueproperty and achildrenarray. addChild(value)should accept a value and add it to that node'schildrenarray.contains(value)should returntrueif the tree or its children the given value.- When you add nodes to the
childrenarray usenew Tree(value)to create the node. - You can instantiate the
Treeclass inside of itself.
- Should have the methods:
insert,contains, anddepthFirstForEach. insert(value)inserts the new value at the correct location in the tree.contains(value)searches the tree and returnstrueif the the tree contains the specified value.depthFirstForEach(cb)should iterate over the tree using DFS and passes each node of the tree to the given callback function.
- should have methods named
addNode,contains,removeNode,addEdge,getEdge, andremoveEdge addNode(newNode, toNode)should add a new item to the graph. IftoNodeis given then the new node should share an edge with an existing nodetoNode.contains(value)should return true if the graph contains the given value.removeNode(value)should remove the specified value from the graph.addEdge(fromNode, toNode)should add an edge between the two specified nodes.getEdge(fromNode, toNode)should returntrueif an edge exists between the two specified graph nodes.removeEdge(fromNode, toNode)should remove the edge between the two specified nodes.
- Add a method to the
Graphclass that searches through the graph using edges. Make this search first as a depth first search and then refactor to a breadth first search.