You are on page 1of 100

Question 1

Incorrect
Mark 0.00 out of 1.00

Question text
Given the following code. What is output of running DuyetGraph program?

package fe.util;

import java.util.ArrayDeque;

public class DuyetGraph {

public static void main(String[] args) {


String nnames[]={"SG", "DN", "NTr", "DNg", "HP", "HN", "TrS", "HgS"};
int[][] conn =
{{0, 1, 1, 1, 0, 0, 0, 0},
{1, 0, 1, 1, 0, 0, 0, 0},
{1, 1, 0, 1, 0, 0, 0, 0},
{1, 0, 1, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 1, 1, 0, 1, 0},
{0, 0, 0, 0, 1, 1, 0, 1},
{0, 0, 0, 0, 1, 0, 1, 0} };

MyGraph G = new MyGraph(conn, nnames);

System.out.println("Graph traversal prints output: ");


G.traversal(3);
}

class MyGraph {

/* ------------------------------------------
Data structure used to represent a graph
------------------------------------------ */
int[][] adjMatrix;
int NNodes;
String nodeNames[];

boolean[] visited;
boolean[] enqueued;

/* ---------------------------------------------
Construct a graph with the adjacency matrix
--------------------------------------------- */
public MyGraph(int[][] mat, String nnames[]) {
int i, j;

NNodes = mat.length;
nodeNames = new String[NNodes];

adjMatrix = new int[NNodes][NNodes];


visited = new boolean[NNodes];
enqueued = new boolean[NNodes];

for (i = 0; i < NNodes; i++) {


nodeNames[i] = nnames[i];
for (j = 0; j < NNodes; j++) {
adjMatrix[i][j] = mat[i][j];
}
}
}

public void traversal(int k) {


// Visit nodes using a Stack to store "to visit" nodes
java.util.Stack<Integer> s = new java.util.Stack<Integer>();
clearVisited(); // Set all visited[i] = 0
s.push(k); // Start the "to visit" at node 0
/* ===========================================
Loop as long as there are "active" node
=========================================== */
while (!s.isEmpty()) {
int nextNode;
int i;
nextNode = s.pop();
if (!visited[nextNode]) {
visited[nextNode] = true;
System.out.println("Node visited: " + this.nodeNames[ nextNode ]);

for (i = NNodes - 1; i >= 0; i--) {


if (adjMatrix[nextNode][i] > 0 && !visited[i]) {
s.push(i);
}
}
}
}
}

void clearVisited() {
int i;

for (i = 0; i < visited.length; i++) {


visited[i] = false;
}
}

void printNode(int n) {
System.out.println(n);
}
}

Select one:
a.
Graph traversal prints output:
Node visited: DNg
Node visited: HN

Node visited: SG

Node visited: DN
Node visited: NTr
Node visited: HP
Node visited: TrS
Node visited: HgS

wrong

b. Graph traversal prints output:


Node visited: DNg
Node visited: SG
Node visited: DN
Node visited: NTr
Node visited: HN
Node visited: HP
Node visited: TrS
Node visited: HgS
c.

Graph traversal prints output:

Node visited: SG

Node visited: DN
Node visited: NTr
Node visited: DNg

Node visited: HP
Node visited: HN

Node visited: TrS


Node visited: HgS

d. Graph traversal prints output:


Node visited: DNg
Node visited: HN

Node visited: HP
Node visited: TrS
Node visited: HgS

Node visited: SG
Node visited: DN
Node visited: NTr

Feedback
Your answer is incorrect.
The correct answer is: Graph traversal prints output:
Node visited: DNg
Node visited: SG
Node visited: DN
Node visited: NTr
Node visited: HN
Node visited: HP
Node visited: TrS
Node visited: HgS

Question 2
Incorrect
Mark 0.00 out of 1.00

Question text
Choose the correct answer:
Select one:
a. Tree is a collection of objects that are inserted and removed according to the First-in, First-out
principle.

b. Tree is abstract data types that represents a linear sequence of elements.


c. Tree stores all elements hierarchically.

d. Tree is a collection of objects that are inserted and removed according to the Last-in, First-out
principle.

Feedback
Your answer is incorrect.
The correct answer is: Tree stores all elements hierarchically.

Question 3
Incorrect
Mark 0.00 out of 1.00

Question text
A chained hash table has an array size of 512. What is the maximum number of entries that can be
placed in the table?
Select one:
a. 1024

b. None of the others


c. 512
d. 256
e. 511

Feedback
The correct answer is: None of the others

Question 4
Incorrect
Mark 0.00 out of 1.00

Question text
Consider one AVL tree has a path of all zero balance factors. Assume that a new node has been
appended to the end of this path. Select correct/ incorrect statements:
a. All of them have to be updated.
b. No rotation is needed for any of the encountered nodes.
Select one:
a. a is correct and b is incorrect.
b. a is incorrect and b is correct.

c. a and b are correct.


d. a and b are incorrect.

Feedback
Your answer is incorrect.
The correct answer is: a and b are correct.

Question 5
Not answered
Marked out of 1.00

Question text
Give the following tree. We start from node A. The binary tree is traversed in-order, the output
will produce sorted key values in an ascending order. Choose the correct answer:
Select one:
a. D – B – E – A – F – C – G.
b. D – E – B – A – F – C – G.
c. A – B – C – D - E – F – G.
d. D – E – F – G – B – C – A.

Feedback
Your answer is incorrect.
The correct answer is: D – B – E – A – F – C – G.

Question 6
Not answered
Marked out of 1.00

Question text
Specify the correct implementation of dequeue() method of a queue. This queue uses
java.util.LinkedList, here is pool, for storing data and the head of the list is treated as the head of the
queue. (Choose the most suitable one)
Select one:
a. void dequeue(Object x)
{ if (isEmpty()) return(null);
pool.remove(pool.size()-1);
}
b. Object dequeue()
{ if (isEmpty()) return(null);
return(pool.removeLast());
}
c. Object dequeue()
{if (isEmpty()) return;
return(pool.remove(pool.size()-1));
}
d. Object dequeue()
{ if (isEmpty()) return(null);
return(pool.removeFirst();
}

Feedback
The correct answer is: Object dequeue()
{ if (isEmpty()) return(null);
return(pool.removeFirst();
}

Question 7
Not answered
Marked out of 1.00

Question text
In .................................. algorithm, each vertex v is visited and then each unvisited vertex adjacent
to v is visited. If a vertex v has no adjacent vertices or all of its adjacent vertices have been visited,
we backtrack to the predecessor of v. The traversal is finished if this visiting and backtracking
process leads to the first vertex where the traversal started. If there are still some unvisited vertices
in the graph, the traversal continues restarting for one of the unvisited vertices.
Select one:
a. None of the others
b. Breath First Search
c. Depth First Search

Feedback
Your answer is incorrect.
The correct answer is: Depth First Search

Question 8
Not answered
Marked out of 1.00

Question text
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 factor of the node 4? (please note that the tree is still AVL)
Select one:
a. 0
b. 1
c. 2
d. -1

Feedback
The correct answer is: 0

Question 9
Not answered
Marked out of 1.00

Question text
The execution of which sorting algorithm(s) can be visualized by means of a binary recursion tree.
Select all:

Select one or more:


A. Insertion sort
B. Quick-sort
C. Merge-sort
D. Bubble-sort

Feedback
Your answer is incorrect.
The correct answer is: Merge-sort, Quick-sort

Question 10
Not answered
Marked out of 1.00

Question text
Consider the following statements:
a. Every node of a Singly Linked List has two reference fields, one to the predecessor and one to the
successor.
b. Every node of a Doubly Linked List has two reference fields, one to the predecessor and one to
the first node of the list.
Select one:
a. a and b are true
b. a is true and b is false
c. a is false and b is true
d. a and b are false
Feedback
The correct answer is: a and b are false

Question 11
Not answered
Marked out of 1.00

Question text

Which of the following algorithms in graphs can be implemented by extending Depth


First Search algorithm?
Select one:
a. Finding the shortest path (Dijkstra algorithm)
b. All of the others.
c. The Chinese Postman Tour
d. Cycle detection.

Feedback
The correct answer is: Cycle detection.

Question 12
Not answered
Marked out of 1.00

Question text
Which of the following operation in the doubly linked circular list can be done in O(1) time?
Select one or more:
a. Insertion of the tail node
b. Deletion of the tail node
c. Deletion of any node
d. Insertion of a node to any position.

Feedback
The correct answer is: Insertion of the tail node, Deletion of the tail node

Question 13
Not answered
Marked out of 1.00

Question text
Select the best choice.
A stack can be implemented using .....
Select one:
a. A singly linked list
b. An array
c. All of the others.
d. A double linked list
e. A circular linked list

Feedback
The correct answer is: All of the others.

Question 14
Not answered
Marked out of 1.00

Question text
Which statement is incorrect?
Select one:
a. A spanning tree has all the graph’s vertices covered with minimum possible number of edges.
b. A spanning tree has at least one cycle.
c. A spanning tree does not have cycles.
d. Every connected and undirected Graph G has at least one spanning tree.

Feedback
Your answer is incorrect.
The correct answer is: A spanning tree has at least one cycle.

Question 15
Not answered
Marked out of 1.00

Question text
Select an incorrect statement.
Select one:
a. Recursion is always more efficient than loops.
b. Recursion, gone wrong, can lead to an overflow stack error.
c. Recursion can make the conceptual design of an algorithm's implementation easier.

Feedback
The correct answer is: Recursion is always more efficient than loops.

Question 16
Not answered
Marked out of 1.00

Question text
Given a sequence consists of n distinct elements and is already sorted. The height of the quick-sort
tree which associated with an execution of quick-sort is:

Select one:
A. n-1
B. n
C. log (n)
D. n.log(n)

Feedback
Your answer is incorrect.
The correct answer is: n-1

Question 17
Not answered
Marked out of 1.00

Question text
Priority queues can be implemented by using unordered linkedlist. Which of the following operations
is (are) used to dequeue?
Select one:
a. Searching and Deleting
b. Searching
c. Inserting and Searching
d. Deleting

Feedback
The correct answer is: Searching and Deleting

Question 18
Not answered
Marked out of 1.00

Question text
Apply Floyd algorithm to the following graph:
Which of the following statements is false?
Select one:
a. In initial weighted matrix, distances from e to others are infinity.
b. We can find shortest paths from any vertex to others in this graph.
c. The shortest path from vertex a to vertex e is zero.
d. abce is not shortest path from a to e.

Feedback
Your answer is incorrect.
The correct answer is: We can find shortest paths from any vertex to others in this graph.

Question 19
Not answered
Marked out of 1.00

Question text

How many activation records are allocated when calculating Fibonacci(5) by


calling recursion method?
Select one:
a. 9
b. 25
c. 15
d. 41

Feedback
The correct answer is: 15

Question 20
Not answered
Marked out of 1.00
Question text
The best technique when the amount of data is not well known is ……
Select one:
a. quadratic probing.
b. separate chaining.
c. double hashing.
d. linear probing.

Feedback
The correct answer is: separate chaining.

Question 21
Not answered
Marked out of 1.00

Question text
Suppose that you place 180 elements in a hash table with an array size of 200. What is the load
factor?
Select one:
a. 1.45
b. 0.5
c. 0.9
d. 0.75

Feedback
The correct answer is: 0.9

Question 22
Not answered
Marked out of 1.00

Question text
What is the best definition of a collision situation in a hash table?
Select one:
a. Two entries with different keys have the same exact hash value.
b. Two entries with different data have the exact same key.
c. Two entries with the exact same key have different hash values.
d. Two entries are identical except for their keys.

Feedback
The correct answer is: Two entries with different keys have the same exact hash value.

Question 23
Not answered
Marked out of 1.00

Question text
Which of the following statements about the shortest path finding algorithm of Dijkstra is true?
Select one:
a. All of the others.
b. It can be applied to graphs have negative weights.
c. It is label-setting algorithm.
d. It's complexity is O(|V|), where |V| is number of vertices of the graph.

Feedback
The correct answer is: It is label-setting algorithm.

Question 24
Not answered
Marked out of 1.00

Question text

Priority queues can be implemented by using unordered linked list. In this case, which
of the following operations of the linked list is (are) used to enqueue an element?
Select one:
a. Deleting
b. Inserting
c. Searching
d. All of the others

Feedback
The correct answer is: Inserting

Question 25
Not answered
Marked out of 1.00

Question text
Select the best choice about a linked structure.
Select one:
a. Inserting a new element to it is efficiently.
b. All of the others
c. It needs more memory spaces for linking elements.
d. Deleting an element from it is efficiently.

Feedback
The correct answer is: All of the others

Question 26
Not answered
Marked out of 1.00

Question text

Which of the following Sorting algorithms have complexity of O( n ) in best case ?


Select one:
a. Buble sort
b. Selection sort
c. Insertion sort
d. All of the others.

Feedback
The correct answer is: Insertion sort

Question 27
Not answered
Marked out of 1.00

Question text

Choose the correct answer about java.util package:


Select one:
A.
A. The capacity of an ArrayList instance can be increased or decreased on demand.

B.
A. Class ArrayList is synchronized.

C.
A. The ArrayList.add operation runs adding n elements requires O(1) time.

D.
A. The capacity of an ArrayList instance is fixed-size capacity after created.

Feedback
Your answer is incorrect.
The correct answer is:
A. The capacity of an ArrayList instance can be increased or decreased on demand.

Question 28
Not answered
Marked out of 1.00

Question text
The top-down method of J. Williams is used to organize the following array as a heap.
8 14 12 7 16 21 9 18 17
Show the contents of the array after we applied this algorithm.
Select one:
a. 21 18 12 17 16 8 9 7 14
b. 21 18 16 17 8 12 9 7 14
c. 21 12 16 9 8 16 17 14 7
d. 21 12 18 16 17 8 9 7 14

Feedback
The correct answer is: 21 18 16 17 8 12 9 7 14

Question 29
Not answered
Marked out of 1.00

Question text
We implement the stack as a singly linked list and use AddtoHead() method of the linked list to
implement push() method. A top pointer of the stack is …
Select one:
a. The tail reference of the singly linked list.
b. Nothing. We need a doubly linked list.
c. The head reference of the singly linked list.
d. Any one reference. Depending on the node that is accessed.

Feedback
The correct answer is: The head reference of the singly linked list.

Question 30
Not answered
Marked out of 1.00

Question text
Consider the following statements about recursion:
a) A recursive approach may be inefficient in many cases. If so, it can be replaced with a simple loop
or a stack-based approach.
b) Some value of its arguments causes a recursive method to return without calling itself. This is
called the ground case.
Select one:
a. a is true, b is false
b. a is false, b is true
c. a and b are false
d. a and b are true

Feedback
The correct answer is: a and b are true

Question 31
Not answered
Marked out of 1.00

Question text
Use Dijkstra’s algorithm to find shortest paths from vertex C to others in the following graph:

What is “current distance of A“ after executing of the algorithm end?


Select one:
a. inifinity
b. 40
c. 35
d. 0

Feedback
The correct answer is: inifinity

Question 32
Not answered
Marked out of 1.00

Question text
Select incorrect statement about restrictions need to be imposed on the prospective codes:
Select one:
a. Each codeword may be corresponds to one or many symbols.
b. Decoding should not require any look ahead.
c. There should not be any unused short codewords either as stand-alone encodings or as prefixes
for longer codewords.
d. The length of the codeword for a given symbol A should not exceed the length of the codeword of
a less probable symbol B.

Feedback
The correct answer is: Each codeword may be corresponds to one or many symbols.

Question 33
Not answered
Marked out of 1.00

Question text

Consider the following chain of method calls:


f() -> f1() -> f2() -> f3() -> f()
What is this kind of recursion?
Select one:
a. Tail recursion
b. Nontail recursion
c. None of the others
d. Indirect recursion

Feedback
The correct answer is: Indirect recursion

Question 34
Not answered
Marked out of 1.00

Question text
Which of the following statements is true?
Select one:
a. If the binary tree has n nodes and height h, then h <= lg ( n + 1 )
b. If every proper subtree of a binary tree is full, then the tree itself must also be full.
c. If all of its leaves are at the same level, then the binary tree is full.
d. A binary tree cannot have more than 2d nodes at level d.

Feedback
The correct answer is: A binary tree cannot have more than 2d nodes at level d.

Question 35
Not answered
Marked out of 1.00

Question text
Given the character frequencies
B : 32%
C : 28%
D : 16%
E : 6%
F : 18%
Using Huffman encoding, what is the code for character D? (Suppose that when constructing a sub
tree from 2 nodes we always place node with higher frequency on the left; and the left branch of a
node gets value 0, the right one gets value 1)
Select one:
a. 001
b. 100
c. 101
d. 01

Feedback
The correct answer is: 100

Question 36
Not answered
Marked out of 1.00

Question text
Which of the following data structures are the most suites for handling the minimum (maximum)
weighted distances?
Select one:
a. Linked list
b. Stack
c. Queue
d. Priority Queue

Feedback
The correct answer is: Priority Queue

Question 37
Not answered
Marked out of 1.00

Question text

Which of the following arrays is (are) heap?


Select one:
a. All of the others
b. 82 70 51 43 55 37 10 43 63 30 34
c. 82 70 51 63 55 37 10 43 27 30 34
d. 82 70 51 63 34 37 10 43 27 30 55

Feedback
The correct answer is: 82 70 51 63 55 37 10 43 27 30 34

Question 38
Not answered
Marked out of 1.00

Question text
Given the following code. What is output of the TestProg printed?
package fe.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class TestProg {

public static void main(String[] args) {


List list = new ArrayList();

list.add("String");
list.add("Other string");
list.add("Another string");
list.add("A String");

Collections.sort(list);
for (Object v : list) {
System.out.println(v.toString());
}
}
}

Select one:
A.
Another string

A String
String

Other string

B. Compiler error.
C. String

Other string

Another string

A String

D. A String
Another string
Other string
String

Feedback
Your answer is incorrect.
The correct answer is: A String
Another string
Other string
String

Question 39
Not answered
Marked out of 1.00

Question text
Which of the following is not correct about a recursive function?
Select one:
a. A recursive function is based on the recursion principle.
b. A recursive function may call itself directly.
c. A recursive function may call itself indirectly.
d. A recursive function is based on the diversion principle.

Feedback
The correct answer is: A recursive function is based on the diversion principle.

Question 40
Not answered
Marked out of 1.00

Question text
In run-length encoding algorithm, a run is defined as …
Select one:
a. a sequence of identical characters.
b. amount of time required to the compression algorithm.
c. size of the result of encoding input data.
d. number of different characters in the input.

Feedback
The correct answer is: a sequence of identical characters.

Question 41
Not answered
Marked out of 1.00

Question text
The height of the merge-sort tree is about:

Select one:
A. ln(n)
B. (n-1)
C. n2
D. log(n)

Feedback
Your answer is incorrect.
The correct answer is: log(n)

Question 42
Not answered
Marked out of 1.00

Question text
Select true / false statement in regarding to graph representation:
a. There are n possible adjacency matrices for the same graph.
b. Multigraphs can be represented in the following adjacency matrix:

aij = number of edges between vi and vj


Select one:
a. a and b are true
b. a is true and b is false
c. a and b are false
d. a is false and b is true

Feedback
Your answer is incorrect.
The correct answer is: a is false and b is true

Question 43
Not answered
Marked out of 1.00

Question text
Which of the following operations always take O( 1)time:
Select one or more:
a. Deleting one any node in a doubly linked list.
b. Inserting one node to the end of the singly linked list that has no tail.
c. Deleting one node from the begin of doubly linked list
d. Searching one node in singly linked list without tail in the best case.

Feedback

The correct answer is: Deleting one node from the begin of doubly linked list , Searching one
node in singly linked list without tail in the best case.
Question 44
Not answered
Marked out of 1.00

Question text
Select incorrect statements about the shortest path algorithm:
Select one:
a. Dijkstra’s algorithm is used to graphs which have positive weight.
b. Dijkstra’s algorithm is sort of label-setting.
c. Dijkstra’s algorithm finds the shortest path from one specified vertex to all other vertices.
d. Dijkstra’s algorithm cannot be applied to undirected weighted graphs.

Feedback
The correct answer is: Dijkstra’s algorithm cannot be applied to undirected weighted graphs.

Question 45
Not answered
Marked out of 1.00

Question text
Choose the correct answer:
Select one:
a. When a recursive call is made, the method clones itself, making only new copies of
the code (not included the local variables and the parameters).
b. When a recursive call is made, the method clones itself, making new copies of the code, the
local variables with their initial values, and the parameters.
c. Recursion usually make your code faster.
d. Recursion usually use less memory.

Feedback
Your answer is incorrect.
The correct answer is: When a recursive call is made, the method clones itself, making new
copies of the code, the local variables with their initial values, and the parameters.

Question 46
Not answered
Marked out of 1.00

Question text
When the bubble sort algorithm is used for sorting the dataset (23, 43, 56, 12, 87, 14, 87, 15, 90, 23,
10) in descending order, how many data exchanges occur during the first iteration of outer loop?
Select one:
a. 10
b. 9
c. 8
d. 7

Feedback
The correct answer is: 8

Question 47
Not answered
Marked out of 1.00

Question text
Give the following code.

public class StackQ001 {

int MAXSIZE = 8;
int stack[];
int top = -1;

public StackQ001() { super(); stack = new int[MAXSIZE]; }


public StackQ001(int maxSize) {
MAXSIZE = maxSize; stack = new int[MAXSIZE];
}
boolean isEmpty() { return (top == -1); }

boolean isFull() { return (top == MAXSIZE); }

int peek() { return stack[top]; }

int pop() {
int data;
if (!isEmpty()) {
data = stack[top];
top = top - 1;
return data;
} else {
System.out.println("Could not retrieve data, Stack is empty.");
}
return -1;
}

int push(int data) {


if (!isFull()) {
top = top + 1;
stack[top] = data;
} else {
System.out.println("Could not insert data, Stack is full.");
}
return -1;
}

public static void main(String args[]) {


// push items on to the stack
int data;
StackQ001 s = new StackQ001();
s.push(11);
s.push(33);
data = s.pop(); System.out.println( data );
s.push(66);
s.push(99);
data = s.pop(); System.out.println( data );
s.push(44);
s.push(55);
data = s.pop(); System.out.println( data );
s.push(0);
data = s.pop(); System.out.println( data );
s.push(10);
data = s.pop(); System.out.println( data );

System.out.println("Element at top of the stack: " + s.peek());


System.out.println("Elements: ");
System.out.println("Stack full: " + s.isFull());
System.out.println("Stack empty: " + s.isEmpty());
}

Choose the correct answer:


Select one:
a. The program prints out “Element at top of the stack: 0”, “Stack full: true”.
b.
A. The program prints out “Element at top of the stack: 11”, “Stack full: false”.

c.
A. The program prints out “Element at top of the stack: 44”, “Stack full: false”.

d.
A. The program prints out “Element at top of the stack: 10”, “Stack full: true”.

Feedback
Your answer is incorrect.
The correct answer is:
A. The program prints out “Element at top of the stack: 44”, “Stack full: false”.

Question 48
Not answered
Marked out of 1.00

Question text
Select true / false statement:
a. The height of a Binary Search tree can be extended after deleting by merging.
b. The height of a Binary Search tree can be reduced after deleting by merging.
Select one:
a. a is true and b is false
b. a is false and b is true
c. a and b are false
d. a and b are true

Feedback
Your answer is incorrect.
The correct answer is: a and b are true

Question 49
Not answered
Marked out of 1.00

Question text
Consider the below AVL tree. Values in nodes are balance factors. h is height of sub trees of P and
Q.

Assume that a node is removed from the left subtree of P and height of this subtree decreases 1.
Select true / false statement:
Select one:
a. The balance is restored by one right rotation and one left rotation.
b. The balance is restored by one right rotation.
c. The balance is restored by one left rotation.

Feedback
Your answer is incorrect.
The correct answer is: The balance is restored by one left rotation.

Question 50
Not answered
Marked out of 1.00

Question text
Choose the correct answer:
Select one:
a. Each node in a binary tree has a maximum of one child.
b. Each node in a binary tree can have a maximum of two children nodes.
c. Each node in a binary tree has at least two children nodes.
d. Each node in a binary tree can have zero or one child node.
Feedback
Your answer is incorrect.
The correct answer is: Each node in a binary tree can have a maximum of two children nodes.

Question 51
Not answered
Marked out of 1.00

Question text

Assume that in an array list implementation of a stack, pushing an element onto a full
stack requires allocating more memory. What is the complexity of pushing operation in
this case?
Select one:
a. O ( lgn )
b. O ( n )
c. O ( 1 )
d. None of the others
e. O ( n2 )

Feedback
The correct answer is: O ( n )

Question 52
Not answered
Marked out of 1.00

Question text
Given the following code. What is output of running this program?

package fe.util;

import java.util.ArrayDeque;

public class DuyetGraph {

public static void main(String[] args) {


String nnames[]={"SG", "DN", "NTr", "DNg", "HP", "HN", "TrS", "HgS"};
int[][] conn =
{{0, 1, 1, 1, 0, 0, 0, 0},
{1, 0, 1, 1, 0, 0, 0, 0},
{1, 1, 0, 1, 0, 0, 0, 0},
{1, 0, 1, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 1, 1, 1},
{0, 0, 0, 1, 1, 0, 1, 0},
{0, 0, 0, 0, 1, 1, 0, 1},
{0, 0, 0, 0, 1, 0, 1, 0} };

MyGraph G = new MyGraph(conn, nnames);

System.out.println("Graph traversal prints output: ");


G.traversal(3);
}

class MyGraph {

/* ------------------------------------------
Data structure used to represent a graph
------------------------------------------ */
int[][] adjMatrix;
int NNodes;
String nodeNames[];

boolean[] visited;
boolean[] enqueued;

/* ---------------------------------------------
Construct a graph with the adjacency matrix
--------------------------------------------- */
public MyGraph(int[][] mat, String nnames[]) {
int i, j;

NNodes = mat.length;
nodeNames = new String[NNodes];
adjMatrix = new int[NNodes][NNodes];
visited = new boolean[NNodes];
enqueued = new boolean[NNodes];

for (i = 0; i < NNodes; i++) {


nodeNames[i] = nnames[i];
for (j = 0; j < NNodes; j++) {
adjMatrix[i][j] = mat[i][j];
}
}
}

public void traversal(int k) {


ArrayDeque queue = new ArrayDeque();

for (int i = 0; i < NNodes; i++) {


enqueued[i] = false;
}
queue.add(k);
enqueued[k] = true;
while (!queue.isEmpty()) {
int u = (int) queue.removeFirst(); //Dequeue

for (int j = 0; j < NNodes; j++) {


if (!visited[j] && !enqueued[j]
&& adjMatrix[u][j] > 0) {
queue.addLast(j);
enqueued[j] = true;
}
}
visited[u] = true;
printNode(u);
}

}
void clearVisited() {
int i;
for (i = 0; i < visited.length; i++) {
visited[i] = false;
}
}

void printNode(int n) {
System.out.println("Node visited: " + this.nodeNames[ n ]);
}
}

Select one:
A. Graph traversal prints output:
Node visited: DNg
Node visited: SG
Node visited: DN

Node visited: NTr

Node visited: HN

Node visited: HP
Node visited: TrS
Node visited: HgS

B. Graph traversal prints output:


Node visited: DNg
Node visited: SG
Node visited: DN

Node visited: NTr

Node visited: HP
Node visited: HN

Node visited: TrS


Node visited: HgS

C. Graph traversal prints output:


Node visited: DNg
Node visited: HN
Node visited: HP
Node visited: TrS
Node visited: HgS

Node visited: SG
Node visited: NTr
Node visited: DN

D. Graph traversal prints output:


Node visited: DNg
Node visited: SG
Node visited: NTr
Node visited: HN
Node visited: DN
Node visited: HP
Node visited: TrS
Node visited: HgS

Feedback
Your answer is incorrect.
The correct answer is: Graph traversal prints output:
Node visited: DNg
Node visited: SG
Node visited: NTr
Node visited: HN
Node visited: DN
Node visited: HP
Node visited: TrS
Node visited: HgS

Question 53
Not answered
Marked out of 1.00

Question text
Which of the following statements is (are) not disadvantage of AVL tree?
a. All data must be put in an array before the tree can be created.
b. Tree rebalancing can be performed locally if only a portion of the tree is affected when changes
are required after an element is inserted into or deleted from the tree
Select one:
a. Neither a nor b
b. b
c. a
d. a and b

Feedback
Your answer is incorrect.
The correct answer is: a
Question 54
Not answered
Marked out of 1.00

Question text
Select incorrect statement about Adaptive Huffman Coding:
Select one:
a. If the sibling property is violated, Huffman tree has to be restructured to restore this property.
b. Adaptive Huffman coding can be applied to any kind of file.
c. The sibling property is described as each node has a sibling (except for the root) and the breadth-
first right-to-left tree traversal generates a list of nodes with nonincreasing frequency counters.
d. If Adaptive Huffman coding is used to compress execute file, output file is much smaller than the
original.

Feedback
The correct answer is: If Adaptive Huffman coding is used to compress execute file, output file is
much smaller than the original.

Question 55
Not answered
Marked out of 1.00

Question text
Consider the following statements:
a. In the circular list, deletion of the tail node takes O ( n ) time.
b. The first node of the circular list has next field reference to the last node.
Select one:
a. a and b are true
b. a is true and b is false.
c. a and b are false
d. a is fale and b is true

Feedback
The correct answer is: a is true and b is false.

Question 56
Not answered
Marked out of 1.00

Question text
We can visualize an execution of the merge-sort algorithm by means of:
Select one:
A.
a binary tree T, called the merge-sort tree.
B.
a 1-ary tree T, called the merge-sort tree.
C.
a directed graph G, called the merge-sort graph.
D.
a list T, called the merge-sort list.

Feedback
Your answer is incorrect.
The correct answer is:
a binary tree T, called the merge-sort tree.

Question 57
Not answered
Marked out of 1.00

Question text
Using the depth-first search traversal on the forllowing graph, we start at vertex A. What is
correct order printed out?

Select one:
A.
A – B – C – D – G – J – I – E – F – M – N – K – O – L – P – H.
B. None of others is correct.
C.
A – B – C – D – E – F – G – H – I – J – K – L – M – N – O – P.
D.
A – E – F – B – C – I – J – G – D – M – N – K – L – O – P – H.

Feedback
Your answer is incorrect.
The correct answer is:
A – B – C – D – G – J – I – E – F – M – N – K – O – L – P – H.

Question 58
Not answered
Marked out of 1.00

Question text
Select correct statement(s) about Doubly Linked List:
Select one or more:
a. Methods for processing doubly linked list are simpler than those of singly linked list.
b. Inserting a new node at the end of the list requires O ( n ) steps.
c. The node which is deleted from the list will be claimed by the garbage collector.
d. Deleting a node at the end of the list takes constant time O ( 1 ).

Feedback

The correct answer is: Deleting a node at the end of the list takes constant time O ( 1 )., The node
which is deleted from the list will be claimed by the garbage collector.
Question 59
Not answered
Marked out of 1.00

Question text

Choose the correct answer:


Select one:
A.
A. All of the java.util.LinkedList’s operations perform as a circularly-linked list.

B. If the list of java.util.LinkedList is remove or add elements at any time after its iterator is
created, the iterator will throw a ConcurrentModificationException.
C.
A. Can not traverse elements in the java.util.LinkedList by index.

D.
A. Class java.util.LinkedList is not synchronized.
Feedback
Your answer is incorrect.
The correct answer is:
A. Class java.util.LinkedList is not synchronized.

Question 60
Not answered
Marked out of 1.00

Question text
Consider the list of eight integers below: 6, 4, 9, 10, 8, 3, 7, 5
What is the list after it has just been partitioned by the first step of quicksort and a pivot value is
chosen as the first element of the list? (sorting from smallest to largest). Assume that selecting
largest element of the array is ignored.
Select one:
a. 3, 4, 5, 6, 8, 7, 9, 10
b. 3, 4, 6, 5, 8, 10, 7, 9
c. 3, 4, 5, 6, 8, 10, 7, 9
d. 3, 4, 5, 6, 7, 8, 10, 9

Feedback
The correct answer is: 3, 4, 5, 6, 8, 10, 7, 9

Question 61
Not answered
Marked out of 1.00

Question text

What is the complexity of inserting a node in a perfectly balanced tree for worst case?
Select one:
a. None of the others.
b. O(lgn)
c. O( n )
d. O(nlgn)

Feedback
The correct answer is: O(lgn)

Question 62
Not answered
Marked out of 1.00
Question text

Choose the correct answer about java.util package:


Select one:
A.
A. The ArrayList.add operation runs adding n elements requires O(1) time.

B.
A. The capacity of an ArrayList instance can be increased or decreased on demand.

C.
A. Class ArrayList is synchronized.

D.
A. The capacity of an ArrayList instance is fixed-size capacity after created.

Feedback
Your answer is incorrect.
The correct answer is:
A. The capacity of an ArrayList instance can be increased or decreased on demand.

Question 63
Not answered
Marked out of 1.00

Question text
A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear
probing. After inserting 6 values into an empty hash table, the table is
as shown below.

Which one of the following choices gives a possible order in which the key values could have been
inserted in the table? (Assume that Linear probing was used to resolved collision)
Select one:
a.
46, 42, 34, 52, 23, 33
b.

34, 42, 23, 52, 33, 46


c.

46, 34, 42, 23, 52, 33


d.

42, 46, 33, 23, 34, 52


Feedback
The correct answer is:

46, 34, 42, 23, 52, 33


Question 64
Not answered
Marked out of 1.00

Question text
Given the following pseudocode. Choose the correct name for the algorithm X:

Algorithm: X(p)
perform the “visit” action for position p { this happens before any recursion }
for each child c in children(p) do
X(c) { recursively traverse the subtree rooted at c }

Select one:
a. postorder
b. inorder
c. preorder
d. breadth-first-traversal

Feedback
Your answer is incorrect.
The correct answer is: preorder

Question 65
Not answered
Marked out of 1.00
Question text
Given the following pseudocode. Choose the correct name for the algorithm X:
Algorithm: X(p)
for each child c in children(p) do
X(c) { recursively traverse the subtree rooted at c }
perform the “visit” action for position p { this happens after any recursion }

Select one:
a. inorder
b. postorder
c. outorder

d. preorder

Feedback
Your answer is incorrect.
The correct answer is: postorder

Question 66
Not answered
Marked out of 1.00

Question text
What is output if using LZW algorithm with the table initialized with the letters a, b, c encode the
string “ababcaab”?
Select one:
a. 1 2 4 3 5 2
b. 4 4 3 1 1 2
c. 1 2 4 3 1 4
d. 1 2 1 2 3 1 1 2

Feedback
The correct answer is: 1 2 4 3 1 4

Question 67
Not answered
Marked out of 1.00

Question text
Which does the sorting algorithm use recursion in an algorithmic design pattern called divide-and-
conquer? Select all:

Select one or more:


A.
insertion-sort.
B.
merge-sort.
C.
selection-sort.
D.
quick-sort.

Feedback
Your answer is incorrect.
The correct answer is:
merge-sort.,
quick-sort.

Question 68
Not answered
Marked out of 1.00

Question text
Linked lists allow easy insertion and deletion of information because such operations have a local
impact on the list.
Select one:
a. True
b. False

Feedback

The correct answer is: True

Question 69
Not answered
Marked out of 1.00

Question text
Consider the heap:
100 90 80 30 60 50 70 20 10
What is position of the elements when dequeuing an element?
Select one:
a. 90 10 80 30 60 50 70 20
b. 90 60 80 30 10 50 70 20
c. 90 60 80 30 20 50 70 10

Feedback
The correct answer is: 90 60 80 30 10 50 70 20

Question 70
Not answered
Marked out of 1.00

Question text
Given the following pseudocode. Choose the correct name for the algorithm X:
Algorithm: X(p)
if p has a left child lc then
X(lc) { recursively traverse the left subtree of p }
perform the “visit” action for position p
if p has a right child rc then
X(rc) { recursively traverse the right subtree of p }

Select one:
a. breadth-first-traversal
b. inorder
c. postorder
d. preorder

Feedback
Your answer is incorrect.
The correct answer is: inorder

Question 71
Not answered
Marked out of 1.00

Question text
Suppose temp refers to a node in a linked list (using the SLLNode class with instance variables
called info and next). What boolean expression will be true when temp refers to the tail node of the
list?
Select one:
a. (temp == null)
b. (temp.info == null)
c. (temp.next != null)
d. (temp.next == null)

Feedback
The correct answer is: (temp.next == null)

Question 72
Not answered
Marked out of 1.00

Question text
Consider the statements related to deleteFromTail operation in the Singly Linked List:
a. There is only one special cases to consider: the list is empty.
b. Most time-consuming part of the operation is finding the next to last node.
Select one:
a. a and b are true.
b. a is false and b is true.
c. a is true and b is false.
d. a and b are false

Feedback
The correct answer is: a is false and b is true.

Question 73
Not answered
Marked out of 1.00

Question text
Give the following tree. We start from A. The binary tree is traversed pre-order, the output will
produce sorted key values in an ascending order. Choose the correct answer:
Select one:
a. D – B – E – A – F – C – G.
b. A – B – D – E – C – F – G.
c. A – B – C – D - E – F – G.
d. D – E – B – A – F – C – G.

Feedback
Your answer is incorrect.
The correct answer is: A – B – D – E – C – F – G.

Question 74
Not answered
Marked out of 1.00

Question text
The recursion statement indicates ...
Select one:
a. the beginning of the recursion statement.
b. the rule of the recursion.
c. the ending of the recursion statement.
d. the starting value.

Feedback
The correct answer is: the rule of the recursion.

Question 75
Not answered
Marked out of 1.00

Question text
Recursion requires much memory because:
Select one:
a. Previous function calls are still open when the function calls itself and the activation records of
these previous calls still occupy space on the call stack.
b. Recursive functions tend to declare many local variables.
c. Many copies of the function code are created.
d. It requires large data values.

Feedback
The correct answer is: Previous function calls are still open when the function calls itself and the
activation records of these previous calls still occupy space on the call stack.

Question 76
Not answered
Marked out of 1.00

Question text
Find the average length LHuf for the letters X, Y, and Z and their probabilities .05, .05 and .9
respectively.
Select one:
a. None of the others.
b. 1.75
c. 0.8
d. 2.3
e. 1.1

Feedback
The correct answer is: 1.1

Question 77
Not answered
Marked out of 1.00

Question text
After two passes of a sort algorithm, the following array:
47 3 21 32 56 92
has been rearranged as shown below:
3 21 47 32 56 92
Which sorting algorithm is being used?
Select one:
a. selection sort.
b. bubble sort.
c. all of them.
d. insertion sort.

Feedback
The correct answer is: all of them.

Question 78
Not answered
Marked out of 1.00

Question text
Which of the following data structures does not suitable for implementing Huffman algorithm?
Select one:
a. Doubly linked list.
b. Queue.
c. Singly linked list.
d. Heap.

Feedback
The correct answer is: Queue.

Question 79
Not answered
Marked out of 1.00

Question text
Consider a hash table of size seven, with starting index zero, and a hash function h(x)= (3x + 4) mod
7. Assuming the hash table is initially empty, which of the following is the contents of the table when
the sequence 1, 3, 8, 10 is inserted into the table using linear probing? Note that ‘_’ denotes an
empty location in the table.
Select one:
a. 8, _, _, _, _, _, 10
b. 1, 8, 10, _, _, _, 3
c. 1, 10, 8, _, _, _, 3
d. 1, _, _, _, _, _,3

Feedback
The correct answer is: 1, 8, 10, _, _, _, 3

Question 80
Not answered
Marked out of 1.00

Question text
Given the following code. What is output of running this program?
package fe.util;
import java.util.ArrayDeque;
public class DuyetGraph {
public static void main(String[] args) {
int[][] conn =
{{0, 1, 0, 1, 0, 0},
{1, 0, 1, 0, 0, 1},
{0, 1, 1, 1, 1, 1},
{1, 0, 1, 0, 1, 0},
{0, 0, 1, 1, 0, 1},
{0, 1, 1, 0, 1, 0}};

MyGraph G = new MyGraph(conn);


System.out.println("Graph traversal prints output: ");
G.traversal(2);
}

class MyGraph {
/* ------------------------------------------
Data structure used to represent a graph
------------------------------------------ */
int[][] adjMatrix;
int NNodes;

boolean[] visited;
boolean[] enqueued;
/* ---------------------------------------------
Construct a graph with the adjacency matrix
--------------------------------------------- */
public MyGraph(int[][] mat) {
int i, j;

NNodes = mat.length;

adjMatrix = new int[NNodes][NNodes];


visited = new boolean[NNodes];
enqueued = new boolean[NNodes];

for (i = 0; i < NNodes; i++) {


for (j = 0; j < NNodes; j++) {
adjMatrix[i][j] = mat[i][j];
}
}
}

public void traversal(int k) {


// Visit nodes using a Stack to store "to visit" nodes
java.util.Stack<Integer> s = new java.util.Stack<Integer>();
clearVisited(); // Set all visited[i] = 0
s.push(k); // Start the "to visit" at node 0
/* ===========================================
Loop as long as there are "active" node
=========================================== */
while (!s.isEmpty()) {
int nextNode;
int i;
nextNode = s.pop();
if (!visited[nextNode]) {
visited[nextNode] = true;
System.out.println("Node visited: " + nextNode);
for (i = 0; i < NNodes; i++) {
if (adjMatrix[nextNode][i] > 0 && !visited[i]) {
s.push(i);
}
}
}
}
}

void clearVisited() {
int i;

for (i = 0; i < visited.length; i++) {


visited[i] = false;
}
}

void printNode(int n) {
System.out.println(n);
}
}

Select one:
A. Graph traversal prints output:
Node visited: 2
Node visited: 5
Node visited: 4
Node visited: 3
Node visited: 0
Node visited: 1
B. Graph traversal prints output:
Node visited: 0
Node visited: 1
Node visited: 2
Node visited: 3
Node visited: 4
Node visited: 5
C.
Graph traversal prints output:
Node visited: 5
Node visited: 4
Node visited: 3
Node visited: 2
Node visited: 1
Node visited: 0

D.
Graph traversal prints output:
Node visited: 2
Node visited: 1
Node visited: 0
Node visited: 3
Node visited: 4
Node visited: 5

Feedback
Your answer is incorrect.
The correct answer is: Graph traversal prints output:
Node visited: 2
Node visited: 5
Node visited: 4
Node visited: 3
Node visited: 0
Node visited: 1

Question 81
Not answered
Marked out of 1.00

Question text
Which of the following is an appropriate description concerning a binary search tree whose node
values are 17, 6, 19, 3, 22, and 32?
Select one:
a. Any binary tree containing these values has a maximum depth of three (3).
b. The root node value cannot be “32”.
c. No matter which value is placed at the root node, “3” is always at the deepest level.
d. No matter which value is placed at the root node, “3” cannot have a left child.

Feedback
The correct answer is: No matter which value is placed at the root node, “3” cannot have a left child.
Question 82
Not answered
Marked out of 1.00

Question text
Given a nonempty tree T. Which statement is wrong?
Select one:
a. Every node in T has zero or more children nodes.
b. The node root of T has no parent node.
c. Each node in T has at least two parent nodes.
d. Each node of T, which differents from the root, has a unique parent node.

Feedback
Your answer is incorrect.
The correct answer is: Each node in T has at least two parent nodes.

Question 83
Not answered
Marked out of 1.00

Question text

Which statement is correct?


Select one:
A. A stack is a collection of objects that are inserted and removed according to the first-in, last-
out (FILO) principle.
B.
A. A linked list is a collection of objects that are inserted and removed according to the last-in, first-out (LIFO)
principle.

C.
A. A stack is a collection of objects that are inserted and removed according to the first-in, first-out (FIFO)
principle.

D.
A. A queue is a collection of objects that are inserted and removed according to the last-in, first-out (LIFO)
principle.

Feedback
Your answer is incorrect.
The correct answer is: A stack is a collection of objects that are inserted and removed according
to the first-in, last-out (FILO) principle.
Question 84
Not answered
Marked out of 1.00

Question text
Using the breadth-first search traversal on the forllowing graph, we start at vertex A. What is correct
order printed out?

Select one:
a.
A – B – C – D – E – F – G – H – I – J – K – L – M – N – O – P.
b.
A – E – F – B – C – I – J – G – D – M – N – K – L – O – P – H.
c.
A – B – C – D – G – J – I – E – F – M – N – K – O – L – P – H.
d. A – B – E – F – C – I – D – G – J – M – N – H – K – L – O – P.
e.

Feedback
Your answer is incorrect.
The correct answer is: A – B – E – F – C – I – D – G – J – M – N – H – K – L – O – P.

Question 85
Not answered
Marked out of 1.00

Question text
If the values of A, B, C and D are 2, 3, 4 and 5, respectively. Using stack, manually calculate the
value of the following postfix expressions: A B C + * D -
Select one:
a. 11
b. 9
c. 7
d. 6

Feedback
The correct answer is: 9

Question 86
Not answered
Marked out of 1.00

Question text
Give the following code. Fill in the (1) and (2) with the correct code:
public static int factorial(int n) throws IllegalArgumentException {
if (n < 0) {
throw new IllegalArgumentException();
} else if (n == 0) {
.….(1)….
} else {
.….(2).…
}
}

Select one:
A. return 1; and return (n - 1) * factorial(n);
B. return n * (n-1); and return 1;
C. return 1; and return n * factorial(n-1);
D. return n* factorial(n-1); and return 1;

Feedback
Your answer is incorrect.
The correct answer is: return 1; and return n * factorial(n-1);

Question 87
Not answered
Marked out of 1.00

Question text
Suppose you are doing a breadth-first search of a graph with n vertices, using a queue implemented
with a static array. What is the minimum number of elements of this array?
Select one:
a. n - 1
b. n + 1
c. 2n
d. n

Feedback
The correct answer is: n - 1

Question 88
Not answered
Marked out of 1.00

Question text
Suppose we are implementing a stack using a singly linked list where the head of the list is treated
as the top of the stack.
Specify the correct implementation of push() method of the stack. (Choose the most suitable one)
Select one:
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 = head;
head=p.next;
}
c. void push(Object x)
{ Node p = new Node(x);
p.next = null;
head=p;
}
d. void push(Object x)
{ Node p = new Node(x);
p.next = head;
head=p;
}

Feedback
The correct answer is: void push(Object x)
{ Node p = new Node(x);
p.next = head;
head=p;
}

Question 89
Not answered
Marked out of 1.00

Question text
Give the following tree. We start from A. The binary tree is traversed post-order, the output will
produce sorted key values in an ascending order. Choose the correct answer:

Select one:
a. A – B – C – D - E – F – G.
b. D – E – B – F – G – C – A.
c. A – B – D – E – C – F – G.
d. D – B – E – A – F – C – G.

Feedback
Your answer is incorrect.
The correct answer is: D – E – B – F – G – C – A.

Question 90
Not answered
Marked out of 1.00

Question text
Select true / false statement in regarding to graph representation:
a. If our task is to process vertices adjacent to a vertex v, then the adjacency list requires only deg(v)
steps, whereas the adjacency matrix requires |V| steps.
b. Inserting or deleting a edge requires linked list maintenance for an adjacency list (if such an
implementation is used); for a matrix, it requires only changing 0 to 1 for insertion, or 1 to 0 for
deletion, in one cell of the matrix.
Select one:
a. a is false and b is true
b. a and b are true
c. a and b are false
d. a is true and b is false

Feedback
Your answer is incorrect.
The correct answer is: a and b are false

Question 91
Not answered
Marked out of 1.00

Question text

Given the following code of N-Queens program. Fill in the correct code in body of the
PutQueen() function.
package fe.util;
import java.io.*;
public class NQueens {

private final boolean available = true;


private final int squares = 4, norm = squares - 1;
private int[] positionInRow = new int[squares];
private boolean[] column = new boolean[squares];
private boolean[] leftDiagonal = new boolean[squares*2 - 1];
private boolean[] rightDiagonal = new boolean[squares*2 - 1];
private int howMany = 0;
private int[] nqueens = new int[squares];
public NQueens() {
for (int i = 0; i < squares; i++) {
positionInRow[i] = -1;
column[i] = available;
}
for (int i = 0; i < squares*2 - 1; i++)
leftDiagonal[i] = rightDiagonal[i] = available;
}
public void PrintBoard(PrintStream out) {
howMany++;
out.println("Solution N-Queens: ");
for (int i=0; i < squares; i++) {
for (int j=0; j < squares; j++) {
if (positionInRow[ i ] == j)
out.print("H ");
else out.print("- ");
}
out.println();
}
}
public void PutQueen(int row) {
// TODO
}
public static void main(String args[]) {
NQueens queens = new NQueens();
queens.PutQueen(0);
System.out.println(queens.howMany + " solutions found.");
}

Select one:
A. for (int col = 0; col < squares; col++)
if (column[col] == available &&
leftDiagonal [row+col] == available &&
rightDiagonal[row-col+norm] == available) {
positionInRow[row] = col;
column[col] = !available;
leftDiagonal[row+col] = !available;
rightDiagonal[row-col+norm] = !available;
if (row < squares-1) {
PutQueen(row+1);
}
else {
PrintBoard(System.out); // SUCCESS
}
column[col] = available;
leftDiagonal[row+col] = available;
rightDiagonal[row-col+norm] = available;
}
B. for (int col = 0; col < squares; col++) {
if (column[col] == available &&
leftDiagonal [row+col] == available &&
rightDiagonal[row-col+norm] == available) {
positionInRow[row] = col;
column[col] = !available;
leftDiagonal[row+col] = !available;
rightDiagonal[row-col+norm] = !available;
if (row < squares-1) {
PrintBoard(System.out); // SUCCESS
}
column[col] = available;
leftDiagonal[row+col] = available;
rightDiagonal[row-col+norm] = available;
}
}
C. for (int col = 0; col < squares; col++) {
if (column[col] == available &&
leftDiagonal [row+col] == available &&
rightDiagonal[row-col+norm] == available) {
positionInRow[row] = col;
column[col] = !available;
leftDiagonal[row+col] = !available;
rightDiagonal[row-col+norm] = !available;
if (row < squares-1) {
PutQueen(row);

}
else {
PrintBoard(System.out); // SUCCESS
}
column[col] = available;
leftDiagonal[row+col] = available;
rightDiagonal[row-col+norm] = available;
}
}
D. for (int col = 0; col < squares; col++)
if (column[col] == available &&
leftDiagonal [row+col] == available &&
rightDiagonal[row-col+norm] == available) {
positionInRow[row] = col;
column[col] = !available;
leftDiagonal[row+col] = !available;
rightDiagonal[row-col+norm] = !available;
if (row < squares-1) {
PutQueen(row - 1);

}
else {
PrintBoard(System.out); // SUCCESS
}
column[col] = available;
leftDiagonal[row+col] = available;
rightDiagonal[row-col+norm] = available;
}

Feedback
Your answer is incorrect.
The correct answer is: for (int col = 0; col < squares; col++)
if (column[col] == available &&
leftDiagonal [row+col] == available &&
rightDiagonal[row-col+norm] == available) {
positionInRow[row] = col;
column[col] = !available;
leftDiagonal[row+col] = !available;
rightDiagonal[row-col+norm] = !available;
if (row < squares-1) {
PutQueen(row+1);

}
else {
PrintBoard(System.out); // SUCCESS
}
column[col] = available;
leftDiagonal[row+col] = available;
rightDiagonal[row-col+norm] = available;
}

Question 92
Not answered
Marked out of 1.00

Question text
Choose the correct pseudo-code to the Algorithms: addFirst and addLast.
Select one:
A.
Algorithm addFirst(e):
newest = Node(e)
head = newest
newest.next = head
size = size+1
Algorithm addLast(e):
newest = Node(e)
tail.next = newest
newest.next = null
tail = newest
size = size+1

B.
Algorithm addFirst(e):
newest = Node(e)
newest.next = head
head = newest
size = size+1
Algorithm addLast(e):
newest = Node(e)
newest.next = null
tail.next = newest
tail = newest
size = size+1

C.
Algorithm addLast(e):
newest = Node(e)
newest.next = head
head = newest
size = size+1
Algorithm addFirst(e):
newest = Node(e)
newest.next = null
tail.next = newest
tail = newest
size = size+1

D.
Algorithm addFirst(e):
newest.next = head
head = newest
newest = Node(e)
size = size+1
Algorithm addLast(e):
tail.next = newest
tail = newest
newest = Node(e)
newest.next = null
size = size+1

Feedback
Your answer is incorrect.
The correct answer is:
Algorithm addFirst(e):
newest = Node(e)
newest.next = head
head = newest
size = size+1
Algorithm addLast(e):
newest = Node(e)
newest.next = null
tail.next = newest
tail = newest
size = size+1

Question 93
Not answered
Marked out of 1.00

Question text
Select true / false statement in regarding to Deleting by copying:
a. This algorithm always increase the height of the tree.
b. If this algorithm always replacing the key being deleted with its immediate predecessor, possibly
reducing the height of the left subtree and leaving the right subtree unaffected.
Select one:
a. a is false and b is true
b. a is true and b is false
c. a and b are false
d. a and b are true

Feedback
Your answer is incorrect.
The correct answer is: a is false and b is true

Question 94
Not answered
Marked out of 1.00

Question text
Consider the below AVL tree. Values in nodes are balance factors.

Assume that one new node is inserted into right sub tree of node Q. Select true / false statements:
a. This insertion results in an unbalanced tree.
b. The balance is restored by one left rotation.
c. The balance is restored by one right rotation.
d. The balance is restored by one left rotation and one right rotation.
Select one:
a. a and d are true
b. a and c are true
c. a and b are true

Feedback
Your answer is incorrect.
The correct answer is: a and b are true

Question 95
Not answered
Marked out of 1.00

Question text
Which statement is correct about java.util package?
Select one:
A.
A. The class java.util.PriorityQueue<E> implements directly the java.util.Queue<E>.

B.
A. The java.util.Queue<E> is an abstract class.

C.
A. Insert, remove operations in the java.util.Queue<E> always throws an exception if the operations fails.

D.
A. The java.util.AbstractQueue<E> implements the java.util.Queue<E>.

Feedback
Your answer is incorrect.
The correct answer is:
A. The java.util.AbstractQueue<E> implements the java.util.Queue<E>.

Question 96
Not answered
Marked out of 1.00

Question text
Consider the heap:
120 110 100 50 80 70 90 40 30
What is position of the elements when dequeuing an element?
Select one:
a. 110 80 100 50 40 70 90 30
b. 110 80 100 50 30 70 90 40
c. 110 30 100 50 80 70 90 40

Feedback
Your answer is incorrect.
The correct answer is: 110 80 100 50 30 70 90 40

Question 97
Not answered
Marked out of 1.00

Question text
Using the Breath-First Search (BFS) traversal on the following graph, we start at vertex 0.
What is correct order of vertexes in the traversal?
Select one:
A. 0 – 2 – 1 – 5 – 6 – 3 – 4 – 7
B. 0 – 2 – 1 – 3 – 7 – 6 – 4 – 5
C. 0 – 2 – 6 – 7 – 3 – 1 – 4 – 5
D. 0 – 2 – 5 – 6 – 4 – 7 – 3 – 1

Feedback
Your answer is incorrect.
The correct answer is: 0 – 2 – 1 – 5 – 6 – 3 – 4 – 7

Question 98
Not answered
Marked out of 1.00

Question text
In a weighted graph, the minimum spanning tree tries to minimize ………..
Select one:
a. the total weight of the edges from the starting vertex to a specified vertex.
b. the total weight of edges connecting all the vertices.
c. the number of edges from the starting vertex to a specified vertex.
d. the number of edges connecting all the vertices.

Feedback
The correct answer is: the total weight of edges connecting all the vertices.

Question 99
Not answered
Marked out of 1.00

Question text
Which the sorting technique always makes recursive calls to sort pieces that are about half the size
of the original array?
Select one:
a. Radix sort.
b. Merge sort.
c. Heap sort.
d. Quick sort.

Feedback
The correct answer is: Merge sort.

Question 100
Not answered
Marked out of 1.00

Question text
Which statement is correct?
Select one:
A.
In the array-based implementation, each method (i.e., top, pop, push, etc.) runs in O(n) time.

B. Advantage of array-based stack implementation relies on a fixed-capacity array


C.
The Stack can be implemented using a singly linked list for storage.

D.
Advantage of array-based stack implementation is without an arbitrary capacity limit.

Feedback
Your answer is incorrect.
The correct answer is:
The Stack can be implemented using a singly linked list for storage.

Question 101
Not answered
Marked out of 1.00

Question text
In order to sort the sequence “98, 12, 4, 56, 34, 23” in ascending order by Bubble Sort algorithm,
how many exchange operations are required?
Select one:
a. 7
b. 5
c. 9
d. 11

Feedback
The correct answer is: 9

Question 102
Not answered
Marked out of 1.00

Question text
In a binary search tree, certain null entries are replaced by special pointers which point to nodes
higher in the tree for traversal. These special pointers are called ……
Select one:
a. Leaf
b. Arc
c. Root
d. Thread
e. Non-terminal

Feedback
The correct answer is: Thread

Question 103
Not answered
Marked out of 1.00

Question text
The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10
using open addressing with hash function h(k) = k mod 10 and linear probing. What is the resultant
hash table?
Select one:
a. C
b. B
c. D
d. A

Feedback
The correct answer is: C

Question 104
Not answered
Marked out of 1.00

Question text
You want to place 1000 elements in a hash table using linear probing, and you would like an average
numbers of trials for successful search two elements. How big does the array of hash table need to
be?
Select one:
a. 500
b. 1000
c. 1250
d. 1500

Feedback
The correct answer is: 1500

Question 105
Not answered
Marked out of 1.00
Question text
Give the following code. What is the correct output?

package fe.util;

import java.util.*;
public class TestList {
public static void main(String[] args) {
List list = new ArrayList();
list.add(1.5);
list.add("string");
list.add("another string");
list.add(new Integer(2));
list.add(new Emp("e001", "Nguyen Van An", 100));
for (Object v:list) {
System.out.println(v.toString());
}
}
}

class Emp {
String code, name; double salary;
public Emp(String id, String name, double sal) {
this.code = id; this.name = name; this.salary = sal;
}
public String toString() {
String s = code + " , " + name + " , " + salary;
return s;
}
}

Select one:
A. 1.5
string
another string
2
e001 , Nguyen Van An , 100.0
B. Runtime error. Cause of let an ArrayList object to the List is wrong.
C. Compiler error at line code 24.
D. Compiler error at line code 11.

Feedback
Your answer is incorrect.
The correct answer is: 1.5
string
another string
2
e001 , Nguyen Van An , 100.0

Question 106
Not answered
Marked out of 1.00

Question text

Which of the following Sorting algorithms use Divide and Conquer strategy?
Select one:
a. Heap sort
b. Radix sort
c. Bubble sort
d. Quick sort

Feedback
The correct answer is: Quick sort

Question 107
Not answered
Marked out of 1.00

Question text

What is the complexity of reversing the order of the elements on a stack using two
additional stacks?
Select one:
a. O ( lgn )
b. O ( n )
c. O ( n2 )
d. O ( 1 )

Feedback
The correct answer is: O ( n )

Question 108
Not answered
Marked out of 1.00

Question text

Which statement is correct?


Select one:
A.
A. Singly linked list is in which data can be viewed as having a cyclic order.

B.
A. Doubly linked list is define a linked list in which each node keeps an explicit reference to the node before it and
a reference to the node after it.

C.
A. Doubly linked list is in which data can be viewed as having a cyclic order.

D.
A. Circularly linked list is define a linked list in which each node keeps an explicit reference to the node before it
and a reference to the node after it.

Feedback
Your answer is incorrect.
The correct answer is:
A. Doubly linked list is define a linked list in which each node keeps an explicit reference to the node before it and
a reference to the node after it.

Question 109
Not answered
Marked out of 1.00

Question text
Which of the following is the appropriate description of the “selection sort” algorithm?
Select one:
a. Each set of the elements extracted at regularintervals is sorted, and then the interval is further
decreased. The operation is repeatedly performed until the interval becomes 1.
b. An intermediate reference value is determined, and then the elements are divided into two groups
of “larger” values and “smaller”values. This operation is recursively repeated.
c. Two adjacent elements are repeatedly compared and swapped if the first element is larger than
the second. This operation is repeated until all elements are arranged in an orderly fashion.
d. The element with the smallest value is determined and swapped for the first element, and then the
smallest value of the unsorted elements is determined and swapped for the second-to-the-first
element. This operation is repeated in the same way.
Feedback
The correct answer is: The element with the smallest value is determined and swapped for the first
element, and then the smallest value of the unsorted elements is determined and swapped for the
second-to-the-first element. This operation is repeated in the same way.

Question 110
Not answered
Marked out of 1.00

Question text
Which of the following algorithms can be used to detect cycle of a graph?
Select one or more:
a. Graph coloring
b. Union-Find
c. Minimum Spanning Tree
d. Depth First Traversal

Feedback
The correct answer is: Union-Find, Depth First Traversal

Question 111
Not answered
Marked out of 1.00

Question text
What is the result of the breadth first traverse of the binary search tree T, after inserting the following
keys into the tree sequentially (suppose T is empty before insertion): 6, 7, 3, 1, 2, 5, 8
Select one:
a. 6, 3, 7, 1, 5, 8, 2
b. 6, 3, 7, 1, 2, 5, 8
c. 6, 3, 7, 1, 5, 2, 8
d. 6, 3, 1, 2, 5, 7, 8

Feedback
The correct answer is: 6, 3, 7, 1, 5, 8, 2

Question 112
Not answered
Marked out of 1.00

Question text
Which of the following statements is false?
Select one:
a. The top-down level order traversals always visit the root first.
b. The postorder traversal always visits the root last.
c. The preorder traversals always visit the root first.
d. The postorder traversal always visits the right-most node first.

Feedback
The correct answer is: The postorder traversal always visits the right-most node first.

Question 113
Not answered
Marked out of 1.00

Question text
Consider the below tree. Values in nodes are balance factors. h is height of sub trees of P and Q.

Assume that a new node is inserted into in the left subtree of Q and height of this subtree increases
1. Select true / false statement:
a. This insertion results in an unbalanced tree.
b. The balance is restored by one left rotation.
c. The balance is restored by one right rotation.
d. The balance is restored by one right rotation and one left rotation.
Select one:
a. a and d are true
b. a and c are true
c. a and b are true

Feedback
Your answer is incorrect.
The correct answer is: a and d are true

Question 114
Not answered
Marked out of 1.00

Question text
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?
Select one:
a. A5-B5-A9-B9
b. A5-B2-C2
c. A5-A2-A3
d. A5-B5

Feedback
The correct answer is: A5-B5-A9-B9

Question 115
Not answered
Marked out of 1.00

Question text
Consider the following pseudocode:
declare a stack of characters
while(there are more characters in the word to read)
{read a character
if a character is '*' then
pop and write the popped character to the screen
else
push the character into the stack
}
What is written to the screen for the input " Go**odMorn**in***g" ?

Select one:
a. oGnrniM
b. oGnrndo
c. oGnrnio
d. oGnrnid

Feedback
The correct answer is: oGnrnio

Question 116
Not answered
Marked out of 1.00

Question text
Give the following code. Choose the correct answer?
public static double func(double x, int n) {
if (n == 0) return 1;
return x * func(x, n-1);
}

Select one:
a. The func runs in O(xn) time.
b. The func runs in O(1) time.
c. The func runs in O(n) time.
d. The func runs in O(n2) time.

Feedback
Your answer is incorrect.
The correct answer is: The func runs in O(n) time.

Question 117
Not answered
Marked out of 1.00

Question text
Given the following code. What is output of running this program?

package fe.util;
public class TestStack {
int MAXSIZE = 8;

int stack[];
int top = -1;

public TestStack() { super(); stack = new int[MAXSIZE]; }

public TestStack(int maxSize) {


MAXSIZE = maxSize; stack = new int[MAXSIZE];
}

boolean isEmpty() { return (top == -1); }


boolean isFull() { return (top == MAXSIZE); }
int peek() { return stack[top]; }

int pop() {
int data;
if (!isEmpty()) {
data = stack[top];
top = top - 1;
return data;
} else {
System.out.println("Could not retrieve data, Stack is empty.");
}
return -1;
}

int push(int data) {


if (!isFull()) {
top = top + 1;
stack[top] = data;
} else {
System.out.println("Could not insert data, Stack is full.");

}
return -1;
}

public static void main(String args[]) {


int data;

TestStack stack = new TestStack();


stack.push(11);
stack.push(33);
stack.pop();
stack.push(66);
stack.push(99);
stack.pop();
stack.push(44);
stack.push(55);
stack.pop();
stack.push(10);

System.out.println("Element at top of the stack: " + stack.peek());


System.out.println("Stack full: " + stack.isFull());
}
}

Select one:
A.
Element at top of the stack: 11
Stack full: true

B.
Element at top of the stack: 11
Stack full: false

C.
Element at top of the stack: 10
Stack full: false

D.
Element at top of the stack: 10
Stack full: true
Feedback
Your answer is incorrect.
The correct answer is:
Element at top of the stack: 10
Stack full: false
Question 118
Not answered
Marked out of 1.00

Question text
Encoding the string "aaabbccddddddeee" with Huffman. Please indicate the size of the output
string?
Select one:
a. 24 bits
b. 16 bits
c. 128 bits
d. 36 bits

Feedback
The correct answer is: 36 bits

Question 119
Not answered
Marked out of 1.00

Question text
Given the following code. Implementing the Breadth-first search (BFS) algorithm for
method public void BFS(int k) in Java.
/* File: GraphTraversal.java */
package fe.util;
public class GraphTraversal {
public static void main(String[] args) {
int[][] conn =
{{0, 1, 0, 1, 0, 0},
{1, 0, 1, 0, 0, 1},
{0, 1, 1, 1, 1, 1},
{1, 0, 1, 0, 1, 0},
{0, 0, 1, 1, 0, 1},
{0, 1, 1, 0, 1, 0}};
Graph G = new Graph(conn);
System.out.println("BFS prints output: ");
G.BFS(0);
}
}
/* File: Graph.java */
package fe.util;
import java.util.*;
public class Graph {
/* ------------------------------------------
Data structure used to represent a graph
------------------------------------------ */
int[][] adjMatrix;
int rootNode = 0;
int NNodes;

boolean[] visited;
boolean[] enqueued;

/* ---------------------------------------------
Construct a graph with the adjacency matrix
--------------------------------------------- */
public Graph(int[][] mat) {
int i, j;

NNodes = mat.length;

adjMatrix = new int[NNodes][NNodes];


visited = new boolean[NNodes];
enqueued = new boolean[NNodes];

for (i = 0; i < NNodes; i++) {


for (j = 0; j < NNodes; j++) {
adjMatrix[i][j] = mat[i][j];
}
}
}

// TODO: public void BFS(int k)


void clearVisited() {
int i;
for (i = 0; i < visited.length; i++) {
visited[i] = false;
}
}

void printNode(int n) {
System.out.println(n);
}
}

Select one:
A.
public void BFS(int k) {
java.util.Stack<Integer> s = new java.util.Stack<Integer>(); // Create a stack
clearVisited(); // Set all visited[i] = 0

while (!s.isEmpty()) {
int nextNode;
int i;
if (!visited[nextNode]) {
visited[nextNode] = true;
System.out.println("nextNode = " + nextNode);
for (i = NNodes - 1; i >= 0; i--) {
if (adjMatrix[nextNode][i] > 0 && !visited[i]) {
s.push(i);
}
}
}
}
}
B. public void BFS(int k) {
ArrayDeque queue = new ArrayDeque();
for (int i = 0; i < NNodes; i++) {
enqueued[i] = true;
}
queue.add(k);
enqueued[k] = false;
while (!queue.isEmpty()) {
int u = (int) queue.getFirst(); //Dequeue
for (int j = 0; j < NNodes; j++) {
if (!visited[j] && !enqueued[j]
&& adjMatrix[u][j] > 0) {
queue.addLast(j);
enqueued[j] = true;
}
}
visited[u] = true;
printNode(u);
}
}
C. public void BFS(int k) {
java.util.Stack<Integer> s = new java.util.Stack<Integer>(); // Create a stack
clearVisited(); // Set all visited[i] = 0
s.push(k);

while (!s.isEmpty()) {
int nextNode;
int i;
nextNode = s.pop();
if (!visited[nextNode]) {
visited[nextNode] = true;
System.out.println("nextNode = " + nextNode);
for (i = NNodes - 1; i >= 0; i--) {
if (adjMatrix[nextNode][i] > 0 && !visited[i]) {
s.push(i);
}
}
}
}
}
D. public void BFS(int k) {
ArrayDeque queue = new ArrayDeque();
for (int i = 0; i < NNodes; i++) {
enqueued[i] = false;
}
queue.add(k);
enqueued[k] = true;
while (!queue.isEmpty()) {
int u = (int) queue.removeFirst(); //Dequeue
for (int j = 0; j < NNodes; j++) {
if (!visited[j] && !enqueued[j]
&& adjMatrix[u][j] > 0) {
queue.addLast(j);
enqueued[j] = true;
}
}
visited[u] = true;
printNode(u);
}
}

Feedback
Your answer is incorrect.
The correct answer is: public void BFS(int k) {
ArrayDeque queue = new ArrayDeque();
for (int i = 0; i < NNodes; i++) {
enqueued[i] = false;
}
queue.add(k);
enqueued[k] = true;
while (!queue.isEmpty()) {
int u = (int) queue.removeFirst(); //Dequeue
for (int j = 0; j < NNodes; j++) {
if (!visited[j] && !enqueued[j]
&& adjMatrix[u][j] > 0) {
queue.addLast(j);
enqueued[j] = true;
}
}
visited[u] = true;
printNode(u);
}
}

Question 120
Not answered
Marked out of 1.00

Question text
Apply Kruskal's Minimum Spanning Tree (MST) to the following graph:

Select false statement:


Select one:
a. cf is the latest edge added to MST.
b. bc is not added to MST because it forms a cycle with ac and ac.
c. The algorithm have consideration to edges be, de and cd but does not add them to MST.

Feedback
Your answer is incorrect.
The correct answer is: The algorithm have consideration to edges be, de and cd but does not add
them to MST.

Question 121
Not answered
Marked out of 1.00

Question text
Choose the correct answer about AVL tree:
Select one:
a. Every binary tree is an AVL tree.
b. For every internal position p of an AVL tree T, the heights of the children of p are same.
c. For every internal position p of an AVL tree T, the heights of the children of p differ by at most 1.
d. For every internal position p of an AVL tree T, the heights of the children of p differ by at most 2.

Feedback
Your answer is incorrect.
The correct answer is: For every internal position p of an AVL tree T, the heights of the children
of p differ by at most 1.

Question 122
Not answered
Marked out of 1.00

Question text
The “prime number division remainder” method is a well-known hashing algorithm. In this method,
a key value is divided by a number N, and the remainder which is also called a hash value is used
directly as an index into the hash table. N is the largest prime number less than or equal to the size
of the table. When the table size is 20, which of the following is the correct hash value calculated
from the key value 136? Here, a prime number is one that cannot be divided evenly by any other
number except one (1). 2, 3, 5, 7, 11, and 13 are the first few prime numbers.
Select one:
a. None of the others.
b. 1
c. 16
d. 3
e. 0

Feedback
The correct answer is: 3

Question 123
Not answered
Marked out of 1.00

Question text
Given a raw message 'BBBUUUUBBBUUBBBBBUU' (without single quote). Run the run-length
encoding algorithm for that message, what is the output?
Select one:
a. 3B4U3B2U5B2UU
b. 3B4U4B3U2B5UU2
c. 3B4U3B2U5B2U
d. 3B4U3B2U5B

Feedback
The correct answer is: 3B4U3B2U5B2U

Question 124
Not answered
Marked out of 1.00

Question text
package csd201exam;

public class U01_Q002 {

public static void main(String[] args) {


int LA[] = {1, 3, 5, 7, 8};
int k = 4, n = 5;
int i, j;

j = k;

while (j < n) {
LA[j - 1] = LA[j];
j = j + 1;
}

n = n - 1;

System.out.println("Output: The elements of array LA is:");

for (i = 0; i < n; i++) {


System.out.println("LA[" + i+ "] = " + LA[i]);
}
}
}
Choose the correct answer:

Select one:
A. The elements of array LA are printed {1, 3, 5, 7, 4, 8}.
B. The elements of array LA are printed {3, 5, 7, 8}.
C. The elements of array LA are printed {1, 3, 5, 8}.
D. The elements of array LA are printed {1, 3, 5, 7}.

Feedback
Your answer is incorrect.
The correct answer is: The elements of array LA are printed {1, 3, 5, 8}.

Question 125
Not answered
Marked out of 1.00

Question text
Give the following code. What is values printed?
package csd201exam;
public class U3_Q003 {

public static int func(int n1, int n2)


{
if (n2 != 0)
return func(n2, n1 % n2);
else
return n1;
}
public static void main(String[] args) {
System.out.println( func(16, 36) );
System.out.println( func(15, 225) );
}

Select one:
a. Compile error.
b. 16, 15
c. 2, 5
d. 4, 15

Feedback
Your answer is incorrect.
The correct answer is: 4, 15

Question 126
Not answered
Marked out of 1.00

Question text
Given the following code. Implementing the SortedEmp class to print out sorted list of
employees that are sorted by non-decreasing salary.

package fe.util;
import java.util.*;
public class TestSort {
public static void main(String[] args) {
TestSort test = new TestSort();
Vector list = new Vector();
for (int i = 1; i <= 10; i++) {
double sal = Math.random() * 1000;
list.add(new SortedEmp("ID" + i, "Name " + i, sal));
}

Collections.sort(list);
for (Object v : list) {
System.out.println(v.toString());
}
}
}
// TODO: class SortedEmp

Select one:
A. class SortedEmp implements Comparable {

String code, name;


double salary;

public String getName() { return name; }

public double getSalary() { return salary; }

public String getCode() { return code; }

public SortedEmp(String id, String name, double sal) {


this.code = id;
this.name = name;
this.salary = sal;
}

public String toString() {


return code + " , " + name + " , " + salary;

@Override
public int compareTo(Object o) {

return (this.salary < ((SortedEmp) o).getSalary())?1:


(this.salary == ((SortedEmp) o).getSalary())?0:-1;

}
}

B. class SortedEmp extends Comparator {

String code, name;


double salary;

public String getName() { return name; }

public double getSalary() { return salary; }

public String getCode() { return code; }

public SortedEmp(String id, String name, double sal) {


this.code = id;
this.name = name;
this.salary = sal;
}

public String toString() {


return code + " , " + name + " , " + salary;

@Override
public int compareTo(Object o) {
return (this.salary <= ((SortedEmp)o).getSalary())? 1 : -1;
}

}
C. class SortedEmp implements Comparable {

String code, name;


double salary;

public String getName() { return name; }

public double getSalary() { return salary; }


public String getCode() { return code; }

public SortedEmp(String id, String name, double sal) {


this.code = id;
this.name = name;
this.salary = sal;
}

public String toString() {


return code + " , " + name + " , " + salary;

@Override
public int compareTo(Object o) {
return (this.salary < ((SortedEmp) o).getSalary())?-1:
(this.salary == ((SortedEmp) o).getSalary())?0:1;
}

}
D. class SortedEmp implements Comparable {

String code, name;


double salary;

public String getName() { return name; }

public double getSalary() { return salary; }

public String getCode() { return code; }

public SortedEmp(String id, String name, double sal) {


this.code = id;
this.name = name;
this.salary = sal;
}

public String toString() {


return code + " , " + name + " , " + salary;

}
}
Feedback
Your answer is incorrect.
The correct answer is: class SortedEmp implements Comparable {

String code, name;


double salary;

public String getName() { return name; }

public double getSalary() { return salary; }

public String getCode() { return code; }

public SortedEmp(String id, String name, double sal) {


this.code = id;
this.name = name;
this.salary = sal;
}

public String toString() {


return code + " , " + name + " , " + salary;

@Override
public int compareTo(Object o) {
return (this.salary < ((SortedEmp) o).getSalary())?-1:
(this.salary == ((SortedEmp) o).getSalary())?0:1;
}

Question 127
Not answered
Marked out of 1.00

Question text
Select correct statement:
Select one:
a. If there are N items, the bubble sort makes exactly N*N comparisons.
b. The bubble sort always ends up comparing every item with every other item.
c. A copy is three times as fast as a swap.
d. In a particular sorting situation, if swaps take much longer than comparisons, the selection sort is
about twice as fast as the bubble sort.

Feedback
The correct answer is: A copy is three times as fast as a swap.

Question 128
Not answered
Marked out of 1.00

Question text

Which of the following problems may use the recursion technique?


Select one:
a. The eight queens problem.
b. Perform symbolic differentiation.
c. The Maze problem.
d. All of the others.

Feedback
The correct answer is: All of the others.

Question 129
Not answered
Marked out of 1.00

Question text

Using the Depth-First Search (DFS) traversal on the following graph, we start at vertex 0.
What is correct order DFS traversal?
Select one:
A. DFS(0) – DFS(2) – DFS(1) – DFS(3) – DFS(7) – DFS(4) – DFS(6) – DFS(5)
B. DFS(0) – DFS(3) – DFS(7) – DFS(4) – DFS(2) – DFS(1) – DFS(6) – DFS(5)
C. DFS(0) – DFS(3) – DFS(1) – DFS(2) – DFS(4) – DFS(6) – DFS(7) – DFS(5)
D. DFS(0) – DFS(2) – DFS(4) – DFS(7) – DFS(3) – DFS(1) – DFS(5) – DFS(6)

Feedback
Your answer is incorrect.
The correct answer is: DFS(0) – DFS(2) – DFS(1) – DFS(3) – DFS(7) – DFS(4) – DFS(6) – DFS(5)

Question 130
Not answered
Marked out of 1.00

Question text
We let n denote the number of vertices, m the number of edges, and dv the degree of vertex
v. Choose the correct answer about the data structures for a Graph ADT:

Select one:
a. Using adjacency list data structure for representing a graph, the method insertVertex(x) is O(1).
b. Using adjacency matrix data structure for representing a graph, the method insertVertex(x) is
O(n).
c. Using adjacency list data structure for representing a graph, the method insertVertex(x) is O(n).
d. Using adjacency matrix data structure for representing a graph, the method insertVertex(x) is
O(1).

Feedback
Your answer is incorrect.
The correct answer is: Using adjacency list data structure for representing a graph, the method
insertVertex(x) is O(1).

Question 131
Not answered
Marked out of 1.00

Question text

When the compiler compiles your program, how is a recursive call treated differently
than a non-recursive method call?
Select one:
a. There is no duplication of local variables.
b. Reference variables are all treated as primitive values.
c. None of the others
d. Primitive values are all treated as reference variables.

Feedback
The correct answer is: None of the others

Question 132
Not answered
Marked out of 1.00

Question text
Using the Breath-First Search (BFS) traversal on the following graph, we start at vertex 0.
What is correct order of vertexes in the traversal?
Select one:
A. 0 – 2 – 3 – 1 – 4 – 5 – 6 – 7.
B. 0 – 3 – 1 – 5 – 2 – 4 – 7 – 6.
C. 0 – 2 – 1 – 5 – 3 – 4 – 6 – 7.
D. 0 – 2 – 4 – 6 – 7 – 1 – 5 – 3.

Feedback
Your answer is incorrect.
The correct answer is: 0 – 2 – 3 – 1 – 4 – 5 – 6 – 7.

Question 133
Not answered
Marked out of 1.00

Question text
Use Dijkstra’s algorithm to find shortest paths from vertex A to others in the following graph:
Which vertex is chosen in iteration 4 of the algorithm?
Select one:
a. C
b. D
c. F
d. E

Feedback
The correct answer is: E

Question 134
Not answered
Marked out of 1.00

Question text
What is output if using LZW algorithm with the table initialized with the letters x, y, z encode the
string “xyxyzxxy”?
Select one:
a. 1 2 1 2 3 1 1 2
b. 4 4 3 1 1 2
c. 1 2 4 3 1 4
d. 1 2 4 3 5 2

Feedback
The correct answer is: 1 2 4 3 1 4

Question 135
Not answered
Marked out of 1.00

Question text
Precondition for both methods: n >= 0
public boolean even(int n) {
if (n==0) return true;
return odd(n-1);
}

public boolean odd(int n) {


if (n==0) return false;
return even(n-1);
}
Which assertions are correct?
Select one:
a. both odd and even may loop indefinitely
b. even always stops, but odd may loop indefinitely
c. both odd and even always stops
d. odd always stops, but even may loop indefinitely

Feedback
The correct answer is: both odd and even always stops

Question 136
Not answered
Marked out of 1.00

Question text
Choose the correct answer:
Select one:
A.
A. The enqueue(e) method in the the queue ADT is the add(e) and offer(e) methods of the interface
java.util.Queue.

B.
A. The enqueue(e) method in the the queue ADT is the add(e) and poll(e) methods of the interface java.util.Queue.

C.
A. The dequeue() method in the the queue ADT is the remove() and offer() method of the interface
java.util.Queue.

D.
A. The first() method in the the queue ADT is the element() and head() methods of the interface java.util.Queue.

Feedback
Your answer is incorrect.
The correct answer is:
A. The enqueue(e) method in the the queue ADT is the add(e) and offer(e) methods of the interface
java.util.Queue.

Question 137
Not answered
Marked out of 1.00

Question text
package csd201exam;
public class CSD201Exam {
public static void main(String[] args) {
int LA[] = {1, 3, 5, 7, 8, 0};
int item = 10, k = 3, n = 5;
int i = 0, j = n-1;
while (j >= k) {
LA[j + 1] = LA[j];
j = j - 1;
}
LA[k] = item;
System.out.println("Output: The elements of array LA[] are :");
for (i = 0; i < n+1; i++) {
System.out.println("LA[" + i + "] = " + LA[i]);
}
}
}

Choose the correct answer:


Select one:
A. The elements of array LA are printed out {1, 3, 5, 10, 7, 8}
B. Runtime error
C. The elements of array LA are printed out {10, 1, 3, 5, 7, 8}
D. The elements of array LA are printed out {1, 3, 5, 7, 8, 10}

Feedback
Your answer is incorrect.
The correct answer is: The elements of array LA are printed out {1, 3, 5, 10, 7, 8}
Question 138
Not answered
Marked out of 1.00

Question text
An array contains the elements shown below:
7 8 26 44 13 23 98 57
What would be the value of the elements in the array after two pass of the heap sort algorithm.
Select one:
a. 7 8 13 23 26 44 57 98
b. 44 26 23 7 13 8 57 98
c. 26 13 23 7 8 44 57 98
d. 57 26 44 7 13 8 23 98

Feedback
The correct answer is: 44 26 23 7 13 8 57 98

Question 139
Not answered
Marked out of 1.00

Question text
In AVL tree, after a node has been deleted from the tree, case in which balance factors are updated
from the parent of the deleted node up to the root:
a. deleted node is leaf.
b. deleted node has only a child.
c. deleted node has two children and deleteByCopying method is applied to delete this node.
d. deleted node has two children and deleteByMerging method is applied to delete this node.

Select one:
a. a and b
b. c and d
c. a, b and d
d. a, b and c

Feedback
Your answer is incorrect.
The correct answer is: a, b and c

Question 140
Not answered
Marked out of 1.00

Question text
Which of sentences about singly linked list are true:
Select one or more:
a. There is no immediate access to the predecessor of any node in list.
b. On the average, delete operation executes O ( n ) steps.
c. Deleting a node at the beginning of the list takes constant time O ( 1 ).
d. Search operation takes O ( n ) time in the best case.
e. Deleting last node of the list always takes O ( lgn ) time.

Feedback
The correct answer is: Deleting a node at the beginning of the list takes constant time O ( 1 )., On
the average, delete operation executes O ( n ) steps., There is no immediate access to the
predecessor of any node in list.

Question 141
Not answered
Marked out of 1.00

Question text
Given a tree T of n nodes. What is the worst-case running time of the Algorithm X to traversal the
tree T?
Algorithm X:
Initialize queue Q to contain root( )
while Q not empty do
p = Q.dequeue( ) { p is the oldest entry in the queue }
perform the “visit” action for position p
for each child c in children(p) do
Q.enqueue(c) { add p’s children to the end of the queue for later visits }

Select one:
a. O(1)
b. O(n)
c. O(n2)
d. O(nlog(n))

Feedback
Your answer is incorrect.
The correct answer is: O(n)

Question 142
Not answered
Marked out of 1.00

Question text
Use Dijkstra’s algorithm to find shortest paths from vertex A to others in the following graph:

What is “current distance of F“ after iteration 3 of the algorithm?


Select one:
a. 95
b. 70
c. 20
d. infinity

Feedback
The correct answer is: infinity

You might also like