You are on page 1of 2

SAMPLE QUESTIONS

Important Instructions:
1. Write your program in C++.
2. Do not use any inbuilt function of array or string.
3. Input should be given by user (do not define it in your program)
4. Array must be dynamically initialized in C++ style (using new )
5. Don’t write or mark anything on paper.

Q1. Two Character strings may have many common substrings.


For example, photograph and tomography have several common substring of length one
(i.e., single letters), and common substring ph, to, and ograph (as well as all the substrings
of ograph). The maximum common substring length is 6.
(a) WAP to find the maximum common substring from given two strings and also
find maximum common substring length.

Q2. Let L be an array of n distinct integers.


(a) WAP to find the length of a longest increasing subsequence of entries in L, For
example if the entries are 11,17,5,8,6,4,7,12,3, then longest increasing subsequence
is 5,6,7,12.
(b) How much time does your algorithm take?

Q3. Let X = x1x2…xn and Y = y1y2….yn be two character strings. We say that X is a
cyclic shift of Y if there is some r such that X = y r+1…yny1…yr.
WAP to determine whether X is cyclic shift of Y or not.

Q4. L is an array containing n integers, and we want to find the maximum sum for a
contiguous sub-sequence of elements of L.
For example, consider the array with elements.
38 -62 47 -33 28 13 -18 -46 8 21 12 -53 25
The maximum subsequence sum for this array is 55.The maximum subsequence
occurs in positions 3 through 6 (inclusive)
(If all elements of a sub-sequence are negative, we define the maximum sub-sequence to be the
empty sequence with sum equal to zero.)

WAP to find the maximum sub-sequence sum in array in O (n).


Q5. Write a program to determine how many different ways there are to give a cents
in change using any coins from among pennies, nickels, dimes, quarter, & half-dollars.

For example, there are six ways to give 17 cents change: a dime, a nickel, & two pennies; a
dime & seven pennies; three nickels & two pennies; two nickels & seven pennies; one
nickels & 12 pennies; & 17 pennies.

Q6. Write a function that takes a number n as an argument and returns (or
outputs) every possible unique substrings (of the first n letters of the alphabet.
For example, substrings(5) could be:
a ab abc abcd abcde b bc bcd bcde c cd cde d de e
Q7. Write a program to reverse words in sentence.

Page 1
E.g. If input : Welcome to string program
Output: emocleW ot gnirts margorp

Q8. Write a program to cyclic shift a string of length l, by value r without using any
other temporary variable in O(n).

Q9. Write a program to fine the maximum common substring between given three
strings.

Q10. Write a program to find whether a string is cyclic shift of second and third string
i.e. X if cyclic shift of Y & Z

Q11. Make a program that Input month and year and prints out a calendar for that
month in a nice calendar format. Date should be greater than 01/01/2000

For instance, for May 2012, it should print out something like:

MAY 2012

M T W T F S S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

1/1/2000 is Saturday , Leap years are 2000,2004,2008,2012

Q12. Write a program to find the maximum common substring between given three
strings.

Q13. Write a program to find whether a string is cyclic shift of second and third string
i.e. X if cyclic shift of Y & Z

Page 2

You might also like