Hannah & Luke
A data structures and algorithms Ruby challenge from the Viking Code School
-
What data structure is used to implement DFS? Stack.
-
What data structure is typically used to implement BFS? Queue.
-
Which one can be done recursively? (the clue should be the data structure) DFS.
-
Which one would you use to print a list of all the nodes in a tree or graph, starting with depth 1, then depth 2, then depth 3 etc.? BFS.
-
What is the difference between a tree and a graph? Tree has orientation. Every node has parent (except root). There is a root node where all the other nodes derive from.
Graphs can have cycles where edges create loops. No orientation.