4 Questions for my Computer Science class. 1.How can you pass a \"temporary\" ob
ID: 3615713 • Letter: 4
Question
4 Questions for my Computer Science class. 1.How can you pass a "temporary" object to a function thataccepts its arguments by reference? 2.Explain the difference between a depth-first search and abreadth-first search in a graph. Thanks. 4 Questions for my Computer Science class. 1.How can you pass a "temporary" object to a function thataccepts its arguments by reference? 2.Explain the difference between a depth-first search and abreadth-first search in a graph. Thanks. 1.How can you pass a "temporary" object to a function thataccepts its arguments by reference? 2.Explain the difference between a depth-first search and abreadth-first search in a graph. Thanks.Explanation / Answer
DFS (Depth First Search)and BFS (Breadth First Search) are search algorithms used forgraphs and trees. When you have an ordered tree or graph, like aBST, it's quite easy to search the data structure to find the nodethat you want. But, when given an unordered tree or graph, the BFSand DFS search algorithms can come in handy to find what you'relooking for. The decision to choose one over the other should bebased on the type of data that one is dealing with.
In a breadth first search,you start at the root node, and then scan each node in the firstlevel starting from the leftmost node, moving towards the right.Then you continue scanning the second level (starting from theleft) and the third level, and so on until you've scanned all thenodes, or until you find the actual node that you were searchingfor. In a BFS, when traversing one level, we need some way ofknowing which nodes to traverse once we get to the next level. Theway this is done is by storing the pointers to a level's childnodes while searching that level. The pointers are stored in FIFO(First-In-First-Out) queue. This, in turn, means that BFS uses alarge amount of memory because we have to store thepointers.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.