Вы находитесь на странице: 1из 21

QUESTION BANK

Dr. NAVALAR NEDUNCHEZHIYAN COLLEGE OF ENGINEERING

II - CSE

THOLUDUR 606 303, CUDDALORE DIST


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
ANNA UNIVERSITY CHENNAI
YEAR: II / SEM IV
CS2251 DESIGN AND ANALYSIS OF ALGORITHMS
UNIT I ALGORITHM ANALYSIS
Algorithm analysis Time space tradeoff Asymptotic notations Conditional asymptotic notation
Removing condition from the conditional asymptotic notation Properties of Big-oh notation Recurrence
equations Solving recurrence equations Analysis of linear search.
UNIT II DIVIDE AND CONQUER, GREEDY METHOD

Divide and conquer General method Binary search Finding maximum and minimum Merge sort
Greedy algorithms General method Container loading Knapsack problem.
UNIT III DYNAMIC PROGRAMMING

Dynamic programming General method Multistage graphs All-pair shortest paths Optimal binary
search trees 0/1 Knapsack Traveling salesperson problem.
UNIT IV BACKTRACKING

Backtracking General method 8 Queens problem Sum of subsets Graph coloring Hamiltonian
problem Knapsack problem.
UNIT V TRAVERSALS, BRANCH AND BOUND

Graph traversals Connected components Spanning trees Biconnected components Branch and Bound
General methods (FIFO and LC) 0/1 Knapsack problem Introduction to NP-hard and NP-completeness.
L: 45 T: 15 Total: 60
TEXT BOOKS
1. Ellis Horowitz, Sartaj Sahni and Sanguthevar Rajasekaran, Computer Algorithms / C++, 2nd Edition,
Universities Press, 2007.
2. Easwarakumar, K.S., Object Oriented Data Structures Using C++, Vikas Publishing House, 2000.
REFERENCES
1. Cormen, T.H., Leiserson, C.E., Rivest, R.L. and Stein, C., Introduction to Algorithms, 2nd Edition,
Prentice Hall of India Pvt. Ltd, 2003.
2. Aho, A.V., Hopcroft J.E. and Ullman, J.D., The Design and Analysis of Computer Algorithms, Pearson
Education, 1999.
3. Sara Baase and Allen Van Gelder, Computer Algorithms, Introduction to Design and Analysis, 3rd
Edition, Pearson Education, 2009.

Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK

II - CSE

CS2251-Design and Analysis of Algorithms


UNIT-I

(Algorithm Analysis)
PART-A

(1 MARKS)

