LinkedIn computes all the possible paths between two users and reports the length of the shortest path as the degree of connection between two users. In graphs, we call two vertices connected if there exists a path between the two. We can see that users A and B are connected to each other in two ways. LinkedIn takes it one level higher by telling you how much distance one user has from the other. Now if Facebook finds all the immediate friends of A, by going through all the immediately adjacent vertices of A, we shall get the set We can build a graph of their relationships. Have you ever wondered how Facebook knows how a person is your mutual friend, or how LinkedIn know if some connection is a 2nd or 3rd connection?įacebook and LinkedIn models their users as a graph where every vertex is a user profile and the edge between two people is the fact that they are friends with each other or follow each other.Ĭonsider two people A and B on Facebook who have several friends. One More Real-life Example of Graphs We See on Facebook or LinkedIn By visualizing such traversal problems as a graph data structure we can run algorithms like BFS to solve complicated problems. The above logic in data structures and algorithms is called a Breadth-First Search. Thus Google Maps will suggest us either route 2 or route 3. Since the cost is directly proportional to the time and distance, the cost of travel is time * distance. Hence we need to account for both in the cost calculation, as Google maps try to optimize the time as well as the distance. Each edge has two attributes associated: distance and time. We can visualize the cities as vertices and the roads as edges. Now this problem can be modelled as a graph. Route 1 goes through two cities B and C Route 2 goes through only one city D Route 3 is an expressway and directly goes to E There are 3 routes to do so as can be seen from the diagram below. We can see a variation of this problem being used in Google Maps. We can use graphs to visualize this problem as a city is a vertex and the distance between them is an edge essentially. We need to find the shortest possible route such that a salesman starts from one city and comes back to the same city without visiting any city twice. A Very Popular Example is the Travelling Salesman Problem (TSP).Ĭonsider a set of cities and the distances between them. Graphs can be used in problems where there are multiple ways to travel from vertex A to vertex B. Let us recollect the important points.Ī graph is a non-linear data structure that can be defined as a set of V vertices and E edges where the edges connect two vertices in a directed or undirected fashion. In this article, we learned the basics of graphs and how to implement them. Graphs help us visualize complex problems in a simpler way by visualizing entities as vertices and the relationships they carry as edges Introduction to Graph in Data Structure
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |