Data Structures and Algorithms Prof. Ajit A. Diwan Prof. Ganesh Ramakrishnan Prof. Deepak B. Phatak Department of Computer Science and Engineering IIT Bombay Session: Graphs Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
Graphs Useful to represent many real life situations Family relationships Road or rail network Optimization problems Minimize transportation costs and/or time Shortest path problem Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
Graphs A B E C D Vertex Each element / node in the graph A, B, C, D, E are vertices of graph Edge Connection between two vertices e.g. There is an edge between A and B A and C B and D etc. But, there is no edge for vertex E A B E C D E D G V ERTEX V ERTEX Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
Undirected Graphs A B E C D Undirected Undirected edges There is an edge from A to B and B to A A to C and C to A B to D and D to B … A B E C D Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
Directed Graphs A B E C D Directed Directed edges There is an edge from A to B, but, not from B to A A to C and also from C to A C to D, but not from D to C A B E C D Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
Directed Graphs A B E C D Outgoing Edge Directed edge from Source Vertex A to C, C to D (but not from D to C) Outgoing Degree Number of edges from a Source Vertex e.g. A has 2 (B and C) B has 0 C has 3 (A, B, and D) A B E C D Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
Directed Graphs A B E C D Incoming Edge Directed edge to the Destination vertex A to B, C to B, D to B Indegree Number of edges pointing to the Destination Vertex e.g. A has 1 (from C) B has 3 (from A, C, and D) A B E C D Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay
Thank you Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay