You are on page 1of 11

Question 1

Marks: 1 Given a weighted graph below and you are using the Dijkstra algorithm t
o find the shortest path from the vertex A to the vertex B. What is the label of
the vertex D when the shortest path from A to B is determined?
Choose one answer. a. 17
b. 21
c. infinity
d. 5
Question 2
Marks: 1
Assume that the sort function is executed with array {5 3 8 9 1 7 0 2 6 4}. What
is it's output after iteration i=4 of the outer for loop completed
Choose one answer. a. {9 8 7 6 5 4 3 2 1 0}
b. {1 3 5 8 9 7 0 2 6 4}
c. {1 3 5 8 9 0 2 4 6 7}
d. {9 8 5 3 1 7 0 2 6 4}
Question 3
Marks: 1 Consider the following function:
Which call will result in the most recursive calls?
Choose one answer. a. fun(100);
b. fun(0);
c. fun(-1012);
d. fun(1012);
Question 4
Marks: 1 Consider the following algorithm:
What is output after executing unknown(s,0,12), where s = 1352467642135?
Choose one answer. a. false
b. true
c. Stack overflow error.
Question 5
Marks: 1 Which of the following represents the efficiency of the insertion sort?
Choose one answer. a. O(n2)
b. O(1)
c. O(n)
d. O(log n)
Question 6
Marks: 1 Give the result of the depth-first traversal on the graph in figure bel
ow, starting from vertex A.
Choose one answer. a. A B C D E F
b. A B C F E D
c. A B C D F E
d. A B D E C F
Question 7
Marks: 1 Consider the AVL tree below. What is the breadth first traversal of the
tree after inserting a node with value 22?
Choose one answer. a. 35, 20, 45, 10, 40, 25, 22, 30
b. 35, 20, 45, 10, 30, 40, 25, 22
c. 35, 20, 45, 10, 25, 40, 22, 30
d. 35, 20, 45, 10, 25, 40, 30, 22
Question 8
Marks: 1 Which algorithms have the complexity of O(n lgn)
Choose at least one answer. a. Bubble sort
b. Shell sort
c. Quick sort in the best case.
d. Heap sort in the worst case.
Question 9
Marks: 1 Suppose we are implementing a stack using a singly linked list where th
e head of the list is treated as the top of the stack.
Specify the correct implementation of push() method of the stack. (Choose the mo
st suitable one)
Choose one answer. a.
void push(Object x)
{ Node p = new Node(x);
p.next = head;
}

b.
void push(Object x)
{ Node p = new Node(x);
p.next = null;
head=p;
}

c.
void push(Object x)
{ Node p = new Node(x);
p.next = head;
head=p.next;
}

d.
void push(Object x)
{ Node p = new Node(x);
p.next = head;
head=p;
}

