0% found this document useful (0 votes)
74 views

Algorithms Practice Questions 2

This document appears to be a midterm examination for an algorithms course. It consists of 6 questions worth a total of 25 marks. The questions cover topics like topological sorting of graphs, designing algorithms to find local minima in arrays and maximum coin collection paths in a grid, analyzing recursive algorithms, and determining if a given flow in a network is maximum using the Ford-Fulkerson algorithm. Students are instructed to show their work and provide clear, rigorous answers.

Uploaded by

Anamta Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Algorithms Practice Questions 2

This document appears to be a midterm examination for an algorithms course. It consists of 6 questions worth a total of 25 marks. The questions cover topics like topological sorting of graphs, designing algorithms to find local minima in arrays and maximum coin collection paths in a grid, analyzing recursive algorithms, and determining if a given flow in a network is maximum using the Ford-Fulkerson algorithm. Students are instructed to show their work and provide clear, rigorous answers.

Uploaded by

Anamta Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE560 Algorithms (Spring’19)

Midterm Examination
Max Marks: 25 Time Allowed: 2 hours

Please give clear and rigorous answers.


Be to the point. Show your work.

Name: ERP:

Question 1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 marks
Consider the graph G shown on the right.

(a) [1 mark] List all the sources and sinks in G.

(b) [3 marks] Find the topological ordering of G using the DFS-


based algorithm discussed in the lectures.

Question 2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 marks
We discussed an algorithm in class that multiplies two n-bit binary integers x and y in time O(na ) where
a = log2 3. Call this procedure fastmultiply(x, y). Now we want to convert the decimal integer 10n
(a 1 followed by n zeros) into binary. Here is the algorithm (assume n is a power of 2):

function pwr2bin(n)
if n = 1: return 10102
else:
z = ???
return fastmultiply(z, z)

Fill in the missing details. Then give a recurrence relation for the running time of the algorithm and
solve the recurrence.

Question 3: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 marks
Given an array of n > 0 distinct integers, design an O(log n)-time algorithm to find a local minimum.
A local minimum in an array is an entry that is smaller than all of its adjacent entries. For example, in
the array [23, 45, 32, 12, 5, 3, 6, 56, 77, 33, 55], there are three local minima: 23, 3, and 33.

Page 1 of 2
CSE560: Algorithms Midterm Examination(Spring’19)

Question 4: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 marks
Coin-collecting problem. Several coins are placed in cells of an n × m board, no more than one coin per
cell. A robot, located in the upper left cell of the board, needs to collect as many of the coins as possible
and bring them to the bottom right cell. On each step, the robot can move either one cell to the right
or one cell down from its current location. When the robot visits a cell with a coin, it always picks up
that coin. Design a O(nm) time algorithm to find the maximum number of coins the robot can collect
and a path it needs to follow to do this.

Question 5: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 marks
Consider the following network (the numbers are edge capacities).

(a) [4 marks] Find the maximum s-t flow using Ford-


Fulkerson algorithm.

(b) [1 mark] Find minimum s-t cut in the network.

Question 6: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 marks
Suppose you are given a directed graph G = (V, E), two vertices s and t, a capacity function c : E → R+ ,
and a second function f : E → R. Describe an algorithm to determine whether f is a maximum (s, t)-flow
in G.

Page 2 of 2

You might also like