Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

BFS, Stacks & Queue Data Structure

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

BFS, STACKS & QUEUE DATA

STRUCTURE
WHAT IS BFS?
Breadth- First Search (BFS) is an algorithm for traversing or searching
Tree of Graph data structure.
It starts at the root or some arbitrary mode of a graph, sometimes
referred to as a ‘Search Key’ and explores all of the neighbor nodes at
the present depth prior to moving on to the nodes at the next depth
level.
.
ADVANTAGES OF BFS

• - BFS guarantees the shortest path in an unweighted graph.


• - It is easy to implement and understand, making it a popular algorithm for
beginners.
• - It can be used to find all nodes reachable from a given node.
• - It can be modified to solve other problems such as finding connected
components or detecting cycles.
DISADVANTAGES OF BFS

• - It requires more memory than depth-first search (DFS) because it needs to


store all the nodes in the current level.
• - It may not be efficient for large graphs with many levels, as it explores all
nodes at each level before moving on to the next level.
• - It may not find the optimal solution in weighted graphs, as it does not take
into account the weight of the edges.
• - It may not work well with directed graphs that have cycles.
STACK DATA STRUCTURE
• Stack Is A Linear Data Structure That Follows A Particular Order In Which The
Operations Are Performed. The Order May Be Lifo(last In First Out) Or
Filo(first In Last Out). LIFO Implies That The Element That Is Inserted Last,
Comes Out First And FILO Implies That The Element That Is Inserted First,
Comes Out Last.
APPLICATION OF STACK
• Infix To Postfix/Prefix Conversion
• Redo-undo Features At Many Places Like Editors, Photoshop.
• Forward And Backward Features In Web Browsers
• Backtracking Is One Of The Algorithm Designing Techniques. Some Examples Of
Backtrackiused In Many Algorithms Like Tree Traversals, Stock Span Problems, And
Histogram Problems.
• Backtracking Is One Of The Algorithm Designing Techniques. Some Examples Of
Backtracking Are The Knight-tour Problem, N-queen Problem, Fiind Your Way Through A
Maze, And Game-like Chess Or Checkers In All These Problems We Dive Into Someway If
That Way Is Not Efficient We Come Back To The Previous State And Go Into Some Another
Path. To Get Back From A Current State We Need To Store The Previous State For That
Purpose We Need A Stack.
• In Graph Algorithms Like Topological Sorting And Strongly Connected Components
COMPARE QUEUE
A Queue Is Defined As A Linear Data Structure That Is Open At Both Ends And
The Operations Are Performed In First In First Out (FIFO) Order.
We Define A Queue To Be A List In Which All Additions To The List Are Made At
One End, And All Deletions From The List Are Made At The Other End.
FIFO Principle Of Queue
• A Queue Is Like A Line Waiting To Purchase Tickets, Where The First Person In
Line Is The First Person Served. (I.E. First Come First Serve).
• Position Of The Entry In A Queue Ready To Be Served, That Is, The First Entry
That Will Be Removed From The Queue, Is Called The Front Of The
Queue(sometimes, Head Of The Queue), Similarly, The Position Of The Last Entry
In The Queue, That Is, The One Most Recently Added, Is Called The Rear (Or
The Tail) Of The Queue. See The Below Figure.
Thank You

You might also like