Lab Week 10 Questions-1
Lab Week 10 Questions-1
Easy
For this week - let’s just try to implement some of the algorithms that we have
🙂
learned in the class. The algorithms might seem tough, so its best to understand
them first, and try to code them up
Let’s start with the Topological Sort Algorithms. We will use the same example as class -
Given a set of courses and pre-requisites, we want to determine if it is possible to complete
all the courses. The condition we need to check is that - we can only do a course if we have
already done its pre-req.
Infact, using Topo-sort algorithm, you can also give a valid ordering of courses. You should
try coding this up, and submit your solution here. If you want to also return ordering of
courses, submit your solution here instead.
You might want to recall Tarjan’s algorithm from your class notes/slides.
Given a Graph G = (V, E), the task is to find the strongly connected components using
Tarjan’s algorithm.
Given a graph G = (V, E), the task in this problem is to find the shortest path from a node to
all other nodes in the graph. You should use the algorithm that you have learned in the class.
😀
Once you know how to implement these algorithm, we should now move to some interesting
applications.
Let’s start one which applies the shortest path algorithm. In this problem, you need to find a
path with “minimum effort”. According to the question - “A route's effort is the maximum
absolute difference in heights between two consecutive cells of the route.”
While this question might seem daunting at first, remember that Dijkstra is a “greedy”
algorithm - and you should just be greedily trying to pick the route which requires minimum
effort.
The first step in such a problem is to figure out what topic it belongs to (The title is
intentionally kept vague to make you think about this). Once you are able to figure that out -
convert this problem in the form that you are able to visualize, and use one of the algorithms
of section 1. For more hints, do ask your group TA.
Hard
Most of the problems, using the topics for this week, are generally hard. (Infact, the TA who
made this sheet had to spend more time finding the medium problems than the hard ones).
You are encouraged to discuss these problems - with your friends and your group TAs.
Again, your first thoughts should be on which topic this problem belongs to.
Once you have done this problem - you should also reason about the Time and Space
Complexity of your algorithm.