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

Ass 3

The document contains 18 questions about data structures and algorithms related to topics like arrays, quicksort, majority elements, inversions, range minimum queries, closest pair of points, polynomial multiplication, graph traversals, connectivity, bridges and Euler tours. The questions are to be solved by designing efficient algorithms and analyzing their time complexities.

Uploaded by

Lavesh Gupta
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)
37 views3 pages

Ass 3

The document contains 18 questions about data structures and algorithms related to topics like arrays, quicksort, majority elements, inversions, range minimum queries, closest pair of points, polynomial multiplication, graph traversals, connectivity, bridges and Euler tours. The questions are to be solved by designing efficient algorithms and analyzing their time complexities.

Uploaded by

Lavesh Gupta
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

ESO207: DATA STRUCTURE & ALGORITHM

NITIN SAXENA

ASSIGNMENT 3
POINTS: 00

DATE GIVEN: 01-MAR-2024 DUE: (DON’T SUBMIT)

Rules:
• You are strongly encouraged to work independently. That is the best
way to understand the subject.
• Write the solutions on your own and honorably acknowledge the
sources if any. cse.iitk.ac.in/pages/AntiCheatingPolicy.html
• Clearly express the fundamental idea of your proof/ algorithm before
going into the other proof details. REMEMBER: The distribution
of partial marks (in quizzes/exams) is according to the proof steps.
• There will be a penalty if you write unnecessary or unrelated details
in your solution. Also, do not repeat the proofs done in the class.
• Use this opportunity to practice writing in LaTeXed- or Word-
processed solution sheet.
Your Tutors could help in doubt resolution (depending on their
availability).

Question 1: [0 points] In class, we discussed an O(n) time algorithm


for finding a contiguous subarray in a 1D array which has the maximum
sum. Though we were able to solve the problem efficiently, there exists
a divide and conquer based approach, as well, which takes O(n log n)
time. Design the divide and conquer algorithm, stating clearly the
divide and conquer steps.

Question 2: [0 points] Recall the QuickSort algorithm, given an array


A of size n. This algorithm is based on the procedure Partition(A, ℓ, n)
that rearranges the subarray so that all elements smaller than A[ℓ]
precede A[ℓ], while all elements greater than A[ℓ] succeed A[ℓ].
Design a linear-time implementation of Partition(A, ℓ, n) that uses
only O(1) extra space.

Question 3: [0 points] The running time of QuickSort depends upon


the element we choose for partition in each recursive call. Use this
Page 1 of 3
observation to find out the worst-case running time of QuickSort on an
array of n elements?
What can be the best-case running time of QuickSort ?

Question 4: [0 points] Design an O(n log n) time algorithm for finding


1/2-majority element which is based on divide and conquer paradigm
in a way similar to Merge Sort or Counting Inversion.

Question 5: [0 points] In a size-n array A, element x is 1/3-majority


if its frequency is > n/3.
Design a linear-time algorithm for finding 1/3-majority element which
takes only constant space.

Question 6: [0 points] Recall the problem of finding the number of


inversions in an array A of size n. This problem was discussed in the
class. Now, let us call a pair (i, j) a significant-inversion if i < j and
A[i] > 2 · A[j] .
Design an O(n log n) time algorithm to count the number of significant-
inversions in an array.

Question 7: [0 points] In the class, you’ve seen the problem of RMQ


(range minima query) for a 1D array A of size n. The data structure
presented was O(n log n) preprocessing time and O(1) query. Could you
improve RMQ to linear-time preprocessing and constant-time query?

Question 8: [0 points] There are n points on the real line. A is an


array that stores the distance of each of these points from the origin.
Design an O(n log n) time algorithm, based on divide and conquer, to
find the closest pair of points.

Question 9: [0 points] You are given two univariate polynomials f (x),


g(x) of degree ≤ d over the complex field. Write an algorithm to
compute the product f · g. What is the best time complexity?

Question 10: [0 points] What is the running time of the BFS traver-
sal algorithm if the underlying graph is represented by an adjacency
matrix?

Question 11: [0 points] We discussed BFS traversal from a vertex in


an (undirected) graph. The same algorithm works for directed graphs
as well. How will BFS traversal from a vertex in directed graph look
like? What relationship can you establish on the levels of the endpoints
of an edge?
Page 2 of 3
Question 12: [0 points] Design an algorithm to count the number of
all possible shortest-paths tree, or BFS tree, rooted at a given vertex r
in a graph G = (V, E).
Question 13: [0 points] Design an O(n) time algorithm to determine
if a given undirected graph has a cycle.
Question 14: [0 points] You are given a graph G = (V, E) and two
vertices u and v. Furthermore, you are told that u and v belong to dif-
ferent connected components. The edge-size of a connected component
is defined as the number of edges present in that component.
You have to determine whether the component of u is smaller than
the component of v. Design a simple algorithm for this problem whose
running-time is of the order of the edge-size of the smaller component.
Question 15: [0 points] Suppose there is a connected graph G = (V, E).
You execute BFS traversal from a vertex v and get a rooted tree T .
Next, you execute a DFS traversal and get the same rooted tree. What
inference can you draw about the graph G?
Question 16: [0 points] You are given an undirected connected graph
G = (V, E). It may have many cycles in it. You want to assign a
direction to each edge in the graph so that the resulting directed graph
does not have a cycle. Design an efficient algorithm for this task.
Question 17: [0 points] You are given a connected graph G = (V, E).
An edge is said to be a bridge if its removal disconnects the graph.
Design an O(m + n) time algorithm to compute all bridges in G.
Question 18: [0 points] [This problem is challenging as it requires
graph theory and good coding skills!]
A graph G is Eulerian if the following property holds: Starting from
any vertex v, it is possible to make a tour on G which terminates at
v, such that each edge is visited exactly once (though a vertex may be
visited multiple times).
The corresponding tour is called an Euler tour of G. You have to
design an O(m + n) time algorithm to output an Euler tour of a graph
G, if it exists.

□□□

Page 3 of 3

You might also like