0% found this document useful (0 votes)
45 views2 pages

Group A

This document summarizes a PhD comprehensive examination in computer science and engineering. It contains 5 questions across 2 parts. Part 1 contains 4 short answer questions on big-O notation, algorithms, and data structures. Part 2 contains 2 programming questions - one to print diamond patterns for different input sizes, and another to write a recursive function to count qualifying substrings in a given string. Candidates must answer 2 questions from Part 1 and 1 question from Part 2 within the 1 hour 15 minute time limit.

Uploaded by

Somnath Pal
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)
45 views2 pages

Group A

This document summarizes a PhD comprehensive examination in computer science and engineering. It contains 5 questions across 2 parts. Part 1 contains 4 short answer questions on big-O notation, algorithms, and data structures. Part 2 contains 2 programming questions - one to print diamond patterns for different input sizes, and another to write a recursive function to count qualifying substrings in a given string. Candidates must answer 2 questions from Part 1 and 1 question from Part 2 within the 1 hour 15 minute time limit.

Uploaded by

Somnath Pal
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/ 2

PhD Comprehensive Examination

Department of Computer Science and Engineering

Group A

Date: 08-Apr-2021 Duration: 1 hour 15 minutes Maximum Marks: 30


h i
Answer any two questions from Part 1, and any one question from Part 2.

Part 1

A.1 Write short answers to the following parts.


(a) Prove/Disprove: 2 f (n) = O(n) if and only if f (n) = O(log n). (3)
(b) Mention which of the following functions is O(n). No derivations are needed. (2)
f (n) = f (n/3) + f (2n/3) + O(n).
g(n) = g(n/3) + g(2n/3) + O(1).
h(n) = h(n/3) + h(3n/4) + O(n).
(c) Let H be a min-heap stored in an array A in the contiguous representation. Assume that each level
of the min-heap H is sorted from left to right. Prove/Disprove: A is a sorted array. (3)
(d) Let A be an array of n integers each in the range [n2 , (n + 1)2 ]. Mention the worst-case running
time (in the big-O notation) of the most efficient algorithm to sort A. No need to propose an algorithm. (2)

A.2 You are given an unsorted array A = (a1 , a2 , a3 , . . . , an ) of n integers (positive, negative, or zero). Your
task is to find a non-empty contiguous subsequence ai , ai+1 , ai+2 , . . . , a j of A such that ai + ai+1 +
ai+2 + · · · + a j = 0. Report failure if no such subsequence exists. Propose an expected O(n)-time
algorithm to solve this problem. (10)

A.3 You have n currencies c1 , c2 , . . . , cn . The exchange rates of the currencies (positive floating-point
numbers) are given in a two-dimensional (n × n) table R, that is, R[i, j] stores the amount of currency
c j you get by selling one unit of currency ci . For every two currencies ci , c j , you are required to find
the sequence of distinct currencies ci , ci1 , ci2 , . . . , cik−1 , cik , c j for which the compound exchange rate

R[i, i1 ] × R[i1 , i2 ] × R[i2 , i3 ] × · · · × R[ik−1 , ik ] × R[ik , j]

is as large as possible. Here k = 0 is allowed, standing for the situation that you directly covert ci to
c j . Assume that you cannot make a profit by a cycle of exchanges, that is, for every choice of distinct
indices j1 , j2 , . . . , jt , we have

R[ j1 , j2 ] × R[ j2 , j3 ] × · · · × R[ jt−1 , jt ] × R[ jt , j1 ] < 1.

Reduce this problem to a problem on graphs. Mention how you solve the graph problem (along with
why you need the condition that the compound exchange rate of a cycle of exchanges is < 1). What
is the running time of your algorithm? (5 + 3 + 2)

— Page 1 of 2 —
Part 2

A.4 Let n be an odd positive integer. Write a C program that will print the edges and the diagonals of a
diamond for a given value on n. For example, the diamond patterns for n = 7, n = 9, and n = 11 are
as follows. (10)
*
* ***
* *** * * *
*** * * * * * *
* * * * * * * * *
******* ********* ***********
* * * * * * * * *
*** * * * * * *
* *** * * *
* ***
*

n=7 n=9 n = 11

A.5 Write a recursive C function int countSubstr(char* str, . . .) to count the number of substrings
of a given C string, where the substrings start and end with the same character and have length of more
than one (single character substrings are not counted). You can include additional arguments in the
function as per your requirement. As an example, if the input is csedept, then the output would be
one (only one substring ede that starts and ends with the same character e and having length more
than one). (10)

— END —

— Page 2 of 2 —

You might also like