1. What is the correct value to return to the operating system upon the successful completion of a
program?
a. -1 b. 1
c. 0
d. Programs do not return a value.
2. What is the only function all C++ programs must contain?
a. start() b. system()
c. main()
d. program()
3. What punctuation is used to signal the beginning and end of code blocks?
a. { }
b. -> and <- c. BEGIN and END d. ( and )
4. What punctuation ends most lines of C++ code?
a. . (dot) b. ; (semi-colon)
c. : (colon)
d. ' (single quote)
5. Which of the following is a correct comment?
a. */ Comments */
b. ** Comment **
c. /* Comment */
d. { Comment }
6. Which of the following is not a correct variable type?
a. Float
b. Real
c. Int
d. double
7. Which of the following is the correct operator to compare two variables?
a. :=
b. = c. Equal
d. ==
8. Which of the following is true?
a. 1
b. 66 c. .1 d. -1 e. All of the above
9. Which of the following is the boolean operator for logical-and?
a. &
b. && c. |
d. |&
10. Evaluate !(1 && !(0 || 1)).
a. True
b. False
c. Unevaluatable
11. Identify the correct statement
a. Programmer can use comments to include short explanations within the source code itself.
b. All lines beginning with two slash signs are considered comments.
c. Comments very important effect on the behaviour of the program d. both
12. The directives for the preprocessors begin with
a. Ampersand symbol (&) b. Two Slashes (//) c. Number Sign (#) d. Less than symbol
(<)
13. The file iostream includes
a. The declarations of the basic standard input-output library.
b. The streams of includes
and outputs of program effect. c. Both of these
d. None of these
14. There is a unique function in C++ program by where all C++ programs start their execution
a. Start()
b. Begin() c. Main()
d. Output()
15. Every function in C++ are followed by
a. Parameters b. Parenthesis
c. Curly braces
d. None of these
16. Which of the following is false?
a. Cout represents the standard output stream in c++.
b. Cout is declared in the iostream standard file
c. Cout is declared within the std namespace
d. None of above
17. Every statement in C++ program should end with
a. A full stop (.)
b. A Comma (,)
c. A Semicolon (;) d. A colon (:)
18. Which of the following statement is true about preprocessor directives?
a. These are lines read and processed by the pre-processor b. They do not produce any code by
themselves
c. These must be written on their own line d. They end with a semicolon
19. A block comment can be written by
a. Starting every line with double slashes (//)b. Starting with /* and ending with */
c. Starting with //* and ending with *// d. Starting with <!- and ending with -!>
20. When writing comments you can
a. Use code and /* comment on the same line
b. Use code and // comments on the same line
c. Use code and //* comments on the same line
d. Use code and <!- comments on the same line
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
Answers
1 2 3 4 5
c c a b c

II - CSE
6
b

7
d

8
e

9
b

10 11 12 13 14 15 16 17 18 19 20
a b c a c b d c d b b

PART-B

(2 MARKS)

21. Define an Algorithm.( A.U.NOV08) (A.U.NOV/MAY10) (A.U.NOV/MAY12)


An algorithm is a sequence of unambiguous instructions for solving a problem,i.e.,
for obtaining a required output for any legitimate input in a finite amount of time.
22. What is algorithmic?.
Algorithmic is more than a branch of computer science. It is the core of
computer science and ,in all fairness ,can be said to be relevant to most of science ,
business ,and technology.
23. What is algorithm design technique?( A.U.MAY10) (A.U.NOV/MAY11)
An algorithm design technique (or strategy or paradigm) is a general approach
to solving problems algorithmically that is applicable to a variety of problems from
different areas of computing.
24. How is an algorithm's time efficiency is measured? (A.U.NOV/MAY12)
The time efficiency is computed by
1) Measuring the input size If the input size is longer then algorithm runs
for a longer time.
2) Measuring the running time - To measure the running time ,it is necessary
to identify the basic operation of an algorithm and measure the time
taken to execute the basic operation.
25. How an algorithm is specified?( A.U.MAY10)
Algorithms can be specified using pseudo code which is a mixture of
natural language and programming language like constructs.
A pseudo code is more precise than a natural language,
and often yields more succinct algorithm descriptions.
26.What is correctness of algorithm?( A.U.APR09)
The algorithm's correctness is ascertained ,if the algorithm yields the required
results for every legitimate input in a finite amount of time.
27.. What are the two kinds of algorithm efficiency? (A.U.NOV/MAY12)
The two kinds of algorithm efficiency are :
Time efficiency which indicates how fast the algorithm runs.
Space efficiency which indicates how much extra memory
the algorithm needs.
28. What are important problem types?( A.U.NOV08)
The important problem types are
Sorting
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
Searching

II - CSE

String processing
Graph problems
Combinatorial problems
Geometric problems
Numerical problems
29. What are fundamental data structures?
Linear data structures Linked lists,stacks,queues
Graphs
Trees
Sets and dictionaries
30. What is a graph?( A.U.MAY10)
A graph G = (V,E) is defines by a pair of two sets:
A finite set V of items called vertices and set
E of pairs of these items called edges.
31 . How a graph is represented?
Graphs for computer algorithms are represented in two principal ways:
the adjacency matrix and adjacency linked lists.
32.What is a Abstract Data type?( A.U.NOV07) (A.U.NOV/MAY10)
It is a set of abstract objects with a collection of operations
that can be performed on them.
33 .What is an algorithm's basic operation?
It is an operation that contributes the most to the total running time of the algorithm.
Usually the basic operation is the most time consuming operation in the
algorithm's inner most loop.
34.what is the formula used to calculate the algorithm's running time?
The running time T(n) of a program implementing the algorithm on a
computer is given by the formula :
T(n) = Cop x C(n) where
Cop is the time of execution of an algorithm's basic operations
C(n) is the the number of times the basic operation is executed.
35. What is the order of growth?( A.U.MAY10) (A.U.NOV/MAY11) (A.U.NOV/MAY12)
The Order of growth is the scheme for analyzing an algorithm's
efficiency for different input sizes which ignores the multiplicative
constant used in calculating the algorithm's running time.
Measuring the performance of an algorithm in relation with the
input size n is called the order of growth.
36. What is the worst-case efficiency of an algorithm?
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
The worst-case efficiency of an algorithm is its efficiency for

II - CSE

the worst-case input of size n,which is an input of size n for which


the algorithm runs the longest among all possible inputs of that size.
37. List 5 of basic efficiency classes. (A.U.NOV/MAY12)
log n

logarithmic

linear

nlogn
n2

n-log-n
quadratic

38. What are asymptotic notations?


Asymptotic notation is the short hand way to represent the time complexity.
39.What is Big O Notation?( A.U.MAY10)
Big O notation is the method of representing the upper bound of algorithm's running time.
A function t(n) is said to be in O(g(n)),denoted by t(n) E O(g(n)),if t(n)
is bounded above by some constant multiple of g(n) for all large n,i.e.,if
there exists some positive constant c and some non negative integer n0
such that
t(n) <= cg(n) for all n >= n0.
What is L'Hopital's rule?
lim
n->oo

t(n)
--------

lim t'(n)
=

n->oo -------g(n)

g'(n)

PART-C

(16 MARKS)

40.Explain in detail the algorithm design and analysis process.( A.U.NOV07) (A.U.NOV/MAY10)
41.Explain in detail the important problem types.
42.Explain in detail the fundamental data structures.( A.U.NOV06)
43.Write Euclid's algorithm and explain the steps.( A.U.APR07)
44.Write sieve of Eratosthenes algorithm which generates consecutive primes and explain.
45.Explain in detail the general framework for analyzing an algorithm's efficiency.
( A.U.NOV08)
46.Explain with examples the worst-case, best-case and the average case efficiencies.
(A.U.NOV/MAY10) (A.U.NOV/MAY11)
47.What are asymptotic notations? Define and explain the three notations used by computer
scientists for analyzing the efficiency of algorithms. (A.U.NOV/MAY12)
48.What are basic efficiency classes? Explain in detail.( A.U.NOV09)
49.What is Order of growth? Plot the order of growth for different functions.

UNIT-II (Divide and Conquer Greedy Method)


PART-A

(1 MARKS)

50. Streams are


Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
II - CSE
a.
Abstraction to perform input and output operations in sequential media
b.
Abstraction to perform input and output operations in direct access media
c.
Objects where a program can either insert or extract characters to and from it
51 Which of the following is known as insertion operator?
a.
^ b.
Vc.
<<
d.
>>
52Regarding the use of new line character (/n) and endl manipulator with cout statement
a.
Both ways are exactly same b.
Both are similar but endl additionally performs flushing
of buffer
c.
endl cant be used with cout d.
\n cant be used with cout
53. Which of the following is output statement in C++?
a.
print
b.
Write
c.
Cout
d.
Cin
54. Which of the following is input statement in C++?
a.
cin
b.
Input
c.
Get
d.
none of above
55. By default, the standard output device for C++ programs is
a.
Printer
b.
Monitor
c.
Modem
d.
Disk
56. By default, the standard input device for C++ program is
a.
Keyboard
b.
Mouse c.
Scanner d.
None of these
57. Which of the following statement is true regarding cin statement?
a.
cin statement must contain a variable preceded by >> operator
b.
cin
does
not
process the input until user presses RETURN key c.
you can use more than one datum input
from user by using cind.
all of above
58. Which of the following is extraction operator in C++?
a.
^ b.
Vc.
<<
d.
>>
59. When requesting multiple datum, user must separate each by using
a.
a space b.
a tab character c.
a new line character
d.
all of above
60. Cin extraction stops execution as soon as it finds any blank space character
a.
true
b.
false
61. Observe the following statements and decide what do they do. string mystring; getline(cin,
mystring);
a. reads a line of string from cin into mystring
b.
reads a line of string from mystring into
cin
c.
cin cant be used this way
d.
none of above
62. Regarding stringstream identify the invalid statement
a.
stringstream is defined in the header file <sstream> b.
It allows string based objects
treated as stream
c.
It is especially useful to convert strings to numerical values and vice
versa.
d.
None of above
63. hich of the header file must be included to use stringstream?
a.
<iostream>
b.
<string>
c.
<sstring>
d.
<sstream>
64. Which of the following header file does not exist?
a.
<iostream>
b.
<string>
c.
<sstring>
d.
<sstream>
65. If you use same variable for two getline statements
a.
Both the inputs are stored in that variable
b.
The second input overwrites the first one
c.
The second input attempt fails since the variable already got its value
d.
You can not use same variable for two getline statements
66. The return 0; statement in main function indicates
a.
The program did nothing; completed 0 tasks b.
The program worked as expected
without any errors during its execution c.
not to end the program yet.d.
None of above
67. Which of the following is not a reserve keyword in C++?
a.
mutable
b.
Default
c.
Readable
d.
volatile
68. The size of following variable is not 4 bytes in 32 bit systems
a.
int
b.
long int
c.
short int
d.
float
69. Identify the correct statement regarding scope of variables
a.
Global variables are declared in a separate file and accessible from any program .
b.
Local variables are declared inside a function and accessible within the function
only.
c.
Global variables are declared inside a function and accessible
d.
Local variables are declared in the main body of the program
Answers
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK

II - CSE

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

PART-B

(2 MARKS)

70.What are recurrence relations?


Consider the function M(n) = M(n-1) + 1
Here the equation defines M(n) not explicitly ,i.e. as a function of nabob
implicitly as a function of its value at another point, namely n-1.
Such equations are called recurrence relations or recurrences.
71.What is the method of backward substitution?( A.U.MAY10)
Among several techniques available for solving recurrence relations,
one of the method used is called the method of backward substitution.
The method's idea will be clear by referring to the particular case as shown below :
M(n) = M(n-1) + 1 for n > 0.
M(0) = 0
= [M(n-2) + 1] + 1 = M(n-2) + 2
= [M(n-3) +1] + 2 = M(n-3) + 3
72.Write an algorithm for element uniqueness problem.
ALGORITHM Unique Elements(A[0..n-1])
for I <-- 0 to n-2 do
for j <-- i+1 to n-1 do
if A[i] = A[j] return false
return true
73.Write an algorithm for matrix multiplication problem. (A.U.NOV/MAY10)
ALGORITHM Matrix Multiplication(A[0..n-1,0..n-1],B[0..n-1,0..n-1])
for i <-- 0 to n-1 do
for j <-- 0 to n-1 do
C(i,j) <-- 0.0
for k <-- 0 to n-1
C(i,j) <-- C(i,j) + A[i,k] * B[k,j]
retutn C
74.Write an algorithm for finding the number of binary digits in the binary representation of a
positive decimal integer.
ALGORITHM Binary(n)
count <-- 1
while n > 1 do
count <-- count + 1
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
n <-- L n/2 _|

II - CSE

return count
Show the tree structure for recursive calls made in the problem of towers of Hanoi.

n
n
-1

n
-1
n
-2
2

...

n
-2

n
-2

...

...

n
-2
2

Write
an

1 1

algorith
m

for

finding
the nth Fibonacci number.
ALGORITHM F(n)
if n <= 1 return 1
else return F(n-1) + F(n-2)
75.What is algorithm visualization?( A.U.MAY10) (A.U.NOV/MAY11)
Algorithm visualization can be defines as the use of images
to convey some useful information about algorithms.
Two principal variations are
Static algorithm visualization
Dynamic Algorithm visualization(also called algorithm animation)
76. List 5 of basic efficiency classes.
log n

logarithmic

linear

nlogn
n2

n-log-n
quadratic

77. What are asymptotic notations?


Asymptotic notation is the short hand way to represent the time complexity.
78.What is the possible application of empirical analysis?
One of the possibilities of the empirical analysis is to attempt predicting
the algorithm's performance on the sample size not included in the experiment's sample.
79.What is algorithm animation?( A.U.APR09) (A.U.NOV/MAY11)
Algorithm animation shows a continuous movie like presentation of an
algorithm's operations. But this is more difficult to implement.

Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
80.What is the tool for analyzing the time efficiency of a non recursive algorithm?

II - CSE

For analyzing the time efficiency of non recursive algorithm we need


to find the input size as well as the basic operation of the algorithm.
The execution of the basic operation depends upon the input size n.
Then a sum is set up and is simplified using standard rules and formula.
81.What is linear congruent method?
It is a well known algorithm for generating pseudo random numbers.
ri <--

( a * ri-1 + b) mod m

82.Differentiate : Mathematical and Empirical analysis. (A.U.MAY08)


The algorithm is analyzed with the help of The algorithm is analyzed by taking some
mathematical derivations and there is no need sample
of specific input.

of

input

and

no

mathematical

derivation is involved

The principal weakness is limited applicability The principal strength is it is applicable for any
algorithm
The principal strength is it is independent of The principal weakness is it depends upon the
any input

sample input

83.What is the principal strength of mathematical analysis of algorithms?


The principal strength of mathematical analysis is its independence of specific inputs.
84.What is the principal strength of empirical analysis of algorithms?
The principal strength lies in the applicability to any algorithm.
PART-C

(16 MARKS)

85.Explain the general plan for analyzing efficiency of non recursive algorithms.
( A.U.MAY08)
86.Write an algorithm for element uniqueness problem and explain.
87.Write an algorithm for matrix multiplication and explain(A.U.NOV07)
88.Explain the general plan for analyzing efficiency of recursive algorithms.
( A.U.APR09) (A.U.NOV/MAY12)
89.Explain the Tower of Hanoi puzzle and how the recurrence relation
is solved for the moves. (A.U.NOV/MAY12)
90.Write short note on algorithm visualization and its applications.( A.U.APR07)
91.Design a non recursive algorithm for computing the product of two nix matrices and also find the
time efficiency of the algorithm. (A.U.NOV/MAY10) (A.U.NOV/MAY12)
92.Design a recursive algorithm to compute factorial function f(n) = n! (A.U.NOV/MAY12)
for an arbitrary non negative integer n and derive the recurrence relation.( A.U.NOV09)
93.Discuss the features of animation of an algorithm.
94.what is the empirical analysis of algorithm? Discuss its strength and weakness.
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK

II - CSE

UNIT-III (Dynamic Programming)


PART-A

(1 MARKS)

95.Find out the error in following block of code. If (x = 100)


a.
c.

Cout << x is 100;

100 should be enclosed in quotations


b. There is no semicolon at the end of first line
Equals to operator mistake
d. Variable x should not be inside quotation

95. Looping in a program means


a.
c.

Jumping to the specified branch of program


Both of above
d. None of above

b.

Repeat the specified lines of code

96. The difference between while structure and do structure for looping is
a.

In while statement the condition is tested at the end of first iteration b. In do structure the condition
is tested at the beginning of first iteration
c.
The do structure decides whether to start the loop
code or not whereas while statement decides whether to repeat the code or not d. In while structure
condition is tested before executing statements inside loop whereas in do structure condition is tested
before repeating the statements inside loop

97. Which of the following is not a looping statement in C?


a.

while b.

Until

c.

Do

d.

for

98. Which of the following is not a jump statement in C++?


a.

break b.

Goto

c.

Exit

d.

switch

99. Which of the following is selection statement in C++?


a.

break

b.

Goto

c.

Exit

d.

Switch

100. The continue statement


a.
c.

resumes the program if it is hanged b. resumes the program if it was break was applied
skips the rest of the loop in current iteration
d. all of above

101. Consider the following two pieces of codes and choose the best answer
CODE 1:
switch (x) {
case 1:
cout <<x is 1;
break;
case 2:
cout <<x is 2;
break;
default:
cout <<value of x unknown;
}
CODE 2
If (x==1){
Cout <<x is 1;
}
Else if (x==2){
Cout << x is 2;
}
Else{
Cout <<value of x unknown;
}

Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
a.

II - CSE

Both of the above code fragments have the same behaviour b. Both of the above code fragments
produce different effects
c.
The first code produces more results than second d. The second
code produces more results than first.

102. Observe the following block of code and determine what happens when x=2?
switch (x){
case 1:
case 2:
case 3:
cout<< "x is 3, so jumping to third branch";
goto thirdBranch;
default:
cout<<"x is not within the range, so need to say Thank You!" }
a. Program jumps to the end of switch statement since there is nothing to do for x=2b. The code inside
default will run since there is no task for x=2, so, default task is run
c.
Will display x is 3, so
jumping to third branch and jumps to thirdBranch.d. None of above

103. Which of the following is false for switch statement in C++?


a.
It uses labels instead of blocks
group of statement of a condition
d. None of above

c.

b. we need to put break statement at the end of the


we can put range for case such as case 1..3

104. The void specifier is used if a function does not have return type.
a.

True

b.

False

105. You must specify void in parameters if a function does not have any arguments.
a.
True
b.
False
106. Type specifier is optional when declaring a function
a.
True
b.
False
107. Study the following piece of code and choose the best answer int x=5, y=3, z;
a=addition(x,y)
a.
The function addition is called by passing the values b.
The function addition is called by
passing reference
108. In case of arguments passed by values when calling a function such as z=addidion(x,y),
a.
Any modifications to the variables x & y from inside the function will not have any effect
outside the function.b.
The variables x and y will be updated when any modification is done in
the function c.
The variables x and y are passed to the function addition
d.
None of
above are valid.
109. If the type specifier of parameters of a function is followed by an ampersand (&), that function call is
a.
pass by value b.
pass by reference
110. In case of pass by reference
a.
The values of those variables are passed to the function so that it can manipulate them
b.
The location of variable in memory is passed to the function so that it can use the
same memory area for its processing c.
The function declaration should contain ampersand
(&) in its type declaration d.
All of above
111. Overloaded functions are
a.
Very long functions that can hardly run
b.
One function containing another
one or more functions inside it.
c.
Two or more functions with the same name but
different number of parameters or type.
d.
None of above
112. Functions can be declared with default values in parameters. We use default keyword to specify
the value of such parameters.
a.
True
b.
False
113. Examine the following program and determine the output
#include <iostream>
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
using namespace std;
int operate (int a, int b)
{
return (a * b);
}
float operate (float a, float b)
{
return (a/b);
}
int main()
{
int x=5, y=2;
float n=5.0, m=2.0;
cout << operate(x,y) <<"\t"; cout << operate (n,m);
}
a.
10.0
5.0 b.
5.0
2.5
c.
10.0
5

II - CSE

return 0;
d.

10

2.5

Answers
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
c B a b d d
c
a
c
c
a
b
b
a
a
b
b
d
b
d

PART-B

(2 MARKS)

115.What is Brute force approach?( A.U.APR09)


Brute force is a straight forward approach to solving a problem,
usually directly based on the problem's statement and definitions of the concepts involved.
116.Give some examples of Brute force approach? (A.U.NOV/MAY10)
a) Selection sort
b) bubble sort
c) string matching
117.What is the principal strength of brute force approach?
Wide applicability and simplicity
118.What are the general plan of divide and conquer strategy?( A.U.NOV/MAY10)
The problem's instance is divided into several smaller instances of the same problem,
ideally about the same size.The smaller instances are solved typically recursively
The solutions obtained for the smaller instances are combined to get a solution to
the original problem.
119.How merge sort works? (A.U.NOV/MAY11)
Merge sort is the sorting algorithm which uses the divide and conquer strategy.
By this method the array is divided into two halves.
These halves are sorted recursively.
Then the sorted halves are merged to get the sorted array.
119.Explain the quick sort algorithm. (A.U.NOV/MAY12)
Quick sort is based on the divide-and-conquer approach.

Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
Unlike mergesort,which divides its input's elements according to their position in the array,

II - CSE

quicksort divides them according to their value. It rearranges elements of a given array
A[0..n-1] to achieve its positional situation where all elements before some
positions 's' are smaller than or equal to A[s]
120.What is a pivot?
In quick sort ,we partition the given array into two sub arrays based on
the value stored in the element called pivot.
121.Give the time efficiency and drawback of merge sort algorithm.
Time efficiency : The best, worst and average case time complexity of merge sort is O(n logn)
The drawbacks : (I) This algorithm requires extra storage to execute this method
(ii) This method is slower than the quick sort method
(iii) This method is complicated to code.
122.Explain briefly how binary search works.
Binary search is remarkably efficient algorithm for searching in a sorted array.
It works by comparing a search key 'K' with the array's middle element A[m].
If they match, the algorithm stops;
Otherwise,the same operation is repeated recursively for the first half of the array
if K < A[m] and for the second half if K > A[m].
123.Write the Binary search algorithm. (A.U.NOV/MAY12)
ALGORITHM Binary Search(A[0..n-1],K)
l <-- 0; r <-- n-1
while l <= r do
m <-- |_ (I + r)/2_|
if K = A[m] return m
else if K < A[m] r <-- m-1
else m <-- m + 1
return -1
124.What is the time complexity of binary search in worst case?
Let the number of comparisons made in binary search algorithm = Cw(n)
We have Cw(n) = Cw(|_n/2_|) + 1 for n > 1, Cw(1) = 1
= Cw(2k/2) + 1
= Cw(2k-1) + 1
= Cw(2k-2) + 2
Let n = 2k
Then

Cw(2k) = k + 1

125.What is a binary tree? (A.U.NOV/MAY10) (A.U.NOV/MAY11)


A binary tree T is defines as a finite set of nodes that is either empty or consists
of a root and two disjoint binary trees TL and TR called resp,
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
the left and right sub tree of the root.

II - CSE

Write a recursive algorithm for computing the height of a binary tree.


ALGORITHM Height(T)
//Input : A binary tree T
//Output : The height of T
if T = 0 return -1
else return max{Height( TL),Height( TR)} + 1
126.What is decrease-and-conquer technique?( A.U.NOV/DEC10)
The decrease-and-conquer technique is based on exploiting the relationship
between a solution to a given instance of a problem and solution
to a smaller instance of the same problem.
69.What are the three major variations of the decrease-and-conquer technique?
( A.U.NOV07)
The three major variations of the decrease-and-conquer technique are
Decrease by a constant decrease by a constant factor variable size decrease
127.Give an example of decrease by a constant
Consider the exponentiation problem of computing an
The relationship between a solution to an instance of size n and an
instance of size n and instance of size n-1 is obtained by the obvious formula :
an = an-1 . a
So the function f(n) = an can be computed by using the recursive definition
f(n) = | f(n-1) . a if n > 1
|

if n = 1

Give an example of variable size decrease


gcd(m,n) = gcd(n,m mod n)
In the above formula the arguments in the right hand side are always
smaller than the left hand side. The right hand side decreases by a variable factor.
128.Compare depth first search and depth first search.( A.U.MAY10) (A.U.NOV/DEC11)
SNO

Depth first traversal

Breadth first traversal

uses stack data structure

uses queue data structure

The DFS sequence is composed of The BFS sequence is composed of tree


tree edges and back edges

edges and cross edges

the efficiency of adjacency matrix the efficiency of adjacency matrix graph is


graph is O(V2)

O(V2)

129.What are the applications of depth first search? (A.U.APR/MAY10) (A.U.NOV/DEC10)


(A.U.NOV/DEC12)
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
To check connectivity and acclivity of graph

II - CSE

To find articulation point


PART-C

(16 MARKS)

130. Write a pseudo code for divide and conquer algorithm for merging two sorted arrays into a
single sorted one. Explain with an example.( A.U.APR09)
131.Design a recursive decrease-by-one algorithm for sorting the n real numbers in an array with
an example and determine the number of key comparisons and time efficiency of the
algorithm.
132.Explain quick sort algorithm with an example.( A.U.APR10)
133.Write an algorithm for Binary search tree and analyzes its efficiency.( A.U.MAY07)
77.Give a suitable example and explain the breadth first search and depth first search algorithms.
(A.U.NOV/DEC10) (A.U.NOV/DEC12)
134.Give an algorithm for selection sort. Analyze your algorithm's(A.U.JUNEO7)
135.Using the bruteforce string matching algorithm match the pattern EXAMPLE
from the text This_IS_A_SIMPLE_EXAMPLE. (A.U.NOV/DEC11)
136.What is the principal idea behind decrease and conquer? Compare and contrast decrease and
and conquer with divide and conquer approach.
137.Compare DFS and BFS.( A.U.APR06) (A.U.NOV/DEC10) (A.U.NOV/DEC12)
Explain in detail the general divide and conquer recurrence.

UNIT-IV (Backtracking)
PART-A

(1 MARKS)

138. A function can not be overloaded only by its return type.


a. True
b. False
139. A function can be overloaded with a different return type if it has all the parameters same.
. True
b. False
140. Inline functions involves some additional overhead in running time.
a. True
b. False
141. A function that calls itself for its processing is known as
a. Inline Function
b. Nested Function c. Overloaded Function d. Recursive Function
142. We declare a function with ______ if it does not have any return type
a. long
b. Double
c. Void
d. Int
143. Arguments of a functions are separated with
a. comma (,) b. semicolon (;)
c. colon (:)
d. None of these
144. Variables inside parenthesis of functions declarations have _____ level access.
a. Local
b. Global
c. Module
d. Universal
145. Observe following function declaration and choose the best answer:int divide( int a, intb=2)
a. Variable b is of integer type and will always have value 2
b. Variable a and b are of int
type and the initial value of both variables is 2
c. Variable b is international scope and will
have value 2 d. Variable b will have value 2 if not specified when calling function
146. The keyword endl
a. Ends the execution of program where it is written b. Ends the output in cout statement c. Ends
the line in program. There can be no statements after endl d. Ends current line and s
tarts
a
new line in cout statement.
147. Strings are character arrays. The last index of it contains the null-terminated character
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
II - CSE
a. \n
b. \t
c. \0
d. \1
148. Identify the correct statement
a. Programmer can use comments to include short explanations within the source code itself.
b.
All lines beginning with two slash signs are considered comments. c.
Comments
very
important effect on the behaviour of the program
d. both
149. The directives for the preprocessors begin with
a. Ampersand symbol (&) b. Two Slashes (//) c. Number Sign (#) d. Less than symbol
(<)
150. The file iostream includes
a. The declarations of the basic standard input-output library.
b. The streams of includes
and outputs of program effect. c. Both of these
d. None of these
151. There is a unique function in C++ program by where all C++ programs start their execution
a. Start()
b. Begin() c. Main()
d. Output()
152. Every function in C++ are followed by
a. Parameters b. Parenthesis
c. Curly braces
d. None of these
152. Which of the following is false?
a. Cout represents the standard output stream in c++.
b. Cout is declared in the iostream
standard file
c. Cout is declared within the std namespace
d. None of above
153. Every statement in C++ program should end with
a. A full stop (.)
b. A Comma (,)
c. A Semicolon (;) d. A colon (:)
154. Which of the following statement is true about preprocessor directives?
a. These are lines read and processed by the pre-processor b. They do not produce any code by
themselves
c. These must be written on their own line d. They end with a semicolon
155. A block comment can be written by
a. Starting every line with double slashes (//)
b. Starting with /* and ending with */
c. Starting with //* and ending with *//
d. Starting with <!- and ending with -!>
156. When writing comments you can
a. Use code and /* comment on the same line
b. Use code and // comments on the same
line
c. Use code and //* comments on the same line
d. Use code and <!- comments on the
same line
Answers
138

139

140

141

142

140

143

144

145

146

147

148

149

150

151

152

153

154

155

156

PART-B

(2 MARKS)

157.Define P,NP<hard and NP complete(A.U.NOV07)


P
P is the class of decision problems that can be solved by a deterministic

polynomial algorithm

NP
NP is the class of decision problem that can be solved by a non-deterministic
polynomial algorithm
158.Define NP complete(A.U.APR08)
NP complete
A problem that is NP- complete can be solved in polynomial time if all other NP- complete
problems can also in polynomial time
159.Define NP-hard(A.U.NOV/DEC10)

Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
II - CSE
If an NP-hard problems can be solved in polynomial time then all NP complete problems can
also solved in polynomial time
160.Give the relation among the P,NP,NP-complete and NP-Hard problems
Aliens from anther world come to earth and tells us that the 3-SAT problems is solvable in time
which of the following statements follows
161.What are deterministic algorithms
Deterministic algorithms are the algorithm with uniquely defined results and predictable terms of
output for a certain input
162.What are Nondeterministic algorithm(A.U.NOV/MAY10)
Non deterministic algorithm are the algorithm that allowed containing operations whose
outcomes are limited to a give set of possibilities instead of being uniquely defined
163.Difference between Deterministic and Nondeterministic algorithm(MAY/JUNE07)
Deterministic Algorithm

Nondeterministic Algorithm

Deterministic algorithms are the Non

deterministic

algorithm

are

the

algorithms with unique defined algorithms that allowed containing operation


results and predictable in term of whose outcomes are limited to a given set of
output for a certain input

possibilities instead of being uniquely define

164.What is called tractable problem?


Problems whose solution times are bounded by a polynomial of a small

degree

are

called

tractable algorithm that is there exists a polynomial time algorithm that solves the problems
165.What is called Intractable problems?
Problems whose best-know algorithm are not bounded by polynomial that is non polynomial are
called hard or intractable problems
166.When do problems are said to be polynomial equivalent?
Two problems L1 and L2 are said to be polynomial equivalent if and only if L1,L2 and L2,L1

PART-C

(16 MARKS)

167.Define AVL tree. Explain the construction sequence of AVL tree with a simple example.(
A.U.NOV07)

168.Define spanning tree. Discuss the design steps in Prisms algorithm to construct a minimum
spanning tree with an example. (A.U.NOV/DEC12) (A.U.APR/MAY11)
169.Construct a minimum spanning tree using Kruskal's algorithm with an example.( A.U.MAY09)
170.Solve the all pairs shortest path problem for the digraph with the weight matrix given below :
171.Give a suitable example and explain the breadth first search and depth first search
algorithms. (A.U.NOV/DEC11) (A.U.NOV/DEC12)
172.Give an algorithm for selection sort. Analyze your algorithm's(APR08)
173.Using the bruteforce string matching algorithm match the pattern EXAMPLE

Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
from the text This_IS_A_SIMPLE_EXAMPLE.

II - CSE

174.What is the principal idea behind decrease and conquer? Compare and contrast decrease and
conquer with divide and conquer approach.
175.Compare DFS and BFS.( A.U.NOV06)
176.Explain in detail the general divide and conquer recurrence. (A.U.NOV/DEC12)

UNIT-V (Travels Branch and Bound)


PART-A

(1 MARKS)

176 Program generation activity aims at


(A) Automatic generation of program

(B) Organize execution of a program

(C) Skips generation of program

(D) Speedens generation of program

177 Which amongst the following is not an advantage of Distributed systems?


(A) Reliability (B) Incremental growth(C) Resource sharing (D) None of the above
178 An imperative statement
(A) Reserves areas of memory and associates names with them
(B) Indicates an action to be performed during execution of assembled program
(C) Indicates an action to be performed during optimization

(D) None of the above

179 Which of the following loader is executed when a system is first turned on or restarted
(A) Boot loader (B) Compile and Go loader(C) Bootstrap loader (D) Relating loader
180 Poor response time is usually caused by
(A) Process busy(B) High I/O rates(C) High paging rates(D) Any of the above
181Throughput of a system is
(A) Number of programs processed by it per unit time
(B) Number of times the program is invoked by the system
(C) Number of requests made to a program by the system (D) None of the above
182 The blocking factor of a file is
(A) The number of blocks accessible to a file
(B) The number of blocks allocated to a file
(C) The number of logical records in one physical record

(D) None of the above

183 Which of these is a component of a process precedence sequence?


(A) Process name (B) Sequence operator ;(C) Concurrency operator , (D) All of the above
184 Which amongst the following is valid syntax of the Fork and Join Primitive?
(A) Fork <label> (B) Fork <label>Join <var> Join <label>
(C) For <var> (D) Fork <var>Join <var> join <var>
185 Nested Macro calls are expanded using the
(A) FIFO rule (First in first out)

(B) LIFO (Last in First out)

(C) FILO rule (First in last out)

(D) None of the above

186 A parser which is a variant of top-down parsing without backtracking is


(A) Recursive Descend. (B) Operator Precedence.(C) LL(1) parser. (D) LALR Parser.
Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
187 The expansion of nested macro calls follows
(A) FIFO rule.

II - CSE

(B) LIFO rule (C) LILO rule.

(D) priority rule.

188. In a two-pass assembler, the task of the Pass II is to


(A) separate the symbol, mnemonic opcode and operand fields.(B) build the symbol table.
(C) construct intermediate code.

(D) synthesize the target program.

189 A linker program


(A) places the program in the memory for the purpose of execution.
(B) relocates the program to execute from the specific memory are allocated to it.
(C) links the program with other programs needed for its execution.
(D) interfaces the program with the entities generating its input data.
190.Which scheduling policy is most suitable for a time-shared operating system
(A) Shortest-job First. (B) Elevator.(C) Round-Robin. (D) First-Come-First-Serve.
191. A critical section is a program segment
(A) which should run in a certain specified amount of time.
(B) which avoids deadlocks.
(C) where shared resources are accessed.
(D) which must be enclosed by a pair of semaphore operations, P and V.
192. An operating system contains 3 user processes each requiring 2 units of resource R .The
minimum number of units of R such that no deadlocks will ever arise is
(A) 4. (B) 3.(C) 5. (D) 6.
193. Locality of reference implies that the page reference being made by a process
(A) will always be to the page used in the previous page reference.
(B) is likely to be the one of the pages used in the last few page references.
(C) will always be to one of the pages existing in memory.
(D)will always lead to a page fault.
194. Which of these is not a part of Synthesis phase
(A) Obtain machine code corresponding to the mnemonic from theMnemonics table
(B) Obtain address of a memory operand from the symbol table
(C) Perform LC processing

(D) Synthesize a machine instruction or the machine form of a constant

195. The syntax of the assembler directive EQU is


(A) EQU <address space>

(B) <symbol>EQU<address space>

(C) <symbol>EQU

(D) None of the above

ANSWERS:
176

177

177

179

180 1

181

182

183

PART-B

184

185

186

187

188

189

190

1911 1921 193

194

195

(2 MARKS)

196.What is Reducibility?( A.U.MAY10)

Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
II - CSE
Let L1 and L2 be problems L1 reduces to L2 if and only if there is a way to solve L1 by a deterministic
polynomial time algorithm using a deterministic

algorithm that solves L2 in polynomial time

197.What is halting problems(A.U.NOV/DEC11)


The Halting problems is to determine for an arbitrary deterministic algorithm
A and input I, whether A with input I ever terminates which is undividable
198.What is called an NP algorithm(A.U.APR08)
If the checking stage of a nondeterministic algorithm is of polynomial time complexity then this
algorithm is called an NP algorithm
199.What is Satisfiability problems?
Satisfiability problem is to determine whether a formula is true for some
200.What is called a optimization problem?( A.U.APR07)
Any problems that involves the identification of an optimal value of a given cost function is known as an
optimization problem
201.What is called decision problem?
Any problems for which the answer is either zero or one is called a decision problem
202.Distinguish between P class problems with NP class problems( A.U.MAY07)
Class P

Class NP

P is the class of decision problems that NP is the class of decision problems that can be
can

be

solved

by

deterministic solved

by

non-deterministic

polynomial

polynomial algorithm

algorithm

It is called as deterministic polynomial

It is called as non-deterministic polynomial

203.What is best-first branch-and-bound?


It is sensible to consider a node with the best bound as the most promising although this dost not preclude
the possibility that an optimal solution will ultimately belong to a different branch of the state space tree
204.What is live node?
Live node is a node that has been generated but whose children have not yet been generated
205.What is dead node?( A.U.MAY10)
Dead node is a generated node that is not to be expanded any further all children
of a dead node have already been expanded
206.Explain briefly branch and bound technique for solving problems( A.U.NOV/DEC12)
Branch and bound refers to all state space search methods in which all children
of an E-node are generated before any other live node can become the E-node
PART-C

(16 MARKS)

207.Explain subset-sum problem and discuss the possible solution strategies using back tracking.(
A.U.NOV09) (A.U.NOV/DEC12)

Mrs.J.VANITHA ASST.PROFESSOR/CSE

QUESTION BANK
208.Discuss the solution for traveling salesman problem using Brach and bound technique.

II - CSE

209Solve the following instance of knapsack problem by branch-and-bound algorithm.


( A.U.APR08) (A.U.NOV/DEC11)
ITEM

WEIGHT

VALUE

$ 40

$42

$25

$12

The knapsack capacity W = 10


210.Differentiate between back tracking and branch-and-bound methods.( A.U.APR08)
211.Construct a state-space-tree and solve the 4 queen problem.( A.U.APR08)
212.Explain with an example the Hamiltonian circuit problem. (A.U.MAY/JUNE07)
213.Explain with an example the assignment problem. (A.U.JUNE08)
214.Write an algorithm Backtrack and explain. (A.U.NOV/DEC12)
215.Apply backtracking technique to solve the following instance of the subset sum problem. S =
{1,3,4,5} and d = 11. (A.U.NOV/DEC12) (A.U.APR/MAY11)

Mrs.J.VANITHA ASST.PROFESSOR/CSE

Вам также может понравиться