0% found this document useful (0 votes)
15 views3 pages

ESO207A: Data Structures and Algorithms: Theoretical Assignment 2 Due Date: 7th October, 2023

TA2

Uploaded by

Rajit Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

ESO207A: Data Structures and Algorithms: Theoretical Assignment 2 Due Date: 7th October, 2023

TA2

Uploaded by

Rajit Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ESO207A: Data Structures and Algorithms

Theoretical Assignment 2
Due Date: 7th October, 2023

Total Number of Pages: 3 Total Points 100


Instructions-
1. For submission typeset the solution to each problem and compile them in a single pdf file. Hand-written
solutions will not be accepted. Use LATEX only for typesetting.
2. Start each problem from a new page. Write down your Name, Roll number and problem number clearly
for each problem.
3. For each question, give the pseudo-code of the algorithm with a clear description of the algorithm.
Unclear description will receive less marks. Less optimal solutions will receive only partial marks.
4. Don’t add any screenshots of code, etc. in your solution.

Question 1. Search Complicated


You are given an array A[0, . . . , n − 1] of n distinct integers. The array has following three properties:
• First (n−k) elements are such that their value increase to some maximum value and then decreases.
• Last k elements are arranged randomly
• Values of last k elements is smaller compared to the values of first n − k elements.
(a) (10 points) You are given q queries of the variable Val. For each query, you have to find out if Val
is present in the array A or not. Write a pseudo-code for an O(k log(k) + q log(n)) time complexity
algorithm to do the task.
(Higher time complexity correct algorithms will also receive partial credit)
(b) (5 points) Explain the correctness of your algorithm and give the complete time complexity analysis
for your approach in part (a).
Question 2. Perfect Complete Graph
A directed graph with n vertices is called Perfect Complete Graph if:
• There is exactly one directed edge between every pair of distinct vertices.
• For any three vertices a, b, c, if (a, b) and (b, c) are directed edges, then (a, c) is present in the graph.
Note: Outdegree of a vertex v in a directed graph is the number of edges going out of v.
(a) (20 points) Prove that a directed graph is a Perfect Complete Graph if and only if between any
pair of vertices, there is at most one edge, and for all k ∈ {0, 1, . . . , n − 1}, there exist a vertex v in
the graph, such that Outdegree(v) = k.
(b) (10 points) Given the adjacency matrix of a directed graph, design an O(n2 ) algorithm to check
if it is a perfect complete graph or not. Show the time complexity analysis. You may use the
characterization given in part (a).

1
Question 3. PnC (20 points)
You are given an array A = [a1 , a2 , a3 , . . . , an ] consisting of n distinct, positive integers. In one
operation, you are allowed to swap the elements at any two indices i and j in the present array for a
cost of max(ai , aj ). You are allowed to use this operation any number of times.
Let Π be a permutation of {1, 2, . . . , n}. For an array A of length n, let A(Π) be the permuted array
A(Π) = [aΠ(1) , aΠ(2) , . . . , aΠ(n) ].
We define the score of an array A of length n as
i=n−1
X
S(A) = |ai+1 − ai |
i=1

(a) (5 points) Explicitly characterise all the permutations A(Π0 ) = [aΠ0 (1) , aΠ0 (2) , aΠ0 (3) . . . , aΠ0 (n) ] of
A such that
S(A(Π0 )) = min S(A(Π))
Π

We call such permutations, a “good permutation”. In short, a good permutation of an array has
minimum score over all possible permutations.
(b) (15 points) Provide an algorithm which computes the minimum cost required to transform the
given array A into a good permutation, A(Π0 ).
The cost of a transformation is defined as the sum of costs of each individual operation used in the
transformation.
You will only be awarded full marks if your algorithm works correctly in O(n log n) in the worst
case, otherwise you will only be awarded partial marks, if at all.
(c) (0 points) Bonus: Prove that your algorithm computes the minimum cost of converting any array
A into a good permutation.
Some examples are given below for the sake of clarity:
• Regarding the operation:
Array (i, j) Cost
A = [7, 2, 5, 4, 1] (1, 3) max(a1 , a3 ) = max(7, 5) = 7
P1 = [5, 2, 7, 4, 1] (2, 5) max(2, 1) = 2
P2 = [5, 1, 7, 4, 2] (3, 5) max(7, 2) = 7
Final Array = [5, 1, 2, 4, 7] – –
In essence, the order of operations contributes significantly to the cost of a transformation.
• Regarding the cost of a transformation:
The cost of transforming the array A = [7, 2, 5, 4, 1] to P3 = [5, 1, 2, 4, 7] using the exact sequencce
of operations mentioned above is 7 + 2 + 7 = 16.
• Regarding permutations:
Let Π be such that [1, 2, 3, 4, 5]  [5, 3, 1, 4, 2] and A = [7, 2, 5, 4, 1], then A(Π) = [5, 1, 2, 4, 7].

Question 4. Mandatory Batman Question (20 points)


Batman gives you an undirected, unweighted, connected graph G = (V, E) with |V | = n, |E| = m, and
two vertices s, t ∈ V .
He wants to know dist(s, t) given that the edge (u, v) is destroyed, for each edge (u, v) ∈ E. In other
words, for each (u, v) ∈ E, he wants to know the distance between s and t in the graph G0 = (V 0 , E 0 ),
where E 0 = E\{(u, v)}.
Some constraints:

2
• The dist definition and notation used is the same as that in lectures.
• It is guaranteed that t is always reachable from s using some sequence of edges in E, even after any
edge is destroyed.
• To help you, Batman gives you an n × n matrix Mn×n . You have to update M [u, v] to contain the
value of dist(s, t) if the edge (u, v) is destroyed, for each (u, v) ∈ E.
• You can assume that you are provided the edges in adjacency list representation.
• The edge (u, v) is considered the same as the edge (v, u).
(a) (12 points) Batman expects an algorithm that works in O(|V | · (|V | + |E|) = O(n · (n + m)).
(b) (4 points) He also wants you to provide him with proof of runtime of your algorithm, i.e., a Time-
Complexity Analysis of the algorithm you provide.
(c) (4 points) Lastly, you also need to provide proof of correctness for your algorithm.

Question 5. No Sugar in this Coat (15 points)


You are given an undirected, unweighted and connected graph G = (V, E), and a vertex s ∈ V ,
with |V | = n, |E| = m and n = 3k for some integer k. Let distance between u and v be denoted by
dist(u, v) (same definition as that in lectures).
G has the following property:

• Let Vd ⊆ V be the set of vertices that are at a distance equal to d from s in G, then

∀i≥0: u ∈ Vi , v ∈ Vi+1 ⇒ (u, v) ∈ E

Provide the following:


(a) (10 points) An O(|V | + |E|) time algorithm to find a vertex t ∈ V , such that the following property
holds for every vertex u ∈ V :
min(dist(u, s), dist(u, t)) ≤ k
Note that your algorithm can report s as an answer if it satisfies the statement above.
(b) (5 points) Proof of correctness for your algorithm.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy