1 / 16

Section A2 ppt5 (1)

DAA BFS and DFS algorithms

Monia1
Download Presentation

Section A2 ppt5 (1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Course Name-DESIGN AND ANALYSIS OF ALGORITHMS Course Code- COM-301 Lecture No-  Topic – Breadth First Search and Depth First Search Date- 18-11- 2022 Model Institute of Engineering & Technology

  2. Objectives • This course will introduce students to the fundamental concepts underlying designing and analyzing algorithms. • Main objective of the course is to familiarize students about Algorithms, Set of Instructions, Running Time Complexity, basic structure and behavior of the various functional modules of the computer and how they interact to provide the processing needs of the user. • The emphasis is on studying and analyzing fundamental Instructions, Execution and their impact on Systems performance.

  3. Contents • Motivation • Objectives • Why study this subject? • Breadth First Search • Depth First Search

  4. MOTIVATION • The advancement in science and technology enhance the performance of processor, which proportionally affect the characteristics of computer system, such as security, scalability and reusability. Important problems such as sorting, searching, string processing, graph problems, Combinational problems, numerical problems are basic motivations for designing algorithm.

  5. Objectives • To gain experiences in fundamental techniques used for algorithm analysis and the main methodologies used for the design of efficient algorithms. • To study the most important computer algorithms of current practical use. Why study this subject? • Efficient algorithms lead to efficient programs. • Efficient programs sell better. • Efficient programs make better use of hardware. • Programmers who write efficient programs are preferred.

  6. GRAPH SEARCH BFS & DFS • Transportation networks (airline carrier, airports as node and direct flights as edges (direct edge).  • Communication networks (a collection of computers as nodes and the physical link between them as edges).  • Information networks (World Wide Web can be viewed as directed graph, the Web pages are nodes and the hyperlink between the pages are directed edges). • Social Network (People are nodes and friendship is an edge). 

  7. Breadth-First Search (BFS) • BFS begins at a root node and inspects all the neighboring nodes. Then for each of those neighbor nodes in turn, it inspects their neighbor nodes which were unvisited, and so on .

  8. Graph: BFS • Suppose we consider node 0 as a root node. Therefore, the traversing would be started from node 0. • Once node 0 is removed from the Queue, it gets printed and marked as a visited node.

  9. DFS • What is DFS? • DFS stands for Depth First Search. In DFS traversal, the stack data structure is used, which works on the LIFO (Last In First Out) principle. In DFS, traversing can be started from any node, or we can say that any node can be considered as a root node until the root node is not mentioned in the problem. • In the case of BFS, the element which is deleted from the Queue, the adjacent nodes of the deleted node are added to the Queue. In contrast, in DFS, the element which is removed from the stack, then only one adjacent node of a deleted node is added in the stack.

  10. DFS Consider node 0 as a root node. First, we insert the element 0 in the stack 

  11. DFS • The node 0 has two adjacent nodes, i.e., 1 and 3. Now we can take only one adjacent node, either 1 or 3, for traversing. Suppose we consider node 1; therefore, 1 is inserted in a stack and gets printed as shown below:

  12. Example

  13. Algorithm

  14. If we represent the graph G by adjacency matrix then the running time of BFS algorithm is O(n ), where n is the number of nodes. • 2) If we represent the graph G by link lists then the running time of BFS algorithm is O(m + n), where m is the number of edges and n is the number of nodes. 

  15. ALgorithm

  16. DFS running time  1) If we represent the graph G by adjacency matrix then the running time of DFS algorithm is O(n ), where n is the number of nodes.  2) If we represent the graph G by link lists then the running time of DFS algorithm is O(m + n), where m is the number of edges and n is the number of nodes. 

More Related