Question 10
Marks: 1 Consider the following sort algorithm:
Which of the following statement is correct:
Choose one answer. a. This algorithm sorts elements of an array in ascending o
rder.
b. This algorithm can be applied to arrays of integers only.
c. This algorithm sorts elements of an array in descending order.
Question 11
Marks: 1 A source emits a message from an ASCII set 8-bit {'A', 'B', 'C', 'D'} u
sing Huffman encoding, with probabilities:
P('A') = 0.27, P('B') = 0.36, P('C') = 0.16 and P('D') = 0.21.
The contents of the message as follows (14 characters):
AABBCDDAABBBCD
Find the compression ratio?
Choose one answer. a. 18%
b. None of the others.
c. 46%
d. 60%
e. 25%
Question 12
Marks: 1 What is the worst-case time for binary search finding a single item in
an array?
Choose one answer. a. Logarithmic time
b. Constant time
c. Linear time
d. Quadratic time
Question 13
Marks: 1 Select correct statements about Linked List:
Choose at least one answer. a. The efficiency of search in singly and doubly l
inked lists can be improved by dynamically organizing the list in a certain mann
er using Self-Ogranizing Lists.
b. In the worst case, search time of skip list is O(lgn)
c. Skip lists was motivated by the need to speed up the searching process.
d. The nodes in doubly linked list contain only references to the predecessors
.
answer: The efficiency of search in singly and doubly linked lists...// Skip lis
ts was motivated by the need to
Question 14
Marks: 1 Use the Huffman code tree below. What is the result of decoding the str
ing 110000100100 ?
Choose one answer. a. CAABBBBA
b. AABBABAB
c. AABBBCAB
d. BABABBBA
Question 15
Marks: 1 Consider the following heapsort algorithm:
Select a correct statement.
Choose one answer. a. All of the others.
b. None of the others.
c. The total number of moves in all executions of moveDown in the second phase
is O(lgn).
d. In the first loop, moveDown is called n/2 times in any case.
answer: None of the others
Question 16
Marks: 1 Consider the following algorithm in Java:
The above algorithm will ________
Choose one answer. a. check whether the height of the right subtree is greater
than the height of the left subtree.
b. None of the others.
c. check whether a binary tree is balanced.
d. check whether the height of left subtree is greater than the height of righ
t subtree.
answer:
If the left subtree has height 2 greater than the right sub-tree we use rotR
answer: If the left subtree has height 2 greater than the right sub-tree we use
rotR
if the right subtree has height 2 greater than the left sub-tree we use rotL
answer: if the right subtree has height 2 greater than the left sub-tree we use
rotL
Question 17
Marks: 1 Consider the following function:
void fun(int n)
{ if (n < 0)
{ System.out.println( - );
fun(-n);
}
else if(n<15)System.out.println( n );
else
{ fun(n/15);
System.out.println( n%15 );
}
}
What values of n are directly handled by the stopping (base) case?
Choose one answer. a. n >= 0 && n<15
b. n >= 15
c. n < 15
d. n < 0
Question 18
Marks: 1 Suppose the frequencies of use of characters is given by:
A [10%], B [20%], C [70%]
We want to improve the average length of the codeword by applying the Huffman al
gorithm to pairs of letters instead of single letters. What is the Huffman code
of AB?
Choose one answer. a. 01
b. 0110
c. 001
d. 0010
Question 19
Marks: 1
Identify which alogrithm the above code implements
Choose one answer. a. Heap sort
b. Bubble sort
c. Radix Sort
d. Quick sort
Question 20
Marks: 1 Consider the following algorithm:
Choose one answer. a. 5
b. 8
c. 3
d. 9
Question 21
Marks: 1 Suppose the Graph class has the form:
class Graph
{int [][] a; int n; char [] v;
... // other member functions
}
n is the number of vertices. Vertices are indexed from 0 to n-1. v[i] is the lab
el of vertex i such that v[0] = 'A', v[1]='B', v[2]='C', v[3]='D', v[4]='E', v[5
]='F',...
a is an adjacency matrix. a[i][j] , i,j=0,1,...,n-1, take value 0 or 1 as usual.

The Graph class has the following member functions:
void visit(int i)
{ System.out.print(" " + v[i]);
}
void fun(boolean visited[], int i)
{ visit(i);visited[i] = true; // visited[i] = true means the vertex i is denoted
as visited
for(int j=0;j<n;j++)
if(a[i][j]>0 && (!visited[j])) fun(visited,j);
}
void fun(int k)
{ int i,h; boolean [] visited = new boolean[20];
for(i=0;i<n;i++) visited[i]=false;
fun(visited,k);
System.out.println();
}
Consider the graph g below (view a picture). What is the output when the stateme
nt:
g.fun(0); // traverse from the vertex 'A'.
is run?
Choose one answer. a. A C E B D
b. A B E D C
c. A B E C D
d. A B E D C F
e. A B E C D F
Question 22
Marks: 1 Select the incorrect statement about binary trees (regardless of the or
der in which the values are inserted into the tree).
Choose one answer. a. Always have multiple links per node.
b. Can be sorted efficiently.
c. Always have the same shape for a particular set of data.
d. Are nonlinear data structures.
answer: Always have the same shape for a particular set of data
Question 23
Marks: 1 Which of the following statement about the Recursion is true
Choose one answer. a. The recursive version increases program readability, imp
roves self-documentation, and simplifies coding.
b. Tail recursion is characterized by the use of only one recursive call at th
e very end of a method implementation.
c. The backtracking technique uses recursion
d. All of the others
answer:
Question 24
Marks: 1 Specify the correct implementation of pop() method of a stack of Intege
rs.
This stack uses java.util.ArrayList for storing data and the end of the list is
treated as the top of the stack. (Choose the most suitable one)
Choose one answer. a.

b.

c.

d.

