answersLogoWhite

0


Best Answer

The main difference is that depth-first uses a stack while breadth-first uses a queue.

To illustrate, imagine a binary tree where every node has up to two child nodes and some data. We begin at the root in both cases. With breadth-first, we enqueue the root. We then begin an iterative process. First, we dequeue a node. If the node contains the data being sought then we're done. Otherwise we enqueue the node's immediate children. If the queue is empty, the data being sought does not exist and we're done. Otherwise we begin a new iteration.

With depth first we do the same thing except we stack the nodes (push and pop rather than enqueue and dequeue). Queues are a FIFO structure (first in, first out) while stacks are LIFO (last in, first out). This dramatically alters the sequence in which nodes are examined. Breadth-first examines nodes in sequence, row by row, whereas depth-first examines the depths of the left hand side of each node before examining the depths of the right hand side of each node.

Depth-first is ideally suited to brute force backtracking algorithms (particularly NP-complete problems) as well as for rapidly building sorted lists from unsorted sequential data. Breadth-first search is better suited to creating diagrams from binary trees because a single pass can determine the number of levels and the maximum width required to display the tree, while a second pass can build the diagram one row at a time (typical breadth-first implementations will maintain the width and height as internal members to avoid recalculating them).

Because depth-first employs a stack, implementations often make use of recursion rather than iteration, thus taking advantage of the call stack to provide the necessary backtracking. However, an iterative approach is usually more efficient, particularly if the tree depth exceeds the compiler's ability to inline expand the recursions.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

Both algorithm can be build very similar. The difference between breadth first search and depth first search is order in which element are added to open list.

In Breadth First Search :- A new node are appended to the end of open list.

in addition it needs Memory Space.

In Depth First Search :- A new node are inserted in the beginning of open list.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Both methods make use of recursion to traverse a tree of nodes starting at the root node, visiting every node until the value being sought is found. Which method you use will depend on whether the data is more likely to appear in the upper levels of the the tree (at or near the root node) or in the lower levels (at or near the leaf nodes). The former uses breadth-first while the latter uses depth-first.

If we assume a node has the following simplified structure:

class cnode

{

public:

cnode* searchbreadth(int value);

cnode* searchdepth(int value);

cnode* m_head;

cnode* m_next;

int value;

};

Then the breadth-first search would be implemented like this:

cnode* cnode::searchbreadth(int value)

{

cnode* found = 0;

if( m_value value )

return( this );

return( found );

}

As you can see the only real difference is whether the comparison is done before or after the recursive traversal. For depth first, you must traverse first, for breadth first, you must compare first.

Note that binary-trees must always use a depth-first search since all data is contained in the leaf nodes. However, the above implementations are unsuitable for binary trees since binary trees are constructed from an abstract node which implements the search method as a traversal of the root and parent (or internal) nodes, while the leaf nodes override the search method to perform the actual comparison with itself. Other than that, the principal is the same.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

The main difference is that with depth first we use a stack to backtrack and with breadth first we use a queue. Which method we use is ultimately determined by the ordering of the tree.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between breadth first search and best first search?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between breadth first search and depth first search in C programming?

Both algoritms can be build very similary. The difference between breadth-first search and depth-first search is order in which elements ar added to OPEN list. In breadth-first search new nodes are appended to the end of OPEN list In depth-first search new nodes are inserted in the begining of OPEN list


Difference between breadth first and depth first search in artificial intelligence?

diference between depth first search and breath first search in artificial intelellegence


What is the advantage of iterative deepening search over depth-first?

Iterative deepening effectively performs a breadth-first search in a way that requires much less memory than breadth-first search does. So before explaining the advantage of iterative deepening over depth-first, its important to understand the difference between breadth-first and depth-first search. Depth first explores down the tree first while breadth-first explores all nodes on the first level, then the second level, then the third level, and so on. Breadth-first search is ideal in situations where the answer is near the top of the tree and Depth-first search works well when the goal node is near the bottom of the tree. Depth-first search has much lower memory requirements. Iterative deepening works by running depth-first search repeatedly with a growing constraint on how deep to explore the tree. This gives you you a search that is effectively breadth-first with the low memory requirements of depth-first search. Different applications call for different types of search, so there's not one that is always better than any other.


Breadth First search is used in?

stacks


How to detect binary search tree as depth first search or breadth first search?

O(N-1)


8 Queens Problem using Breadth First Search and Depth First Search?

1 3


Explain the difference between depth first and breadth first traversing techniques of a graph?

In depth first traversing, the node that is below the current node is considered first. For breadth first traversing, the node to the rightmost of the current mode is considered.


Is breadth first search bidirectional?

It can be. It depends on the structure and how it is implemented.


What is the difference between blind search and heuristic search?

Heuristic search algorithms have knowledge of where the goal or finish of the graph. For example, in a maze, they would know which path leads in the direction of the goal. Blind search algorithms have no knowledge of where the goal is, and wander "blindly" through the graph. Blind search techniques include Breadth-first, Depth-first search, etc. Heuristic search techniques include Best-first, A*, etc.


Which data structure is used for breadth first seach?

Breadth first search can be performed upon any tree-like structure. A binary tree is a typical example. A breadth first search begins at the root and searches the root's children, then all its grandchildren, and so on, working through one level of the tree at a time.


Difference between breadth first search and best first search in artificial intelligence?

These are the two search strategies which are quite similar.In breadth first search a node is expanded according to the cost function of the parent node. In best first search we expand the nodes in accordance with the evaluation function.This can be understood by the given example.Suppose we are at two intermediate nodes N1 & N2.The cost function of N1 is less than that of N2.So the breadth first search will definitely expand N1.Now suppose somehow we have the knowledge about the cost required from reaching goal node from N1 and N2.If the sum of the costs of reaching N1 from Start node and the cost (knowledge) of reaching goal from N1 is more than that of the sum of the costs of reaching N2 from Start node and the cost (knowledge) of reaching goal from N2 , then we should expand N2 and not N1.This expansion is done in Best first search


How do you print all data in a Binary Search Tree?

By using Depth First Search or Breadth First search Tree traversal algorithm we can print data in Binary search tree.