 Welcome to this course on data structures and algorithms. In all the sessions in this week we shall be looking at graphs and their implementation using STL of C plus plus. Today we look at graphs to understand what they are and how they are used. Graphs are useful to represent many real life situations. For example, if we want to represent family relationships or if we want to represent a road network or a rail network, graphs are commonly used. Please note that we have already studied tree structures, but graph is something different from a tree because there could be interconnections between various nodes unlike a tree which we shall see later. The graphs are useful in solving many optimization problems. For example, given a road or rail network we want to find out what is the path which will give me minimum transportation cost or minimum transportation time. To solve such problems I need to represent the transportation network and I need to represent cost associated with travel between any two nodes. Such problems are solved by the graph model. You might have heard of shortest path problem. You want to find out the shortest path between two cities. Again graphs are very useful in depicting the situation as well as solving such problems. Let us look at representational graphs. The graph, any graph consists of a set of vertices and a set of edges. A vertex is merely an element or a node in the graph. For example, in this illustration A, B, C, D, E are all vertices of the graph. An edge is the connection between two vertices. So, you will note in this particular illustration there is an edge between A and B. There is an edge between A and C. There is an edge between B and D, but there is no edge from vertex E. So, these are examples of edges and these are examples of vertices. So, vertices and edges together constitute a graph. There are two types of graph. One is called the undirected graph which is the most general graph in which the edges have no direction. What it implies is that if there is an edge between A and C, we will say that there is an edge from A to C and also from C to A. We will say there is an edge from A to B and also from B to A. This is what is illustrated here. So, this is the property of undirected edges that every such edge represents an edge between the two nodes and they indicate either from two or from two in either direction. Undirected graphs on the other hand have edges which have directions. So, these are called directed edges and they specifically indicate the source and destination in terms of the vertices which are connected by such edges. For example, there is an edge from A to B, but there is no edge from B to A. So, this is a directed edge connecting from A to B. On the other hand, if you see this edge, this edge actually indicates a directed edge from A to C and a directed edge from C to A as well. There is similarly an edge between C to D, but there is no edge from D to C. So, these are called directed graphs. In case of directed graphs, we have the notion of outgoing edge and outgoing degree and a corresponding notion of incoming edge and an incoming degree. Let us look at the notion of outgoing edge first. An outgoing edge is defined as a directed edge from a source vertex. For example, there is an edge from A to C, there is an edge from C to D, but not from D to C. An outgoing degree of a vertex is the number of edges which emanate out of a source vertex. For example, A has outgoing degree 2. Why? Because it has 2 edges going out from A to C and A to B. B has outgoing degree 0 because there is no edge which goes out of B. C on the other hand has an outgoing degree of 3 because from C, I have an edge to A, I have an edge to B and I have an edge to D. E of course has a 0 outgoing degree. So, a simple concept, outgoing edge is a directed edge from a source vertex and outgoing degree is the number of edges going out from a source vertex. As I mentioned, exactly similar concept exists for incoming edges and in degree. Incoming edge is nothing but a directed edge to a destination vertex. For example, if you look at B, there is an edge from A to B, there is an edge from C to B, there is an edge from D to B. So, B is the destination vertex and we define correspondingly a notion of indegree. These are number of edges pointing to the destination vertex. For example, if you consider A as a destination vertex, it has only one edge coming to it from C. So, its degree, indegree is 1. B on the other hand has an indegree of 3 because there are edges coming to it from A, C and D. E again has 0 indegree because it has no edge coming into it. So, in today's session, we looked at graphs and their basic properties. We saw that graphs have vertices and edges. Depending upon the whether the edges are undirected or directed, we classify the graph as directed graph or undirected graph. In case of directed graph, we also saw the notion of indegree and outdegree. We shall later on see how graphs are implemented in our programs. Thank you.