Question 25
Marks: 1 Select correct statement about Run-length encoding.
Choose one answer. a. A serious drawback of run-length encoding is that it rel
ies entirely on the occurrences of runs.
b. Run-length encoding is very useful when applied to files that are almost gu
aranteed to have many runs of at least five characters.
c. All of the others except the option "None of the others".
d. None of the others.
Question 26
Marks: 1 Select the statement that is the most correct.
Basically, the complexity of finding the position of the minimum value in a doub
ly-linked list of integer numbers is .....
Choose one answer. a. O( 1 )
b. O( n )
c. O( n2 )
d. O( nlogn )
Question 27
Marks: 1 In a simple hash function, the division method is used for page-based a
ddress translation: a pair of new logical page number "101000" and its correspon
ding physical page number "0010" is stored into the page table shown below. Whic
h of the following indexes is used to place them in the table? Here, the given l
ogical page number is divided by 7, and its remainder is used as the index of th
e page table. If the slot specified by the index value is already taken, the tab
le is searched forward from that slot to find the next empty slot.
Choose one answer. a. 111
b. 000
c. None of the others.
d. 110
e. 010
Question 28
Marks: 1 In a hash algorithm, when a collision occurs, the sequence of index num
bers of a hash table probed within the WHILE loop of the following function:
private static int hash(Object object) {
// CAPACITY is the capacity of the hash table
int h = (object.hashCode() & MASK) % CAPACITY;
if ( hashTable [h]!= null) {
int h0 = h;
int jump = 1;
while (hashTable[h] != null) {
h = (h0 + jump*jump)%CAPACITY;
++jump;
}
}
hashTable[h] = object;
return h;
}
What is the name of this coliision resolution algorithm?
Choose one answer. a. Quadractic probing
b. Linear probing
c. Open addressing
d. Double hashing
Question 29
Marks: 1 Show what would happen if we applied the following method to a queue?
void foo(Queue<T> queue) {
for (int i=1; i<queue.size(); i++) {
queue.add(queue.remove());
}
queue.remove();
}
Choose one answer. a. Remove the last element
b. Do nothing, remain the same queue
c. Reverse this queue
d. Clear this queue
Question 30
Marks: 1
Choose one answer. a. The program will fail to compile.
b. The program will compile without error and print 1 when run.
c. The program will compile without error and print 0 when run.
d. The program will compile without error and print 2 when running.
Question 31
Marks: 1 Given a weighted graph below and you are using the Dijkstra algorithm t
o find the shortest path from the vertex B to the vertex F. What are the correct
order of vertices selected into the set S until the vertex F is selected? (Each
step a vertex with minimal current distance is selected into S).
Choose one answer. a. B, C, D, F
b. B, C, E, F
c. B, C, F
d. B, C, D, E, F
Question 32
Marks: 1 Recursion is memory-intensive because:
Choose one answer. a. Many copies of the function code are created.
b. Recursive functions tend to declare many local variables.
c. Previous function calls are still open when the function calls itself and t
he activation records of these previous calls still occupy space on the call sta
ck.
d. It requires large data values.
Question 33
Marks: 1 Which of the following is NOT a valid order in which the vertices of th
e graph below can be marked as "visited" during a depth-first search?
Choose one answer. a. ABDFEC
b. ABEDFC
c. ADEFCB
d. ABCDEF
Question 34
Marks: 1 Which of the following statement about the Tree Traversal is false
Choose at least one answer. a. Tree traversal is the process of visiting each
node in the tree some times.
b. Postorder tree traversal can be only implemented in recursion.
c. Tree traversal process can not be implemented without using stack.
d. Tree traversal can be implemented in queue.
Question 35
Marks: 1 What is the worst-case time for heapsort to sort an array of n elements
?
Choose one answer. a. O`(n^2)`
b. O(lgn)
c. O(nlgn)
d. O( n )
Question 36
Marks: 1 Suppose we are considering a singly linked list which has at least 2 no
des. Select the most correct java code snippet that inserts new node with value
x before the last node.
Choose one answer. a.

b.

c.

d.

Question 37
Marks: 1 Suppose that obj is an Object variable and s is a String variable. Whic
h of the following statements is a correctly-compiling widening conversion? Don'
t worry about possible run-time exceptions
Choose one answer. a. s = (String) obj;
b. obj = s;
c. None of the others
d. All of the others
Question 38
Marks: 1 What is the value of the Boundary Folding Hash Function if K = 43-65-76
-7 and TSize = 100?
Choose one answer. a. 86
b. 82
c. 84
d. 85
Question 39
Marks: 1
Assume that sort is executed with array {10,5,3,6,9,11,4}. What is output after
iteration i=5 of the outer for loop completed
Choose one answer. a. {10,9,6,5,3,11,4}
b. {3,4, 5,6,9,10,11}
c. {3,5,6,10,9,11,4}
d. {3,5,6,9,10,11,4}
Question 40
Marks: 1 Suppose we are considering a binary search tree. Select the most correc
t java code snippet that search a node with value x.
Choose one answer. a.
Node search(int x)
{ Node p = root;
while(p.info != x && p!=null)
{ if(x<p.info) p = p.left;
else p=p.right;
}
return(p);
}
b.
Node search(int x)
{ Node p = root;
while(p.info != x)
{ if(x<p.info) p = p.left;
else p=p.right;
}
return(p);
}
c.
Node search(int x)
{ Node p = root;
while(p!=null && p.info != x)
{ if(x>p.info) p = p.left;
else p=p.right;
}
return(p);
}
d.
Node search(int x)
{ Node p = root;
while(p!=null && p.info != x)
{ if(x<p.info) p = p.left;
else p=p.right;
}
return(p);
}

