Subtask2: A Maze Simulation: 1 Problem Statement
Subtask2: A Maze Simulation: 1 Problem Statement
Subtask2: A Maze Simulation: 1 Problem Statement
1 Problem Statement
You are the new manager of Swiggy. The old navigation system was too time
consuming for customers due to which you company’s sales have been falling
rapidly down. You have been given the task to come up with a new navigation
algorithm such that using your algorithm, your delivery boy(s) will finish all
their delivery by the earliest.
2.2 Algorithm
We will modify Dijkstra’s Algorithm in such a way so as we can solve our
delivery problem. Modification includes applying Dijkstra’s algorithm on the
starting delivery point. Then from that we have distance from start to all other
points as well. Now, we approximate the distance from the first visited point
to all the other points using cosine rule. We approximate the paths as straight
lines and the angle can be calculated using property of vectors
~~
cos(θ) = AABB
After doing this for all the remaining delivery points, we choose the shortest
length. We then perform Dijkstra’s again from that node to reach our approxi-
mated closest delivery point. We repeat this process until all the delivery points
are visited.
1
an array d. Initially, we mark all the distances as IN F IN IT Y and d[start] as 0.
We maintain a data structure (preferably a min-heap) to pick the closest vertex
v. Next, we look at the neighbours of v, u, where len is the weight of the edge
between the v and u. If d[u] > d[u] + len, then this means that we have found
a shorter path for u and push this into the data-structure. If some vertex w is
unreachable from starting vertex s, then d[w] = IN F IN IT Y . The algorithm
ends once the data-structure is empty. One constraint over this algorithm is
that it won’t work with negative edge weights.
d[k] = 0;
intv = content.second;
for autoedge : adj[v] do
intto = edge.f irst, len = edge.second;
return
2.3 Correctness
Proof of Dijkstra’s algorithm by Induction:
2
For the first iteration, i.e., the starting node s, the statement is true as
d[s] = 0 which is indeed the shortest distance to s.
Suppose this statement is true for k iterations, then we need to prove it for
k + 1 iterations. Let v be the vertex in the current iteration. Suppose l[v] is the
shortest path to v. We need to prove that d[v] = l[v].
Consider the shortest path to v be P . The path can be divided into two parts
P 1 and P 2 such that P 1 contains only marked vertices(at least the starting
vertex s). Now, P2 may or may not contain marked vertices. (at least it starts
with an unvisited vertex). Let the starting vertex of P 1 be p and the last vertex
of P 2 be q.
First, we prove d[p] = l[p]. This is true because as on one of the previous
iterations we chose the vertex q and performed relaxation on it.
Since the edges’ weights are non-negative, l[p] does not exceed l[v]. Given
that, l[v] <= d[v], we get d[p] = l[p] <= l[v] <= d[v]. Also, d[p] >= d[v] since
both p and v are unmarked and we chose v at the current iteration. Therefore,
d[p] = d[v]. Hence, d[v] = l[v].