1 / 49

graphs

graphs ,its types, working with the help of diagrams and programs

15579
Télécharger la présentation

graphs

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. POST .Graduate govt gulberge college for women,lahore Submitted to:Mam Fatima Subject:Data Strucrure& algorithm Class:BScs Semster:3rd Presentation topic:weak:11 Session:2019-2023

  2. Submitted by: Sidra Tahir 1922110043 Nayyab Mir 1922110025 Alisha 1922110002 Aneela 1922110006 Nida Fatima 1922110027 Areeka 1922110009 Taimul 1922110046 Rukaiya 1922110032 Sewera 1922110039 Tayyaba 1922110047 GROUP3

  3. ONE PART 1 GRAPHS

  4. Graph: A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by points termed as vertices, and the links that connect the vertices are called edges. Formally, a graph is a pair of sets (V, E), where V is the set of vertices and E is the set of edges, connecting the pairs of vertices. Take a look at the following graph − In the above graph, V = {a, b, c, d, e} E = {ab, ac, bd, cd, de}

  5. . Basic Operations: Following are basic primary operations of a Graph − • Add Vertex − Adds a vertex to the graph. • Add Edge − Adds an edge between the two vertices of the graph. • Display Vertex − Displays a vertex of the graph

  6. Example:

  7. TWO PART 1 (A) Types of graph

  8. Types of graph • Undirected Graph: In an undirected graph, nodes are connected by edges that are all bidirectional. For example . if an edge connects node 1 and 2, we can traverse from node 1 to node 2, and from node 2 to 1.

  9. • Directed Graph In a directed graph, nodes are connected by directed edges – they only go in one direction . For example, An edge connects node 1 and 2, but the arrow head points towards 2, we can only traverse from node 1 to node 2 – not in the opposite direction.

  10. THREE PART 1 (B) Type of Representation of Graph

  11. Type of representation • Two ways are there for representing graph in the memory of • Computer • They are: • 1. Sequential representation • 2. Linked representation

  12. Sequential Representation • Graph can be represented through matrix in system,s memory. • This is sequential in nature. • This type of representation is called sequential representation of • graph

  13. Types of Sequential Representation 1. Adjacency Matrix Representation 2. Incidence Matrix Representation

  14. • 3. Circuit Matrix Representation • 4. Cut Set Matrix Representation

  15. Linked Representation • Graphs can be represented • through linked list in the systems • memory. • This is linked in nature. • This type of representation is • called linked representation of • graph.

  16. Type of Linked Representation 1. Adjacency linked Representation • Alternative to the Adjacency Matrix • Requires less memory

  17. FOUR PART 1 (C) Graph traversal Graph traversal is a technique used for searching vertex in a graph. A graph traversal finds the edges to be used in the search process without creating loops Used to search nodes in a graph.

  18. Types of graph traversal: 1. Breadth first search (BFS) 2. Depth first search (DFS)

  19. • Breadth first search: is a vertex based technique for finding a shortest path in graph. It uses a queue data structure which follows first in first out (FIFO).

  20. • Depth first search: is a edge based technique . It uses a stack data structure which follows last in first out (LIFO).

  21. FIVE PART 1 (D) SHORTEST PATH OF GRAPH

  22. Shortest Path Problem:- • It is a problem of finding a path between two vertices (or nodes) in a graph such that the sum of weights of its constituents edges is minimized. • A shortest path from vertex s to vertex t is a directed path from s to t with the property that no other such path has a lower weight. • Formal Definition of Shortest Path:- G=(V,E) Shortest path (u,v) from u to v has weight={min{w(P):P is a path from u to v. • Properties:- Subparts of shortest paths are shortest paths. • No (unique) shortest path exists if graph has a cycle with negative weight. • The graphs should not have negative weights. • Negative weights should create complications. • Shortest paths are normally simple.They are not necessarily unique.

  23. Example: 1 Shortest path: (a-c-e-d-f)

  24. Example:2 Shortest Path: (a-h-g-f-e)=21 length

  25. PROGROM OF SHORTEST PATH

  26. six PART 1 (E) Cycle Dedection Of Graph

  27. Cycle Detection of graph The existence of a cycle in directed and undirected graphs can be determined by whether depth-first search (DFS) finds an edge that points to an ancestor of the current vertex (it contains a back edge). All the back edges which DFS skips over are part of cycles.

  28. Types of cycle dedection in graph • Directed Graph • Indirected Graph

  29. Cycle detection in directed graph `FLAGS VISITED -1=unvisited 0= visited&in stack 1=pooped out from stack ABCDE CYCLE is B D E B E - 1,O,1 TOP IS E PARENT MODE(-1) -1,O,1 B D D,E A _ -1,O,1 C,D C X B A A B C B E C D C A -1,O,1 -1,O,1 E D

  30. PROGRAM https://youtu.be/0dJmTuMrUZM

  31. Cycle detection in undirected Graph X X X X `FLAGS -1=unvisited 0= visited&in stack 1=pooped out from stack QEUE A B C D E VISITED SET -1,O,1 ABCDE B -1,O,1 D -1,O,1 A improtant point: if any vector finds its adecent vectors with flag 0,then it contain a cycle. E -1,O,1 -1,O,1 C

  32. PROGRAM https://youtu.be/tJkpxwg90KY

  33. Isomorphic Graphs Condition (graphs are isomorphic or not)  Two graphs G1 and G2 are said to be isomorphic if their;  Number of components ( vertices and edge are same. |V1G1|=| V2G2| and| EG1|=|EG2|  Their edge connectivity is retained.  Degree sequence of graphs are same.

  34. G1 and G2 if and only if the corresponding subgraphs of G1 and G2(obtained by the deleting some vertices in G1 and G2 and the image in G2) are isomorphic Example:

  35. seven PART 1 (F) Graph Traversal Types

  36. Depth-first search Depth-first search(DFS): Finds a path between two vertices by exploring each possible path as far as possible before backtracking. ▪Often implemented recursively. ▪Many graph algorithms involve visitingor markingvertices. •Depth-first paths from ato all vertices (assuming ABC edge order): ▪to b:{a, b} ▪to c:{a, b, e, f, c} ▪to d:{a, d} ▪to e:{a, b, e} ▪to f:{a, b, e, f} ▪to g:{a, d, g} ▪to h: {a, d, g, h}

  37. Breadth-first search Breadth-first search(BFS): Finds a path between two nodes by taking one step down all paths and then immediately backtracking. ▪Often implemented by maintaining a queue of vertices to visit. •BFS always returns the shortest path (the one with the fewest edges) between the start and the end vertices. ▪to b:{a, b} ▪to c:{a, e, f, c} ▪to d:{a, d} ▪to e:{a, e} ▪to f:{a, e, f} ▪to g:{a, d, g} ▪to h: {a, d, h}

  38. DFS, BFS runtime •What is the expected runtime of DFS and BFS, in terms of the number of vertices V and the number of edges E ? •Answer: O(|V| + |E|)▪where |V| = number of vertices, |E| = number of edges ▪Must potentially visit every node and/or examine every edge once. ▪why not O(|V| * |E|) ? •What is the space complexity of each algorithm? ▪(How much memory does each algorithm require?)

More Related