Find online courses made by experts from around the world.
Take your courses with you and learn anywhere, anytime.
Learn and practice real-world skills and achieve your goals.
Note: This course is a subset of our much longer course 'From 0 to 1: Data Structures & Algorithms' so please don't sign up for both:-)
This is an animated, visual and spatial way to learn data structures and algorithms
Taught by a Stanford-educated ex-Googler.
The graph is a data structure that is used to model a very large number of real world problems. It's also an programming interview favorite. The study of graphs and algorithms associated with graphs forms an entire field of study called graph theory.
Mail us about anything and we will always reply :-)
Not for you? No problem.
30 day money back guarantee.
Learn on the go.
Desktop, iOS and Android.
Certificate of completion.
|Section 1: Its A Connected World!|
You, This Course, and Us!Preview
|The graph is a data structure that is used to model a very large number of real world problems. It's also an programming interview favorite. The study of graphs and algorithms associated with graphs forms an entire field of study called graph theory.|
|Edges in a graph can be directed or undirected. A graph with directed edges forms a Directed Graph and those with undirected edges forms an Undirected Graph. These edges can be likened to one-way and two-way streets.|
|Different relationships can be modeled using either Directed or Undirected graphs. When a graph has no cycles it's called an acyclic graph. A graph with no cycles is basically a tree.|
There are a number of different ways in which graphs can be implemented. However they all follow they same basic graph interface. The graph interface allows building up a graph by adding edges and traversing a graph by giving access to all adjacent vertices of any vertex.
|An adjacency matrix is one way in which a graph can be represented. The graph vertices are rows and columns of the matrix and the cell value shows the relationship between the vertices of a graph.|
|The adjacency list and the adjacency set are alternate ways to represent a graph. Here the connection between the vertices is represented using either a linked list or a set.|
Compare the adjacency matrix, adjacency list and the adjacency set in terms of space and time complexity of common operations
Common traversal methods of trees apply to graphs as well. There is an additional wrinkle with graphs, dealing with cycles and with unconnected graphs. Otherwise the algorithms are exactly the same as those we use to traverse trees.
|Section 2: Graph Algorithms|
|Topological sort is an ordering of vertices in a graph where a vertex comes before every other vertex to which it has outgoing edges? A mouthful? This lecture will make things easy to follow. Topological sort is widely used in real world problems.|
|Here is the code in Java to implement topological sort.|
|Section 3: Shortest Path Algorithms|
|Graphs with simple edges (directed or undirected) are unweighted graphs. The distance table is an important data structure used to find the shortest path between any two vertices on a graph. This is used in almost every shortest path algorithm.|
|Visualize the shortest path algorithm using the distance table, step by step.|
|Shortest path implementation in Java.|
So far we only deal with unweighted graphs. Graphs whose edges have a weight associated are widely used to model real world problems (traffic, length of path etc).
A greedy algorithm is one which tries to find the local optimum by looking at what is the next best step at every iteration. It does not look at the overall picture. It's best used for optimization problems where the solution is very hard and we want an approximate answer.
Finding the shortest path in a weighted graph is a greedy algorithm.
|Dijkstra's algorithm is a greedy algorithm to find the shortest path in a weighted graph.|
The implementation of Dijkstra's algorithm in Java.
A weighted graph can have edge weights which are negative. Dealing with negative weights have some quirks which are dealt with using the Bellman Ford algorithm.
|Visualize how the Bellman Ford works to find the shortest path in a graph with negative weighted edges.|
If a graph has a negative cycle then it's impossible to find a shortest path as every round of the cycle makes the path shorter!
Implementation Of The Bellman Ford Algorithm
|Section 4: Spanning Tree Algorithms|
|A minimal spanning tree is a tree which covers all the vertices of of the graph and has the lowest cost. Prim's algorithm is very similar to Dijkstra's shortest path algorithm with a few differences.|
The minimal spanning tree is used when we want to connect all vertices at the lowest cost, it's not the shortest path from source to destination.
Let's see how we implement Prim's algorithm in Java.
|Kruskal's algorithm is another greedy algorithm to find a minimal spanning tree.|
Implementation Of Kruskal's Algorithm
|Section 5: Graph Problems|
|Given a course list and pre-reqs for every course design a course schedule so pre-reqs are done before the courses.|
|Find the shortest path in a weighted graph where the number of edges also determine which path is shorter.|
Loonycorn is us, Janani Ravi, Vitthal Srinivasan, Swetha Kolalapudi and Navdeep Singh. Between the four of us, we have studied at Stanford, IIM Ahmedabad, the IITs and have spent years (decades, actually) working in tech, in the Bay Area, New York, Singapore and Bangalore.
Janani: 7 years at Google (New York, Singapore); Studied at Stanford; also worked at Flipkart and Microsoft
Vitthal: Also Google (Singapore) and studied at Stanford; Flipkart, Credit Suisse and INSEAD too
Swetha: Early Flipkart employee, IIM Ahmedabad and IIT Madras alum
Navdeep: longtime Flipkart employee too, and IIT Guwahati alum
We think we might have hit upon a neat way of teaching complicated tech courses in a funny, practical, engaging way, which is why we are so excited to be here on Udemy!
We hope you will try our offerings, and think you'll like them :-)