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

Midterm 2

This document contains a midterm exam for a Design and Analysis of Algorithms course. The exam contains 3 questions worth a total of 18 marks. Question 1 asks for a greedy algorithm pseudo-code to solve a modified fractional knapsack problem that allows item repetition. Question 2 asks the student to perform a dynamic programming solution to find the maximum subarray sum of a given array and fill out the solution and subarray starting index arrays. Question 3 asks for an algorithm to compute the transitive closure of a directed graph, including a brief English explanation, pseudo-code, and time complexity analysis.

Uploaded by

aliidrees8600
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)
40 views3 pages

Midterm 2

This document contains a midterm exam for a Design and Analysis of Algorithms course. The exam contains 3 questions worth a total of 18 marks. Question 1 asks for a greedy algorithm pseudo-code to solve a modified fractional knapsack problem that allows item repetition. Question 2 asks the student to perform a dynamic programming solution to find the maximum subarray sum of a given array and fill out the solution and subarray starting index arrays. Question 3 asks for an algorithm to compute the transitive closure of a directed graph, including a brief English explanation, pseudo-code, and time complexity analysis.

Uploaded by

aliidrees8600
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

Name: ___________________ Roll #: ___________________ Section: _____________

National University of Computer and Emerging Sciences, Lahore Campus

Course: Design and Analysis of Algorithms Course Code: CS302


Program: BS(Computer Science) Semester: Fall 2020
Duration: 90 Minutes Total Marks: 18
Paper Date: 3-Feb-21 Weight 12.5%
Section: ALL Page(s): 5
Exam: Midterm 2
Instruction/Notes: Attempt the examination on the question paper and write concise answers. You can use
extra sheet for rough work. Do not attach extra sheets used for rough with the question
paper. Don’t fill the table titled Questions/Marks.

Question 1 2 3 Total

Marks /5 /5 /8 /18

Q1) In a twist to the fractional Knapsack problem, we allow the repetition of i.e. we can use any
number of copies of a certain element if we wish. What will be the new greedy algorithm for this
modified fractional knapsack? Give a pseudo-code. [5 Marks]

Department of Computer Science Page1


Name: ___________________ Roll #: ___________________ Section: _____________
Q2) Dry run the dynamic programming algorithm to find the Max Sub-array Sum of the following
input array, A:

-10 50 60 -150 20 80 -10 -5 100 -5

In array S, fill into S[i] : the optimal sum of a subarray ending at A[i]. In array P, fill into P[i]: the starting
index of the optimal array ending at A[i] [5 Marks]

Solution:

S[]

P[]

Department of Computer Science Page2


Name: ___________________ Roll #: ___________________ Section: _____________
Q3) Given a directed graph G (V,E), we might wish to determine whether G contains a path
from i to j for all vertex pairs (i, j) ∈ V. We define the transitive closure of G as the graph G*=(V,E*),

where E* = {(i, j) | there is a path from vertex i to vertex j in G}.

In other words you want to find out for each vertex u, which vertices are reachable from vertex u. Give an
efficient algorithm that computes the transitive closure of a given graph G(V,E). [8 Marks]

a) Briefly explain your algorithm in English.

b) Write pseudo code of your algorithm

c) Analyze its worst case time complexity.

Department of Computer Science Page3

You might also like