Question 41
Marks: 1 When the compiler compiles your program, how is a recursive call treate
d differently than a non-recursive method call?
Choose one answer. a. None of the others
b. There is no duplication of local variables.
c. Primitive values are all treated as reference variables.
d. Reference variables are all treated as primitive values.
Question 42
Marks: 1 Select the one TRUE statement.
Choose one answer. a. Every balanced binary tree is also a perfect balanced bi
nary tree.
b. No binary tree is both balanced and perfect balanced.
c. Every binary tree is either balanced or perfect balanced.
d. Every perfect balanced binary tree is also a balanced binary tree.
Question 43
Marks: 1 If the values of A, B, C and D are 2, 3, 4 and 5, respectively. Using s
tack, manually calculate the value of the following postfix expressions: A B C +
* D -
Choose one answer. a. 6
b. 11
c. 9
d. 7
Question 44
Marks: 1 To implement an AVL tree, a concept balance factor is introduced (bal =
height(right)-height(left). Suppose an AVL tree is created by inserting to the
tree the following keys sequentially: 6, 4, 7, 3, 5, 2 What is the balance facto
r of the node 4? (please note that the tree is still AVL)
Choose one answer. a. 2
b. 0
c. -1
d. 1
Question 45
Marks: 1 Using the coalesced hashing to put the following values in a table with
10 elements:
A5, A2, A3, B5, A9, B2, B9, C2
Using the extraction method to extract the number as the key.
What is the chain to begin with A5?
Choose one answer. a. A5-A2-A3
b. A5-B2-C2
c. A5-B5-A9-B9
d. A5-B5
Question 46
Marks: 1 Suppose we have an array with m elements stored at data[0] through data
[m-1]. The capacity of the array is n (n > m). What is the complexity of inserti
ng a new element to end of the array?
Choose one answer. a. O( 1 )
b. O( n )
c. O( lgn )
d. O( m )
Question 47
Marks: 1 Select the most correct statement about the complexity of insertion sor
t .
Choose one answer. a. The best case is O( n ), and the worst case is O( nlogn
)
b. The best case is O( nlogn ), and the worst case is O( n2 )
c. Both best and worst cases are O( n2 )
d. The best case is O( n ), and the worst case is O( n2 )
Question 48
Marks: 1 Which of the following operation on singly linked list, with the comple
xity is O(1)?
Choose one answer. a. list traversal in reverse
b. insert the last node
c. removal the last node
d. find a node containing the requested object
Question 49
Marks: 1 Assume you have the following list:
head->100->200->300->NULL
What is result after the following code is executed on the list:
Choose one answer. a. head->100->300->200->NULL
b. head->200->100->300->NULL
c. head->300->200->100->NULL
d. head->200->300->100->NULL
Question 50
Marks: 1 An array contains the elements shown below. What would be the order of
the elements in the array after phase 1 of the heap sort algorithm?
3 9 7 2 11 16 4 13 12
Choose one answer. a. 16 13 7 12 11 3 4 2 9
b. 16 12 13 4 9 7 11 2 3
c. 16 13 12 11 9 7 4 3 2
d. 16 12 11 9 13 7 4 3 2
Link:
http://wps.prenhall.com/br_deitel_c_comoprogra_5/56/14470/3704495.cw/index.html
http://wps.prenhall.com/br_deitel_c_comoprogra_5/56/14472/3705018.cw/content/ind
ex.html
https://docs.google.com/viewer?a=v&q=cache:CIfHFSEBZYcJ:www.cs.iit.edu/~iraicu/t
eaching/EECS211/quiz4-sol.pdf+Always+have+the+same+shape+for+a+particular+set+of
+data&hl=vi&gl=vn&pid=bl&srcid=ADGEESgyYWgNTXKJLJUgYwNtItxOzKdK5bODJRpo7uxuRlMri
bzc2pb0ZaTLbfUElPRK2oP3-1jr5gKY7hrtWLXCEBG2rZtnYkz8EJJLzknmEURTrsl3DlH5kf6e_Eoa7
6TZLZdbLszI&sig=AHIEtbS3zZK3XkevdRcf7OsNX-5h3K1g8w

You might also like