0% found this document useful (0 votes)
324 views139 pages

Object-Oriented Programming Concepts

The document contains multiple choice questions about object-oriented programming concepts, data structures, algorithms, and Java programming. It tests knowledge on topics like OOP principles, access modifiers, inheritance, serialization, data types, operators, linked lists, stacks, queues, trees, graphs, recursion, and more. The questions have single or multiple correct answers regarding statements, time complexities, implementations, and definitions related to these topics.

Uploaded by

hashir mahboob
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
324 views139 pages

Object-Oriented Programming Concepts

The document contains multiple choice questions about object-oriented programming concepts, data structures, algorithms, and Java programming. It tests knowledge on topics like OOP principles, access modifiers, inheritance, serialization, data types, operators, linked lists, stacks, queues, trees, graphs, recursion, and more. The questions have single or multiple correct answers regarding statements, time complexities, implementations, and definitions related to these topics.

Uploaded by

hashir mahboob
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Select incorrect statements about Object – Oriented Programming:

Answer: tatic methods and variables are associated with the class itself and are
called instance methods and instance variables//The combination of data and related
operations is called information hiding principle.

Which of the following keywords are access modifier:


Answer:private / protected

Select correct statements:


Answer: Subclasses or derived classes inherit the fields and methods from their
base class.//An abstract data type can be part of a program in the form of an
interface.

Which of following statements are true:


Answer: An object can be saved in a file if its class type is stated to implement
the Serializable interface.//If the vector’s capacity is greater than its size,
then a new element can be inserted at the end of the vector immediately.

Select true statement(s) about Java.


Answer: Variable names are strings of any length of letters, digits, underscores,
and dollar signs//For a postfix operator, autoincrement (or autodecrement) is the
last operation performed// Characters are 16 bits long

x = 7; y = 4 * ++x; z = 5 * x--; what are the values of x, y, z after executing the


above three statements?
Answer: x = 7, y = 32, z = 40

What kind of methods of a class can be called by methods which is belong to another
class?
Answer: public methods

Can two different classes contain methods with the same name?
Answer:Yes, this is always allowed.

What is the primary purpose of a constructor?


Answer:To initialize each object as it is declared.

Select correct statement.


Answer:In Java, the extends clause is used to specify inheritance

Select correct statement.


Answer:Interfaces can extend any number of other interfaces.

Select correct Java statement.


Answer:for (int i=0, j=100; i < j; i++, --j) {;}

Select incorrect statement. In java, ......


Answer:The default modifier means that a method or a field is accessible to derived
classes.

Which of sentences about singly linked list are true:


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

Select correct statement(s) about Doubly Linked List:


Answer: 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.
Select incorrect statement about skip list:
Answer: The number of reference fields indicates the level of each node, and the
number of levels is maxLevel = `[lgn]`+ 1

Select incorrect statement about skip list:


Answer: In 20-element skip list, the node in position 3 points to the node in
position 7//The search time is O (lgn) in the worst case.

Select correct statement(s):


Answer: A singly linked list is a node that has a link only to its successor in
this sequence//Inserting a new node at the end of the singly linked list without
tail field requires O( n ) steps.

Linked lists allow easy insertion and deletion of information because such
operations have a local impact on the list.
Answer:True

Which of the following operations take O( 1)time:


Answer: Searching one node in singly linked list without tail in the best case.
//Deleting one node from the begin of doubly linked list

Select correct statements about Linked List:


Answer: Skip lists was motivated by the need to speed up the searching process.//
The efficiency of search in singly and doubly linked lists can be improved by
dynamically organizing the list in a certain manner using Self-Ogranizing Lists.

Which of the following statements about the Stack are true


Answer: Popping operation in the linked list implementation is executed in the
constant time O(1)//Popping operation in the array implementation is executed in
the constant time O(1)

In the circular array version of the Queue class, which operations require O(n)
linear time for their worst-case behavior
Answer:enqueue() when the capacity has been reached//clear()

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?
Answer:([Link] == null)

Suppose that the variable temp refers to a node in a linked list (using the SLLNode
class with instance variables called info and next). What statement changes temp so
that it refers to the next node?
Answer:temp = temp . next ;

Which boolean expression indicates whether the data in two nodes (p and q) are the
same. Assume that neither p nor q is null.
Answer:[Link] == [Link] or [Link]([Link])

Which of these operations are likely to have a constant time for worst-case in the
linked lists?
Answer:None of the others.

Select false statement:


Answer:In the array list, poping is executed in O (lgn) to the worst case.

Select true statements about stack:


Answer:The Java implementation of the stack is potentially fatal.//Stack can be
implemented by linked list.
Which of the following methods of queue are true:
Answer: enqueue(el) — Put the element el at the end of the queue.//firstEl() —
Return the first element in the queue without removing it.//isEmpty() — Check to
see if the queue is empty.

Which of the following can be executed in constant time O ( n )


Answer: when deleting a node of a singly linked list in the average case.//when
deleting a node of a singly linked list in the worst case.

Which of the following about stack are true:


Answer: The most top element is the latest added element.//Operations of stack are
based on Last in First out structure.

In the doubly linked list implementation of queue, enqueuing can be executed in


constant time O( n).
Answer: False

In the array implementation of queue, enqueuing can be executed in constant time


O(1)
Answer:True

Which of the following statement about the Recursion is true


Answer:All of the others

When a method call is executed, which information is not saved in the activation
record?
Answer: Instances of classes.//Current depth of recursion

The operation for adding an entry to a stack is traditionally called:


Answer:push

In the array version of the Queue, which operations require Otime for their worst-
case behavior?
Answer:None of the others

Which of the following applications may use a stack?


Answer:All of the others.

In the linked-list version of the Queue, which operations require linear time for
their worst-case behavior?
Answer:None of the others

Which of the following statements are true:


Answer:The return address is address of the caller’s instruction immediately
following the call.//The recursive version increases program readability, improves
self-documentation and simplifies coding.

When converting a method from a recursive version into an iterative version,


Answer: The brevity of program formulation lost. However, the brevity may not be an
issue in Java.//Program clarity can be diminished.

Select incorrect statement about Recursion:


Answer:The anchor or ground case allows for the construction of new objects out of
basic elements or objects that have already been constructed

Which of the following statements are false:


Answer:An activation record contains code of method owning it//An activation record
still exists after a method owning it ends
Which of the following statement about the Binary Tree is true
Answer:Binary Trees can be implemented as arrays//The search process of Binary
Search Tree takes O( n ) time in the worst case.

Which of the following statement about the Tree Traversal is false


Answer:Tree traversal is the process of visiting each node in the tree some
times.//Postorder tree traversal can be only implemented in recursion.

When a method call is executed, which information is not saved in the activation
record?
Answer:Current depth of recursion.

With respect to the execution of recursive function (method), .......


Answer:None of the others.

With respect to recursion, select correct statement.


Answer:All of the others.

With respect to recursion, select correct statement. (1) Recursive version executes
slower than iterative version. (2) Iterative version executes slower than recursive
version. (3) Recursive version needs more memory than iterative version (4)
Iterative version needs more memory than recursive version Statements .....
and ...... are true.
Answer:None of the other

Recursive definitions on most computers are eventually implemented using a run-time


stack and this implementation is done by the operating system.
Answer:True

In all cases, nonrecursive implementation is faster recursive implementation.


Answer:False

Which of the following concepts of tree are true:


Answer:The level of a node must be between 1 and height of the tree.//The height of
a nonempty tree is the maximum level of a node in the tree.//The level of a node is
the length of the path from the root to the node plus 1.

Select correct statement:


Answer:Breath-First traversal is implemented using queue.//The complexity of
searching depends on the shape of the tree and the position of the node in the
tree.//For a binary tree with n nodes, there are n! different traversals.

Select incorrect statement:


Answer:Morris’s algorithm does not temporarily change tree structure.//A recursive
implementation of preorder tree traversal uses stack explicitly.//Depth-first
traversal can not be implemented if not using stack.

Which of the following statements are true:


Answer:Using Polish notation, all expressions have to be broken down unambiguous
into separate operations and put into their proper order.//Expression trees do not
use parentheses.//Polish notation eliminates all parentheses from formulas.

In which order does an postorder traversal visit the nodes of the above tree:
Answer:j k e f l m g b c n h q r s o p i d a

Which of the following statement about the Graph is true


Answer:All of the others
What graph traversal algorithm uses a queue to keep track of vertices which need to
be processed?
Answer:Breadth-first search.

Select the one TRUE statement.


Answer:Every perfect balanced binary tree is also a balanced binary tree.

......... will visit nodes of a tree starting from the highest (or lowest) level
and moving down (or up) level by level and at a level, it visits nodes from left to
right (or from right to left).
Answer:Breath-First Traversal

Study the following statements: (1) A drawback of a balanced tree is the search-
time may be out of control. (2) The DSW algorithm can be used to rebalance a binary
tree. (3) An AVL tree is one in which the height of the left and the right subtrees
of the every node must be same. The statement (1) is ....., the statement (2)
is ...... and the statement (3) is ......
Answer:False, true, false

A heap implemetation is an excellent demonstration for a .......


Answer:priority queue

Which of the following sentences are true:


Answer:The complexity of DFS is `O(|V| + |E|)` , where `|V|` is number of vertices
and `|E|` is number of edges.//The complexity of DFS is `O(|V|^2)`

Which of the following statements about finding the shortest path are true:
Answer:The complexity of Dijkstra’s algorithm is `O(|V|^2)`//For label-correcting
method, information of any label can be changed during application of method.

Which of the following statement about spanning tree is false:


Answer:None of the others.

Which of the following statements about graph coloring is true:


Answer:Sequential Coloring algorithm establishes the sequence of vertices and a
sequence of color before coloring them.//The complexity of sequential Coloring
algorithm is `O(|V|^2)`

Which graph representation is best?


Answer:It depends on the problem

Most of the label-setting and label-correcting methods are used to find from one
vertex to all other vertices.
Answer:True

When is insertionsort a good choice for sorting an array?


Answer:The array’s size is not large .

Which algorithms have the complexity of O(n lgn)


Answer:Quick sort in the best case.//Heap sort in the worst case.

What is the worst-case time for mergesort to sort an array of n elements?


Answer:O ( ` n `lg` n`)

Selectionsort and quicksort both fall into the same category of sorting algorithms.
What is this category?
Answer:Worst time is quadratic.//Interchange sorts

Using adjacency matrix representation for a graph of n vertices and m edges, what
is the expected number of operations needed to loop through the graph to find down
adjacent list of a known vertex?
Answer:O( n )

What graph traversal algorithm uses a queue to keep track of vertices which needs
to be processed?
Answer:Breadth-first search.

Suppose that you have a directed graph representing all the flights that an airline
flies. What algorithm might be used to find the best sequence of connections from
one city to another?
Answer:A shortest-path algorithm.

The ..... algorithm can be used to schedule the final exams so that no student has
two exams at the same time.
Answer:Graph coloring

Which of the following statements about efficient sorting is false :


Answer:Only insertion sort is apllied in all h-sorts of shell sort.//Shell sort
divides the original array into physical subarrays, sorting them separately, then
merging and dividing them again to sort the new subarrays until the whole array is
sorted.

Which of the following statements about efficient sorting is false:


Answer:The worst case is when the bound divides an array into subarrays of
approximately length `n/2`//The best case of quick sort happens when bound is the
largest (the smallest) element of the array.

Which of the following statements is true:


Answer:None of others.

Which of the following statements about efficient sorting is true:


Answer:In heap sort, the number of calling moveDown() in the first loop is
n/2//Heap sort starts from the end of the array by finding the largest elements.

What is the worst-case time for mergesort to sort an array of n elements?


Answer:O(nlgn)

What is the worst-case time for bubble sort to sort an array of n elements?
Answer:O`(n^2)`

What is the worst-case time for heapsort to sort an array of n elements?


Answer:O(nlgn)

With respect to number times of moving data in the selection sort algorithm applied
to an array of a elements, how many times are the array elements moved in the worst
case?
Answer:O( n )

In Insertion Sort, the number of movements and comparisons for a randomly ordered
array is closer to the best case.
Answer:False

Which of the following statement about Open Addressing are false:


Answer:In linear probing of the open addressing method, the position in which key
can be stored is found by sequentially searching starting from the begin of
table.//Using quadratic probing gives much better results than linear probing and
avoids the problem of cluster buildup.
Which of the following statement are true:
Answer:Linked list can be used in Bucket Addressing.//Coalesced hashing combines
linear probing with chaning.

Which of the following statement about Perfect Hash Functions are true:
Answer:Cichelli’s method uses an exhaustive search.//Cichelli’s method is used to
hash relatively small number of reserved words.

Select correct statements :


Answer:A reorganization of the file is avoided by using extendible hashing if the
directory overflows.//The characteristic feature of extendible hashing is the
organization of the index, which is expandable table.

Hash function is function that can transform a particular key (K) (a string, number
or record) into an index in the table used for storing items of the same type as K.
Answer:True

Which of the following statement is true:


Answer:If hash function transforms different keys into different numbers, it is
called a perfect hash function.

Select correct statements:


Answer:The boundary folding method can not be applied to string data.//In shift
folding method, the key is usually divided into even parts of some fixed size plus
some remainder and added.

What is the worst-case time for binary search finding a single item in an array?
Answer:Logarithmic time

What is the best definition of a collision situation in a hash table?


Answer:Two entries with different keys have the same exact hash value.

A chained hash table has an array size of 512. What is the maximum number of
entries that can be placed in the table?
Answer:None of the others

Suppose that you place m items in a hash table with an array size of s. What is the
correct formula for the load factor?
Answer:m/s

Which of the following data structure can be implement Huffman Coding


Answer:Singly linked list.//Priority queue.//Doubly linked list.

Select incorrect statements about Huffman Coding:


Answer:Huffman tree is only implemented by non-recursive algorithm.//Adaptive
Huffman coding uses breath-first left-to-right tree traversal generates a list of
nodes with nonincreasing frequency counter.

Select correct statement about Run-length encoding.


Answer:A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs.

Select correct statement about Ziv-Lempel Code.


Answer:All of the others.

In data compression, no special punctuation is required to separate two codewords


in a coded message
Answer:True.
Which of the following data structure can be implemented using Huffman Coding?
Answer:All of the others

Select incorrect statement about restrictions need to be imposed on the prospective


codes:
Answer:Each codeword may be corresponds to one or many symbols.

Select correct statement about Run-length encoding.


Answer:A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs.

Identify whether below code has error or not:


Answer:Compile error.

Identify whether below code has error or not:


Answer:3 compile errors.

Which of the following statements are true


Answer:a. object1.process2 (‘N’) calls process2 of class ExtC.//object2.process3
(‘N’) call process3 of class C.

Identify which alogrithm the above code implements


Answer:Insertion Sort

Identify which alogrithm the above code implements


Answer:Bubble sort

Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is “ABCDEF\n”
Answer:FEDCBA

What is output if nontail is called with i = 3


Answer:Runtime error is issued.

What is output if nontail is called with i = 5


Answer:1315131

What is output if preorderVRL is executed and structure of Binary Tree is the


following image:
Answer:2 6 3 15 8 10 1 11 12

What is output if breadthFirst is executed and structure of Binary Tree is the


following image:
Answer:2 6 8 3 15 10 1 11 12

Assume that sort is executed with array {9,4,2,5,8,10,3}. What is output after
iteration i=5 of the outer for loop completed
Answer:{2,4,5,8,9,10,3}

Assume that sort is executed with array {19,14,6,5,18,10,15}. What is output after
iteration i=5 of the outer for loop completed
Answer:{19,18,14,6,5,10,15}

Let deleteFromHead be method used to delete the first element of generic singly
linked list class: Identify whether above code has error or not:
Answer:There may be runtime error in some case

Identify whether the code of pop method has error or not:


Answer:There may be runtime error in some case.

Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is “ABCDEF\n”
Answer: \nFEDCBA

Suppose that obj is an Object variable and s is a String variable. Which of the
following statements is a correctly-compiling widening conversion? Don't worry
about possible run-time exceptions
Answer:All of the others

Suppose that obj is an Object variable and that it refers to an Integer object. If
s is a String variable, then which statement is correct about the assignment "s =
(String) obj;"?
Answer:The statement will not compile.

Suppose that obj is an Object variable, and consider these two possible
assignments: obj = new Integer(42);obj = new Double(42.0);Both assignments compile
correctly. Select the true statement about what happens at run time:
Answer:Both assignments will run with no errors, regardless of which one occurs
first.

Identify which alogrithm the above code implements


Answer:Heap Sort

Identify which alogrithm the above code implements


Answer:Quick sort

Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is “123456\n”
Answer:654321

Here is an INCORRECT pseudocode for the algorithm which is supposed to determine


whether a sequence of parentheses is balanced: Which of these unbalanced sequences
does the above code think is balanced?
Answer:((()()))//((()))

Here is an INCORRECT pseudocode for the algorithm which is supposed to determine


whether a sequence of parentheses is balanced:declare a character stackwhile ( more
input is available){read a characterif ( the character is a '(' )push it on the
stackelse if ( the character is a ')' and the stack is not empty )pop a character
off the stackelseprint "unbalanced" and exit}print "balanced"Consider the usual
algorithm for determining whether a sequence of parentheses is balanced. What is
the maximum number of parentheses that will appear on the stack AT ANY ONE TIME
when the algorithm analyzes: (()(())(()))?
Answer:3

What is output if inorderRVL is executed and structure of Binary Tree is the


following image:
Answer:30 40 11 10 7 14 3 2 1

Consider this binary search tree:Suppose we remove the root, replacing it with
something from the left subtree. What will be the new root ?
Answer:5

Assume that sort is executed with array {5 3 8 9 1 7 0 2 6 4} {9,4,2,5,8,10,3}.


What is output after iteration i=4 of the outer for loop completed
Answer:1 3 5 8 9 7 0 2 6 4
Assume that sort is executed with array {5 3 8 9 1 7 0 2 6 4}. What is output after
iteration i=4 of the outer for loop completed
Answer:{9 8 5 3 1 7 0 2 6 4}

Consider the following method:public static void test_a(int n){[Link](n


+ " ");if (n>0)test_a(n-2);}What is printed by the call test_a(4)?
Answer:4 2 0

Consider the following method:public static void test_a(int n){if (n>0)test_a(n-


2);[Link](n + " ");}What is printed by the call test_a(4)?Identify
whether the code of pop method has error or not
Answer:0 2 4

Assume that sort is executed with array {5 3 8 9 1 7 0 2 6 4}. What is output after
iteration j=4 of the inner for loop completed
Answer:3 5 8 1 9 7 0 2 6 4

Answer:144

Answer:Nothing is wrong with the code, it will be compiled without errors.

The program will compile without error and print 2 when running.

Answer:120

Study the following pseudocode:What is written to the screen if the input is


"ABBAABBA" ?
Answer:ABBAABBA

number >= 0 && number < 10

Answer:O`(n^2)`

Answer:1, 2, 3, 4, 5, 7, 6

Answer:O`(n^2)`

Assume that the class BSTNode is implemented for a node in a binary search tree and
basic operations on a stack are implemented also and the operation visit will
process requirements on a node of the tree. Consider the following tree traversal
algorithm in Java:Which traversal does the above algorithm implement?
Answer:Preorder tree traversal

b. In the second phase, this algorithm exchanges n-1 times the root with the
element in position i.c. moveDown() is called n/2 times to create the heap in the
first phase.d. The heap is restored n-1 times in the second phase.
Answer:All of the others.

Answer:7
Answer:40 30 7 10 11 3 1 2 14

Consider the following algorithm:


Answer:5

Answer:5

//////////////////////// 2 file check of Vuong/////////////////////////////////////


Which statements are true about inheritance?
Answer: In Java the extends clause is used to specify inheritance

Which statements are true about interfaces?


Answer: Interfaces can extend any number of other interfaces

Which one of these for statements is valid


Answer: for (int i=0, j=100; i<j; i++, --j) {;}

Which statements are false about modifiers?


Answer: The default modifier means that a method or a field is a accessible to
derived classes

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?
Answer: ([Link] == null)

Suppose temp refers to a node in a linked list (using the SLLNode class with
instance variables called info and next).
What statement changes temp so that it refers to the next node?
Answer: temp = [Link];

Which boolean expression indicates whether the data in two node (p and q) are the
same. Assume that neither p nor q is null
Answer: [Link] == [Link]

Which of these operations are likely to have a constant time for worst-case in the
linked lists?
Answer: None of the others

The operation for adding an entry to a stack is traditionally called


Answer: push

In the array version of the Queue, which operations require O(n) time for their
worst-case behavior?
Answer: None of the others

Which of the following applications many use a stack?


Answer: All of the others

In the linked-list version of the Queue, which operations require linear time for
their worst-case behavior?
Answer: None of the others

When a method call is executed, which information is not saved in the activation
record?
Answer: Current depth of recursion

When the compiler compiles your program, how is a recursive call treated
differently than a non-recursive method call?
Answer: None of the others

Select the one TRUE statement


Answer: Every perfect balanced binary tree is also a balanced binary tree

……. Is visiting node starting from the highest (or lowest) level and moving down
(or up) level by level, visiting nodes on each level from left to right (or from
right to left)
Answer: Breath-First Traversal
……………..rebalances the tree globally; each and every node could have been involved
in rebalancing either by moving data from nodes or by creasing new values to
reference fields.
Answer: The DSW Algorithm

A heap is an exellent way to implement a ……………..


Answer: priority queue

What is the expected number of operations needed to loop through all the edges
terminating at a particular vertex given an adjacency matrix representation of the
graph? (Assume n vertices are in the graph and m edges terminate at the desired
node).
Answer: O(n)

What graph traversal algorithm uses a queue to keep track of vertices which need to
be processed?
Answer: Breadth-first search.

Suppose you have a directed graph representing all the flights that an airline
flies. What algorithm might be used to find the best sequence of connections from
one city to another?
Answer: A shortest-path algorithm.

The final exams at a university can be scheduled so that no student has two exams
at the same time by applying ……………
Answer: Graph coloring

What is the worst-case time for mergesort to sort an array of n elements?


Answer: O(nlgn)

What is the worst-case time for bublesort to sort an array of n elements?


Answer: O(n2)

What is the worst-case time for heapsort to sort an array of n elements?


Answer: O(nlgn)

In a selectionsort of n elements, how many times are the array elements moved in
the worst case?
Answer: O(n)

What is the worst-case time for binary search finding a single item in an array?
Answer: Logarithmic time

What is the best definition of a collision in a hash table?


Answer: Two entries with different keys have the same exact hash value.

A chained hash table has an array size of 512. What is the maximum number of
entries that can be placed in the table?
Answer: There is no maximum

Suppose you place m items in a hash table with an array size of s. What is the
correct formula for the load factor?
Answer: m/s

Which of the following data structure can be implement Huffman Coding


Answer: All of the others

Select incorrect statements about restrictions need to be imposed on the


prospective codes:
Answer: Each codeword may corresponds to one or many symbols.

Select correct statement about Run-length encoding.


Answer: A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs.

Select correct statement about Ziv-Lempel Code.


Answer: All of the others.

Which statement is true about the following code?a. Interface1 and Interface2 do
not match, therefore, MyClass cannot implement them [Link] declarations of void
g() in the two interfaces conflict, therefore, the code will not compilec. The
declarations of int VAL_B in the two interfaces conflict, therefore, the code will
not compile.d. Nothing is wrong with the code, it will compile without errors.
Answer: Nothing is wrong with the code, it will compile without errors.

What will be the result of attempting to compile and run the following program?
a. The program will fail to compile.
b. The program will compile without error and print 0 when run.
c. The program will compile without error and print 1 when run.d. The program
will compile without error and print 2 when run.
Answer: The program will compile without error and print 2 when run.

Which digits, and in which order, will be printed when the following program is
run?
a. The program will only print 1 and 4, in that order
.b. The program will only print 1, 4, and 5, in that order.
c. The program will only print 3 and 5, in that order.
d. The program will only print 1, 2, 4, and 5, in that order.
Answer: The program will only print 1, 4, and 5, in that order.

Consider the following pseudocode: What is written to the screen for the input
"ABBAABBA"?
a. ABABABABb. BABABABAc. ABBAABBAd. BAABBAAB
Answer: ABBAABBA

Consider the following method: What values of number are directly handled by the
stopping case?
a. number < 0b. number < 10c. number >= 0 && number < 10d. number > 10
Answer: number >= 0 && number < 10

Consider the following sort algorithm Number of comparisons of keys and comparisons
of i and least is:
a. n(n-1)/2b. n-1c. ((n-1)(n+2))/2d. None of the others
Answer: ((n-1)(n+2))/2

Consider the following sort algorithm: Assume that this algorithm is executed with
array {7,1,2,3,4,5,6}. What is output after iteration i=4 of the outer for loop
completeda. 1, 2, 3, 4, 5, 6, 7b. 1, 2, 3, 7, 4, 5, 6c. 1, 2, 3, 4, 5, 7, 6d.
1, 2, 3, 4, 7, 5, 6
Answer: 1, 2, 3, 4, 5, 7, 6

Consider the following sort algorithm: Number of comparisons of keys isa.


(n(n+1))/2b. (n(n-1))/2c. n2d. n2/2
Answer: (n(n-1))/2
Consider the following algorithm: Which traversal does the above algorithm
implement?
a. Breadth-first traversal
b. Inorder tree traversal
c. Postorder tree traversal
d. Preorder tree traversal
Answer: Preorder tree traversal

Consider the following sort algorithm:


a. moveDown() is called times to create the heap in the first phase
.b. The heap is restored times in the second phase.
c. In the second phase, this algorithm exchanges times the root with the
element in position.
d. All of the others.
Answer: All of the others.

Consider this method declaration:How many asterisks are printed by the method call
quiz(5)?
a.
8b.
4c.
7d. None of the others
Answer: 7

Consider the following traversal algorithm:What is output if this algorithm is


executed on the following binary tree:
a. 40 30 7 10 11 3 1 2 14
b. 1 3 2 7 10 40 30 11 14
c. 1 2 3 14 7 10 11 40 30
d. 14 2 1 3 11 10 7 30 40
Answer: 40 30 7 10 11 3 1 2 14

Consider the following algorithm:


a. 3
b. 9
c. 5
d. 8
Answer: 5

Which statement, when inserted at the indicated position in the following code,
will cause a runtime exception?a. x = y;b. z = x;c. y = (B) x;d. z =
(C) y;e. y = (A) y;
Answer: y = (B) x;

A method within a class is only accessible by classes that are defined within the
same
Answer: Do not declare the method with any accessibility modifiers.

Which are invalid identifiers?


Answer: zer@

Which statement concerning the switch construct is true?


Answer: A character literal can be used as a value for a case label

If str denotes a String object with the string "73", which of these expressions
will convert the string to the int value 73?
Answer: (new Integer(str)).intValue()

Select correct statements about a singly linked list.


Answer: A node with a specified value (info) can be found by traversing the list.

Advantages which linked list have over an array:


Answer: Size can be expanded and shrunk rapidly.

Which of the following methods take O(n) time for the worst case:
Answer: All of the others.

Select correct statements about a singly linked list.


Answer: Deleting a node at the beginning of a list involves setting head to point
to [Link].

Properties of a stack is:


Answer: Only one item can be accessed at once.

Properties of a queue are:


Answer: Only one item can be accessed at once.

In the array version of the Stack class, which operations require linear time for
their worst-case behavior?
Answer: None of these operations require linear time.

In the linked-list version of the Stack class, which operations require linear time
for their worst-case behavior? Assume that addtoTail, deletefromTail are used.
Answer: pop

Select wrong statements:


Answer: Recursion can be only replaced by iteration.

In a single method declaration, what is the maximum number of statements that may
be recursive calls?
Answer: There is no fixed maximum

Consider algorithm of the 8-queen problem:


Answer: The algorithm finds all solutions.

On average, what is the maximum number of comparisons needed to find a key in a


balanced binary search tree with 1 million nodes?
Answer: 20

To delete a node in a binary search tree that has two children, the Deletion by
Merging method requires to find what node?
Answer: The rightmost node of the left subtree of the deleted node.

Tree balancing can be performed locally after an element is inserted into or


deleted from the tree using………………….
Answer: AVL tree.

The DSW Algorithm uses:


Answer: All of the others.

The depth-first search algorithm for a graph:


Answer: Travels all possible paths from a vertex to see if it can find the
destination before it moves on to the adjacent vertices.
Select right statements:
a. Djikstra's shortest path algorithm can be applied to undirected graph.
b. The breadth-first search can be used to find the shortest path from a source
vertex to the destination vertex
c. All of the others.
d. None of the others.
Answer: All of the others.

Two algorithms which used for finding a minimum spanning tree are Kruskal and
Dijkstra. Which algorithm uses the cycle detection method?
Answer: All of the others.

Which of the following statements about shortest path finding algorithms are true:
Answer: Dijkstra’s algorithm is label-setting algorithm.

When is Insertionsort a good choice for sorting an array?


Answer: The array has only a few items out of place.

Mergesort makes two recursive calls. Which statement is true after these recursive
calls finish, but before the merge step?
Answer: Elements in each half of the array are sorted amongst themselves.

Suppose we are sorting an array of eight integers using a some quadratic (O(n2)))
sorting algorithm. After four iterations of the algorithm's main loop, the array
elements are ordered as shown here: 2 4 5 7 8 1 3 6. Which statement is
correct?
Answer: The algorithm is not selectionsort, but it might be insertionsort.

In Quicksort, the bound value (pivot) is:


Answer: All of the others.

The more complex the hashing functions, the better it is


Answer: False

Which of the following methods are used to collision resolution:


Answer: Open addressing.

Which of the following hashing methods can cause collision:


Answer: All of the others.

Select incorrect statements:


a. Quadratic probing eliminates primary clustering but suffers from the less
severe secondary clustering.
b. In double hashing the step size depends on the key and is obtained from a
secondary hash function.
c. In quadratic probing the offset from x is the square of the step number, so
the probe goes to x, x+1, x+2, x+3, x+4, and so on.d. None of the others
Answer: In quadratic probing the offset from x is the square of the step number, so
the probe goes to x, x+1, x+2, x+3, x+4, and so on.

Assume that encoding of three symbols X, Y, W, Z is: V: 10, X: 010, Y: 101, W: 100,
Z: 110.
Which of the following restrictions does this encoding violate:
Answer: No codeword is a prefix of another codeword.

Select incorrect statements about Data compression:


Answer: Huffman algorithm can be only applied to text files.
The Huffman algorithm always produces a unique binary tree.
Answer: False

In an optimal system, there should not be any unused short codewords either a
stand-alone encodings or as prefixes for longer codewords.
Answer: True

Select incorrect statements about Data compression:


Answer: Huffman tree can be only constructed bottom-up.

Which expressions will evaluate to true if preceded by the following code?a. (a ==


"Hello")b. (a == b)c. (a == c)d. [Link](b)
Answer: (a == c) [Link](b)

Consider the following alogorithm: What is output when calling TriangularNumber(4)


a. 6
b. 10
c. 15
d. 20
Answer: 10

Consider the following alogorithm: What is maximum number of activation records


(including its caller) in runtime stack when calling TriangularNumber(10)
Answer: 11

Consider the following alogorithm:


What is maximum number of activation records (including its caller) in runtime
stack when traversing the below tree using the above algorithm?
Answer: 5

Consider the following alogorithm: What is maximum number of elements in queue when
traversing the below tree using the above algorithm?
Answer: 4

Consider the following alogorithm: Assume array data[] = {2,8,6,1,10,15,3,12,11}.


Array data after ending the first loop.
Answer: {15,12,6,11,10,2,3,1,8}

Consider the following alogorithm: Select right statements:


a. In the first loop, moveDown is called n/2 times in any case.
b. The total number of moves in all executions of moveDown in the second phase
is O(lgn)
.c. All of the others.
d. None of the others.
Answer: In the first loop, moveDown is called n/2 times in any case.

What will be printed when the following program is run?


a. 0
b. 1
c. 2
[Link] error occurs when compiling the program.
Answer: 2
What will be printed when the following program is run?
a. “this is g of A”b. “this is g of C”c. An error occurs when
compiling the programd. Nothing is printed
Answer: “this is g of C”

Consider the following alogorithm: Assume array data[] = {4,10,8,3,12,17,5,14,13}.


Array data after executing 4 iterations of outer loop.
Answer: {3,4,8,10,12,17,5,14,13}

Consider the following alogorithm: How many times is number 840 printed out when
call pattern(840)
Answer: 2

Consider the following alogorithm: How many integers will the program print when
calling nonTail(n), n > 0
Answer: 2^n-1

Consider the following alogorithm:The above algorithm is used to:


a. Count number of even values in binary tree.
b. Print even numbers in binary tree.c. Print even numbers in ascending
order.
d. Print and count number of even values in binary tree.
Answer: Print even numbers in binary tree.

Consider the following alogorithmThe above algorithm is used to:


a. Count number of nodes in binary tree.
b. Calculate height of binary tree.
c. Count number of nonterminal nodes in binary tree.d. None of the others.
Answer: Calculate height of binary tree.

Consider the following alogorithm:The above algorithm is used to:


a. Check whether binary tree is balanced.
b. Check whether height of left subtree is greater than height of right subtree
c. Check whether height of right subtree is greater than height of left subtree.
d. None of the others
Answer: Check whether binary tree is balanced.

Select incorrect statements about Object – Oriented Programming


Answer:Static methods and variables are associated with the class itself and are
called instance methods and instance variables

Which of the following keywords are access modifier


Answer:Protected b. Private

Select correct statements


a. A derived class can override the definition of a final method by introducing
its own definition
b. In an abstract class, methods are only declared but not defined
c. Subclasses or derived classes inherit the fields and methods from their base
class
d. An abstract data type can be part of a program in the form of an interface
Answer: In an abstract class, methods are only declared but not defined /////
Subclasses or derived classes inherit the fields and methods from their base
class ////// An abstract data type can be part of a program in the form of an
interface
Which of following statements are true
Answer: An object can be saved in a file if its class type is stated to implement
the Serializable interface /// If the vector’s capacity is greater than its size,
then a new element can be inserted at the end of the vector immediately

Which of sentences about singly linked list are true


Answer: Deleting a node at the beginning of the list takes, constant time O(1)///
c. On the overage, delete operation executes O(n) steps////
e. There is no immediate access to the predecessor of any node in list

Select correct statement(s) about Doubly Linked List


Answer: The node which is deleted from the list will be claimed by the garbage
collector //// Deleting a node at the end of the list takes constant time O(1)

Select incorrect statement about skip lista. In a skip list of n nodes, for each
k and I such that 1 <= k <= [lgn]…b. The number of reference fields indicates
the level of each node and the number of levels is maxLevel = [lgn] +1c. All of
the othersd. None of the others
Answer:None of the others

Select incorrect statement about skip list:


Answer:The search time is O(lgn) in the worst case

Select false statement:


a. Stack can be implemented using linked list///
b. Stack is applied to Java Virtual Machine///
c. In the array list, popping is executed in O(lgn) to the worst case///
d. In the array list, popping is executed in constant time O(1)
Answer:In the array list, popping is executed in O(lgn) to the worst case

Select true statements about stack


Answer:The Java implementation of the stack is potentially fatal ///// Stack can be
implemented by linked list

Which of the following methods of queue are true


Answer: isEmpty() – Check to see if the queue is empty d. enqueue(el) – Put the
element el at the end of the queue f. firstEl() – Return the first element in
the queue without removing it

Which of the following can be executed in constant time O(n)


Answer: When deleting a node of a singly linked list in the average case b. When
deleting a node of a singly linked list in the worst case

Which of the following statements are true


Answer: The return address is address of the caller’s instruction immediately
following the call b. The recursive version increases program readability,
improves self-documentation and simplifies coding

When converting a method from a recursive version into a iterative version


Answer: The brevity of program formulation lost. However, the brevity may not be an
issue in Java b. Program clarity can be diminished

Recursive definitions on most computers are eventually implemented using a run-time


stack and this implementation is done by the operating system
Answer:True

In all cases, nonrecursive implementation is faster recursive implementation


Answer:True
Which of the following concepts of tree are true
a. The height of a nonempty tree is the maximum level of a node in the tree.
c. The level of a node is the length of the path from the root to the node plus
1
d. The level of a node must be between 1 and height of the tree

Select correct statement


Answer: The complexity of searching depends on the shape of the tree and the
position of the node in the tree d. Breath-First traversal is implemented
using queue e. For a binary tree with n nodes, there are n! different traversals

Select incorrect statement


Answer: Depth-first traversal can not be implemented if not using stack c. A
recursive implementation of preorder tree traversal uses stack explicitly e.
Morris’s algorithm does not temporarily change tree structure

Which of the following statements are true


Answer: Polish notation eliminate all parentheses from formulas b. Using Polish
notation, all expressions have to be broken down unambiguous into separate
operations and put into their proper order e. Expression trees do not use
parentheses

Which of the following sentences are true: a. All algorithms are more efficient
if the underlying graph traversal is not BFS but DFS b. The complexity of DFS is
O(|V|2) c. The complexity of DFS is O(|V| + |E|), where |V| is number of
vertices and |E| is number of edges d. To prevent loop from happen is al
algorithm for traversing a graph, each visited vertex can be marked
Answer: The complexity of DFS is O(|V| + |E|), where |V| is number of vertices and
|E| is number of edges d. To prevent loop from happen is al algorithm for
traversing a graph, each visited vertex can be marked

Which of the following statements about finding the shortest path are true: a.
The complexity of Ford’s algorithm is O(|V||E|) for any graph b. For
label-correcting method, information of any label can be changed during application
of method c. Ford’s algorithm relies on label-setting method d. The
complexity of Dijkstra’s algorithm using heap is O(}V}ln|V|) e. The complexity of
Dijkstra’s algorithm is O(|V|2)
Answer: For label-correcting method, information of any label can be changed during
application of method c. Ford’s algorithm relies on label-setting method e.
The complexity of Dijkstra’s algorithm is O(|V|2)

Which of the following statement about spanning tree is false a. The


complexity of Kruskal’s algorithm depends on the complexity of the sorting method
applied b. The complexity of Kruskal’s algorithm depends on the method used
for cycle detection c. All of the others d. None of the others
Answer:None of the others

Which of the following statements about graph coloring is true


Answer: In sequential coloring algorithm, vertices must be ordered according to
indices already to the vertices b. The complexity of sequential corloring
algorithm is O(|V|2) c. Sequential Coloring algorithm establishes the
sequence of vertices and a sequence of color before colring them

Which of the following statements about efficient sorting is false


Answer: Shell sort divides the original array into physical subarrays, sorting them
separately, then merging and dividing them again to sort the new subarrays until
the whole array is sorted d. Only insertion sort is apllied in all h-sorts of
shell sort
Which of the following statements about efficient sorting is false
Answer: The worst case is when the bound divides an array into subarrays of
approximately length n/2 c. The best case of quick sort happens when bound is the
largest (the smallest) element of the array

Which of the following statement is true: a. All the forting methods implemented
in java is applied to any basic data type b. For objects comparison, a
comparison criterion must be implemented by user for all classes c. All of
others d. None of others
Answer:For objects comparison, a comparison criterion must be implemented by user
for all classes

In insertion Sort, the number of movements and comparisons for a randomly ordered
array is closer to the best case
Answer:False

Which of the following statement about Open Addressing are false


Answer: Using quadratic probing gives much better results than linear probing and
avoids the problem of cluster buildup b. In linear probing of the open addressing
method, the position in which key can be stored is found by sequentially searching
starting from the begin of table

Which of the following statement are true: a. Linked list can be used in Bucket
Addressing b. In chaining, searches always fast if using linked lists c.
Self-organizing linked list can be used to improve performance in chaining
d. Coalesced hashing combines linear probing with chaning
Answer:Linked list can be used in Bucket Addressing b. Self-organizing linked
list can be used to improve performance in chaining c. Coalesced hashing
combines linear probing with chaning

Which of the following statement about Perfect Hash Functions are true
Answer: Cichelli’s method uses an exhaustive search b. Chichelli’s method is
used to hash relatively small number of reserved words

Select correct statements: a. Extendible hashing is directory less technique b.


Extendible hashing is faster than and requires less space than Linear hashing
c. A reorganization of the file is avoided by using extendible hashing if the
directory overflows d. The characteristic feature of extendible hashing is the
organization of the index, which is expandable table e. Linear hashing is
director technique
Answer:A reorganization of the file is avoided by using extendible hashing if the
directory overflows d. The characteristic feature of extendible hashing is
the organization of the index, which is expandable table

Which of the following data structure can be implement Huffman Coding a. Singly
linked list b. Queue c. Skip list d. Priority queue e. Doubly
linked list
Answer:Singly linked list b. Priority queue c. Doubly linked list

Select incorrect statement about Huffman Coding: a. Huffman tree is only


implemented by non-recursive algorithm b. Huffman tree can be built top-down
c. David Huffman’s algorithm may not be useful for sending some specialized
files d. Adaptive Huffman coding uses breath-first left-to-right tree traversal
generates a list of nodes with nonincreasing frequency counter.
Answer:Huffman tree is only implemented by non-recursive algorithm b. Adaptive
Huffman coding uses breath-first left-to-right tree traversal generates a list of
nodes with nonincreasing frequency counter.
Select correct statement about Run-length encoding
Answer:A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs

Identify whether below code has error or not


Answer:Compile error

Identify whether below code has error or nota. 3 compile errorsb. No errorc.
Runtime errord. 2 compile errors
Answer:3 compile errors

Which of the following statements are true: a. object1.process2(‘N’) calls


process2 of class ExtC b. object2.process1(1) does not issue compiler error c.
object2.process3 (‘N’) call process 3 of class C d. object3.process2(‘N’)
call process2 of class C
Answer:object1.process2(‘N’) calls process2 of class ExtC /// object2.process3
(‘N’) call process 3 of class C

Identify which algorithm the above code implements: a. Insertion sort b. Bubble
Sort c. Selection Sort d. Radix Sort
Answer:Insertion sort

Identify which algorithm the above code implements: a. Quick sort b. Radix
sort c. Bubble sort d. Heap sort
Answer:Bubble sort

Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is “ABCDEF\n“
Answer:FEDCBA

What is output if nontail is called with i=3: a. Runtime error is issued b.


1213121 c. 12321 d. 21312
Answer:Runtime error is issued

What is output if nontail is called with i = 5: a. 1315131 b. 13531 c.


3135313 d. None of the others
Answer:1315131

What is output if preorderVRL is executed and structure of Binary Tree is the


following image
Answer:2 6 3 15 8 10 1 11 12

What is output if breadthFirst is executed and structure of Binary Tree if


following image
Answer:2 6 8 3 15 10 1 11 12

Assume that sort is executed with array {9,4,2,5,8,10,3}. What is output after
iteration i=5 of the outer for loop completed
Answer:{2,4,5,8,9,10,3}

Assume that sort is executed with array {19,14,6,5,18,10,15}. What is output after
iteration i=5 of the outer for loop completed
Answer:{19,18,14,6,5,10,15}

//////////////////Duy Cu nho//////////// quizzzzzzzzzzz//////////////


In the doubly linked list implementation, dequeuing can be executed in constant
time O(1)
answer: true
In the doubly linked list implementation, enqueuing can be executed in constant
time O(n)
answer: false

In the doubly linked list implementation, denqueuing can be executed in constant


time O(n)
answer: false

In the array implementation, dequeuing can be executed in time O(n)


answer: false

In the doubly linked list implementation,enqueuing can be executed in time O(n)


answer: false

Which of the following methods of queue are true:


answer:enqueue(el) Put the element el at the end of the queue + dequeue() Take the
first element from the queue + isEmpty() — Check to see if the queue is empty +
firstEl() — Return the first element in the queue without removing it + clear() —
Clear the queue

Select true statements about stack:


answer: Stack can be implemented by linked list // The Java implementation of the
stack is potentially fatal

Which of the following about queue are true:


answer: A queue is an FIFO structure

Which of the following statement of queue are true:


answer: Using array for queue implementation may bot be the best choice // A
natural queue implementation is a linked list (doubly linked list)

Select false statement:


answer: In the array list, poping is executed in time O(n) to the worst case

Which of the following about stack are true:


answer: The most top element is the latest added element // Operation of stack
based on Last in First out structure

When converting a method from a recursive version into an itrative version,


answer:The brevity of program formulation [Link], the brevity may not be in
issue in Java // The program clarity can be diminished

What is the value of h(20)


answer:11

What is the value of h(1)


answer: 14

Select incorect statement:


answer:The anchor or ground case allows for the construction of new objects out of
basic elements or objects that have already been constructed

In all cases, nonrecursive implementation is faster recursive implementation.


answer: false

Which of the following statements are false:


answer: An activation record still exists after a method owning it ends. // An
activation record contains code of method owning it.
Which of the following statements are true:
answer: The data area containing state information of one method is called an
activation record or stack frame // The sate of each method ,including main(), is
characterized by the contents of all automatic variables ,the values of the
method's parameters and the return address.

What is the value of A(3,1)


answer: 13

What are number of additions and number of calls to find Fib(8) using recursive
definition;
answer: 33 and 67

Recursive definitions on most computers are eventually implemented using a run-time


stack and this implementation is done by the operating system.
answer:true

Which of the following statements are true:


answer: The recursive version increases program readability ,improves self-
documentation and simplifies coding // The return address is address of the
caller's instruction immediately following the call

Which of the following concepts of tree are true:


answer: The level of a node is the length of the path from the root to the node
plus 1 // The level of a node must be between 1 and the height of the tree // The
height of a nonempty is the maximum level of a node in the tree.

Which of the following statements are true:


anwer: Polish notation eliminates all parentheses from formulas // Using Polish
notation, all expressions have to be broken down unambiguously into separate
operations and put into their proper order // Expression trees do not use
parentthes

Select incorrect statement:


answer: Morris's algorithm does not temporarily change tree structure // A
Recursive implementation of preorder tree traversal uses stack explicitly // Depth-
first traversal can not be implemented if not using stack

Which of the following statements about heap are false:


answer: Heap represented by array can be traversed eaily in depth-first // A heap
can be defined as an array heap of length n in which

Consider below recursive define about tree:[Link] empty structures is an empty


tree.2. If t1,..,tk are disjointed trees ,then the structure whose root has its
children the root t1,..,tk is also a treeanswer: true
answer: true

In all binary trees, there are 2^i nodes at level i.


answer: false

Which of the following methods are used to traverse a tree without using any stack
or threads:
answer: Traversal through Tree Transformation

Which operation is used in DSW Algorithm:


answer: Rotation

Select correct statement:


answer: The complexity of searching depends on the shape of the treee and the
position of the node in the tree // For a binary tree with n nodes, there are n!
different traversals// Breath-First traversal is implemented using queue

Which of the following methods are used for Depth-First Traversal


answer:All of others

Which of the following statement about finding the shortest path is false:
answer: The complexity of WFI's algorithms is |V^3| that is good efficiency for any
graph // WFI's algorithm doesn't allows detecting cycles in graph

Which of the following statements about graph coloring is true:


answer: The chromatic number of the cycle graph K100 is 100 // In Brelaz's
algorithm, the loop "For each uncolored vertex u adjacent to v" takes O(|V|)

Most of the label-setting and label-correcting methods are used to find the
shortest paths from one vertex to all other vertices:
answer:True

Which graph representation is best?


answer: It depends on the problem.

Which of the following statements about finding the shortest path are true:
answer: The methods solving the shortest path problems are divided into classes:
label-setting and label-correcting // For label-setting methods ,in each pass
through the vertices still to be processed, one vertex is set to value that remains
unchanged to the end of the execution.

Which of the following statements about graph coloring is true:


answer: Sequential Coloring algorithm establishes the sequence of vertices and a
sequence of color before coloring them // The complexity of sequential Coloring
algorith is O(|V^2|)

Which of the following are false:


answer: A graph from v1 to vn is a sequence of edges (v1v2), edges (v2v3)...edges
(vn-1vn) and no edge is repeated // A circuit is a cycle in which all vertices must
be different

Which of the following statements about finding the shortest path are true:
answer: The complexity of Dijkstra's algorithm is O(|V|^2) // The complexity of
Ford's algorithm is O(|V||E|) for any graph (?) // The complexity of Dijkstra's
algorithm using the heap is O((|E| + |V|)lg|V|) // For label-correcting method,
information of any label can be changed during application of method

Which of the following statement about spanning tree is false:


answer: None of the others

Which of the following statement about spanning tree is true:


answer: All of the others (The complexity of Kruskal's algorithm depends on the
complexity of the sorting method applied // The complexity of Kruskal's algorithm
depends on the method used for cycle detection.

Which of the following statements about elementary sorting is true:


answer: None of the others

Which of the following statements about efficient sorting is true:


answer:Mergersort can be made more efficient by replacing recursion with
iteration // insertion sort is applied to small portions of an array to improve
performance
In Insertion Sort, the number of movements and comparisons for a randomly orded
array is closer to the beast case.
answer:False

Which of the following statements about efficient sorting is true:


answer: All of the others (Heap sort starts from the end of array by finding the
largest elements // In heap sort, for the best case the number of calling
moveDown() in the first loop is n/2)

Select correct statements about Radix sort:


answer: bitRadixsort() can be improved by implementing array insted of using
queue // One of techniques radix sort uses is by looking at each number as a string
of bits so that all integers are euqal length

In insertion sort algorithm, the number of times variable tmp is loaded and
unloaded in the outer for loop is not:
answer: None of the other

Which of the following statements about Quich sort is true:


answer: Quick sort is recursive in nature // A strategy for selecting a bound is to
choose the element located in the middle of the array

Which of the following statements about efficient sorting is true:


answer: Shell sort is more efficient than insertion sort even if in case there are
only two increments // There is no sequence of increments it optimal

In sertion sort, which case is only one comparison made for each position i:
answer: The data are already in order

Which of the following statements about elementary sorting is true:


answer:Advantage of using insertion sort is that it sorts the array only when is
really necessary

Select correct statements:


answer: The characteristic feature of extendible hashing is the organization of the
index ,which is an expendable table // A reorganization of the file is avoided by
using extendible hashing if the directory overflows.

Which of the following statement about Perfect Hash Functions are true:
answer: In a minimal perfect hash function, wasting time for collision resolution
and wasting space for unused table cells are avoided // The function in FHCD
algorithm is found in three steps: mapping ,ordering and searching

Which of the following statement about Perfect Hash Functions are true:
answer: Cihcelli's method uses an exhaustive search // Cichelli's method is used to
hash relatively small number of reserved

Hash function is function that can transform a particular key (K) (a string, number
or record) into an index in the table used for storing items of the same type as K.
answer: True

Which of the following statement is true:


answer: If hash function transforms different keys into different numbers, it is
called a perfect hash function

Which of the following statement about Open Addressing are false:


answer: In linear probing of the open addressing method, the position in which key
can be stored is found by sequentially searching starting from the begin of
table // Using qadratic probling gives much better results than linear probing and
avoids the problem of cluster buildup

Which of the following statement are true:


answer: Coalesced hashing combine linear probing with chaining // Linked list can
be used in Bucket Addressing

Which of the following statement are false:


answer: In chaining ,searches always fast if using linked list // Self-organizing
linked lists do not improve performance in chaining.

Which of the following statement are false:


answer: The best value of divisor can be any // The folding method ( instead of
division method) is the preferred choice for the hash function if very little is
know about the keys.

Which of the following statement are true:


answer: If there are 32 items and a 64-cel table then there are 8^64 hash functions
// The divsion method depends on division modulo // Good value for m are prime
numbers that are not very close powers of 2

Select correct statements:


answer: In shifting folding method (+ boundary folding) the key is usually divided
into even parts of some fixed size plus some remainder and added // The boundary
folding method is applied to number data.

Select correct statements:


answer: In practice ,the mid-square method is more efficient to the size of table
that is power of 2// The middle part of bit representation of the square of a key
is extracted using a mask and a shift operation

The length of the codeword for a given sysbol mj should not less than the length of
the codeword of a less probable symbol mi; that is,if P(mi)<=P(mj), then
L(mi)<=L(mj) for 1<=i, j<=n
answer: false

Select correct statement about Ziv-Lempei Code.


answer: All of the others (The codeword of Ziv-Lempei Code is a triple // Ziv-
Lempei Code uses buffer of symbols)

Entropy of source M is defined by:


answer: False

Select correct statement about Run-length encoding.


answer: A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs

Select incorrect statements about Huffman Coding:


answer: Huffman tree is only implemented by non-recursive algorithm // Adaptive
Huffman coding uses breath-first left-to-right tree traversal generates a list of
nodes with nonincreasing frequency counter

Select correct statements about Huffman Coding:


answer: David Huffman's algorithm is not useful for sending some specialized
files // Huffman tree can be built top-down

Each codeword corresponds to one or more symbols.


answer: False

Run-length encoding is very efficient for text file in which only blank character
has a tendency to be repeated without using any technique.
answer: flase

///////nay la ly thuyet

A Java program is a sequence of statements that have to be formed in accordance


with the predefined syntax.

A statement is the smallest executable unit in Java.

Compound statements, or blocks, are marked by delimiting them with braces, { and }.

A class is a template in accordance to which objects are created.

Functions defined in a class are called methods.

Variables used in a class are called class scope variables, data fields, or fields.

The combination of data and related operations is called data encapsulation.

An object is an instance of a class, an entity created using a class definition.

An item specified in terms of operations is called an abstract data type.

Subclasses, or derived classes, inherit the fields and methods from their base
class so that they do not have to repeat the same definitions.

Polymorphism is the ability of acquiring many forms.

In many languages, pointer is a technical term for a type of variable; in Java, the
term reference is used instead.

A vector is a data structure with a contiguous block of memory, just like an array.

A linked structure is a collection of nodes storing data and links to other nodes.

A linked list is a data structure composed of nodes, each node holding some
information and a reference to another node in the list.

A singly linked list is a node that has a link only to its successor in this
sequence.

A circular list is when nodes form a ring: The list is finite and each node has a
successor.

A skip list is a variant of the ordered linked list that makes a nonsequential
search possible.

There are four methods for organizing lists: move-to-front method, transpose
method, count method, and ordering method.

Optimal static ordering - all the data are already ordered by the frequency of
their occurrence in the body of data so that the list is used only for searching,
not for inserting new items.

A sparse table refers to a table that is populated sparsely by data and most of its
cells are empty.

Linked lists allow easy insertion and deletion of information because such
operations have a local impact on the list.

The advantage of arrays over linked lists is that they allow random accessing.

A stack is a linear data structure that can be accessed at only one of its ends for
storing and retrieving data.

A stack is called an LIFO structure: last in/first out.

A queue is a waiting line that grows by adding elements to its end and shrinks by
taking elements from its front.

A queue is an FIFO structure: first in/first out.

In queuing theory, various scenarios are analyzed and models are built that use
queues for processing requests or other information in a predetermined sequence
(order).

A priority queue can be assigned to enable a particular process, or event, to be


executed out of sequence without affecting overall system operation.

In priority queues, elements are dequeued according to their priority and their
current #queue position.

Recursive definitions are programming concepts that define themselves

Recursive definitions serve two purposes:

Generating new elements

Testing whether an element belongs to a set

Recursive definitions are frequently used to define functions and sequences of


numbers

Tail recursion is characterized by the use of only one recursive call at the very
end of a method implementation.

Backtracking is a technique for returning to a given position (e.g., entry point)


after trying other avenues that are unsuccessful in solving a particular problem.

The process of translating one executable statement at a time and immediately


executing it is called interpretation.

A tree is a data type that consists of nodes and arcs.

The root is a node that has no parent; it can have only child nodes.

Each node has to be reachable from the root through a unique sequence of arcs,
called a path.

An orderly tree is where all elements are stored according to some predetermined
criterion of ordering.

A binary tree is a tree whose nodes have two children (possibly empty), and each
child is designated as either a left child or a right child.

A decision tree is a binary tree in which all nodes have either zero or two
nonempty children.
Tree traversal is the process of visiting each node in the tree exactly one time.

Threads are references to the predecessor and successor of the node according to an
inorder traversal.

An AVL tree is one in which the height of the left and right subtrees of every node
differ by at most one.

A modification of the move-to-the-root strategy #is called splaying.

Polish notation is a special notation for propositional logic that eliminates all
parentheses from formulas.

A graph is a collection of vertices (or nodes) and the connections between them

A multigraph is a graph in which two vertices can be joined by multiple edges

A pseudograph is a multigraph with the condition vi ≠ vj removed, which allows for


loops to occur

The sets used to solve the union-find problem are implemented with circular linked
lists

A spanning tree is an algorithm that guarantees generating a tree (or a forest, a


set of trees) that includes or spans over all vertices of the original graph

An undirected graph is called connected when there is a path between any two
vertices of the graph

A network is a digraph with one vertex s, called the source, with no incoming
edges, and one vertex t, called the sink, with no outgoing edges

Maximum matching is a matching that contains a maximum number of edges so that the
number of unmatched vertices (that is, vertices not incident with edges in M) is
minimal

A Hamiltonian cycle in a graph is a cycle that passes through all the vertices of
the graph

Sequential coloring establishes the sequence of vertices and a sequence of colors


before coloring them, and then color the next vertex with the lowest number
possible

Sorting is a two step process: Choose the criteria that will be used to order data
and determine how to put a set of data in order using that criterion

An insertion sort starts by considering the two first elements of the array data,
which are #data[0] and data[1]

Selection sort is an attempt to localize the exchanges of array elements by finding


a misplaced element first and putting it in its final place

A decision tree is when nonterminal nodes of the tree contain conditions or queries
for labels, and the leaves have all possible orderings of the array to which the
algorithm is applied

Shell sort divides the original array into subarrays, sorting them separately, and
then dividing them again to sort the new subarrays until the whole array is sorted
Mergesort makes partitioning as simple as possible and concentrates on merging
sorted halves of an array into one sorted array

Radix sort is a a technique to sort integers by proceeding right to left

Java provides two sets of versions of sorting methods: one for arrays and one for
lists

Hash functions include the division, folding, #mid-square, extraction and radix
#transformation methods

Collision resolution includes the open addressing, chaining, and bucket addressing
methods

Cichelli’s method is an algorithm to construct a minimal perfect hash function

The FHCD algorithm searches for a minimal perfect hash function of the form (modulo
TSize), where g is the function to be determined by the algorithm

In expandable hashing and dynamic hashing, a binary tree is used as an index of


buckets

In extendible hashing, a directory of records is kept in a table

A hash map is a collection of singly linked lists (buckets); that is, chaining is
used as a collision resolution technique

HashSet is another implementation of a set #(an object that stores unique elements)

A Hashtable is roughly equivalent to a HashMap except that it is synchronized and


does not permit null values with methods to operate on hash tables

To compare the efficiency of different data compression methods when applied to the
same data, the same measure is used; this measure is the compression rate

The construction of an optimal code was developed by David Huffman, who utilized a
#tree structure in this construction: a binary tree for a binary code

In adaptive Huffman coding, the Huffman tree includes a counter for each symbol,
and the counter is updated every time a corresponding input symbol is being coded

A run is defined as a sequence of identical characters

Run-length encoding is useful when applied to files that are almost guaranteed to
have many runs of at least four characters, such as relational databases

Null suppression compresses only runs of blanks and eliminates the need to identify
the character being compressed

The Ziv-Lempel code is an example of a universal data compression code

/////////////////////////////////SE0570 ////////////
- Static methods and variables are associated with the class itself and are called
instance methods and instance
Answer:variables - The combination of data and related operations is called
information hiding principle

2. Which of the following keywords are access modifier:


Answer:- Protected - Private

3. Select correct statements:


Answer:- Subclasses or derived classes inherit the fields and methods from their
base class - An abstract data type can be part of a program in the form of an
interface

4. Which of the following statements are true:


Answer:- AN object can be saved in a life if its class type is stated to implement
in the Serializable interface - If the vector’s capacity is greater than its size,
then a new element can be inserted at the end of the vector
immediately

5. Which of sentences about singly linked list are true:


Answer:- 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

6. Select correct statement(s) about Doubly Linked List:


Answer:- The node which is deleted from the list will be claimed by the garbage
collection - Deleting a node at the end of the list takes constant time O(1) -
Processing for adding a node to the end of list includes six steps

7. Select incorrect statements about skip list:


Answer:- None of the others: + In a skip list of n nodes, for each k and I such
that and , the node in position
2k-1
.i points to the node in position 2k-1
.(i+1)
+ The number of reference fields indicates the level of each node, and the number
of levels is maxLevel =

8. Select incorrect statement about skip list:


Answer:- The search time is O(lgn) in the worst case - In 20-element skip lists,
the node in position 3 points to the node in position 7

9. Select false statement:


Answer:- In the array list, poping is executed in O(lgn) to the worst case

10. Select true statements about stack:


Answer:- The Java implementation of the stack is potentially fatal - Stack can be
implemented by linked list

11. Which of the following methods of queue are true:


Answer:- isEmpty() – Check to see if the queue is empty - enqueue(el) – Put the
element el at the end of the queue - firstEl() – Return the first element in the
queue without removing it

12. Which of the following can be executed in constant time O(n)


Answer:- When deleting a node of a singly linked list in the average case - When
deleting a node of a singly linked list in the worst case

13. Which of the following statements are true:


Answer:- The recursive version increases program readability, improves self-
documentation and simplifies coding

14. When converting a method from a recursive version into an iterative version,
Answer:- The brevity of program formulation lost. However, the brevity may not be
an issue in Java - Program clarity can be diminished

15. Recursive definitions on most computers are eventually implemented using a run-
time stack and this
implementation is done by the operating system.
Answer:- True

16. In all cases, nonrecursive implementation is faster recursive implementation.


Answer:- False

17. Which of the following concepts of tree are true:


Answer:- The height of a nonempty tree is the maximum level of a node in the tree
- The level of a node is the length of the path from the root to the node plus 1 -
The level of a node must be between 1 and height of the tree

18. Select correct statement:


Answer:- For a binary tree with n nodes, there are n! different traversals - The
complexity of searching depends on the shape of the tree and the position of the
node in the tree - Breath-First traversal is implemented using queue

19. Select incorrect statement


Answer:- Depth-first traversal can not be implemented if not using stack - A
recursive implementation of preorder tree traversal uses stack explicitly - There
are six possible ordered depth-first traversal

20. Which of the following statements are true:


Answer:- Polish notation eliminates all parentheses from formulas - Using Polish
notation, all expressions have to be broken down unambiguous into separate
operations and put into their proper order. - Expression trees do not use
parentheses

21. Which of the following sentences are true:


Answer:- The complexity of DFS is O(|V| + |E|), where |V| is number of vertices
and |E| is number of edges - To prevent loop from happen in an algorithm for
traversing a graph, each visited vertex can be marked

22. Which of the following statements about finding the shortest path are true:
Answer:- For label-correcting method, information of any label can be changed
during application of method - The complexity of Dijkstra’s algorithm is O(|V| -
The complexity of Ford’s algorithm is O(|V||E|) for any graph

23. Which of the following statement about spanning tree is false:


Answer:- None of the others: + The complexity of Kruskal’s algorithm depends on
the complexity of the sorting method applied
+ The complexity of Kruskal’s algorithm depends on the method used cycle detection

24. Which of the following statements about graph coloring is true:


Answer:- The complexity of sequential Coloring algorithm is O(|V|2- Sequential
Coloring algorithm establishes the sequence of vertices and a sequence of color
before coloring
them

25. Which of the following statements about efficient sorting is false:


Answer:- Shell sort divides the original array into physical subarrays, sorting
them separately, then merging and dividing
them again to sort the new subarray until the whole array is sorted
26. Which of the following statements about efficient sorting is false:
Answer:- The worst case is when the bound divides an array into subarrays of
approximately length - The best case of quick sort happens when bound is the
largest (the smallest) element of the array

27. Which of the following statements is true:


Answer:- All of the others: + All the sorting methods implemented in Java is
applied to any basic data type + For objects comparison, a comparison criterion
must be implemented by user for all claases

28. In Insertion Sort, the number of movements and comparison for a randomly
ordered array is closer to the best
case.
Answer:- False

29. Which of the following statement about Open Addressing are false:
Answer:- In linear probing of the open addressing method, the position in which
key can be stored is found by sequentially searching starting from the begin of
table - Using quadratic probing gives much better results than linear probing and
avoids the problem of cluster buildup

30. Which of the following statement are true:


Answer:- Linked list can be used in Bucket Addressing - Self-organizing linked
lists can be used improve performance in chaining - Coalesced hashing combines
linear probing with chaining

31. Which of the following statement about Perfect Hash Functions are true:
Answer:- Cichelli’s method uses an exhaustive search - Cichelli’s method is used
to hash relatively small number of reserved words

32. Select correct statements:


Answer:- A reorganization of the file is avoided by using extendible hashing if
the directory overflows - The characteristic feature of extendible hashing is the
organization of the index, which is expandable table

33. Which of the following data structure can be implemented Huffman Coding
Answer:- Singly linked list - Priority queue - Doubly linked list

34. Select incorrect statements about Huffman Coding:


Answer:- Huffman tree is only implemented by non-recursive algorithm - David
Huffman’s algorithm may not be useful for sending some specialized files -
Adaptive Huffman coding uses breath-first left-to-right tree traversal generates a
list of nodes with
nonincreasing frequency counter

35. Select correct statement about Run-length encoding.


Answer:- A serious drawback of run-length encoding is that it relies entirely on
the occurrences of runs

36. Identify whether below code has error or not:


Abstract class AC1{
Int AC1f1() {return 0;}
Void AC1f2(int i) {return;}
Int AC1f3();
}
Answer:- Compile error

37. Identify whether below code has error or not:


Interface I2{
Double I2f1(); Void I2f1();
Double I2f3() {return 10;}
Int n = 10;
Private double m;
}
Answer:- 3 compile errors

38. Class C{
Void process1(char ch)(….)
Void process2(char ch)(….)
Void process3(char ch)(….)
}

Class ExtC extends C{


Void process1(int n)()
Void process2(char ch)()
Void process4(int n)()
}

ExtC object1 = new ExtC();


C object2 = new ExtC(), object3 = new ExtC();
Which of the following statements are true
Answer:- Object1.process2(‘N’) calls process2 of class ExtC - Object2.process1(1)
does not issue compile error - Object2.process3(‘N’) call process3 of class C

39. For (int I = first, j; I <= last; i++) {


Int tmp = data[i];
For (j=I; j>0 && tmp<data[j-1]; j--)
Data[j] = data[j-1];
Data[j] = tmp;
}
Identify which algorithm the above code implements
Answer:- Insertion Sort

40. Public <T extends Comparable<? Super T>> void XYZsort (T[] data)
{
For (int i=0 ; i<[Link]-1 ; i++)
For (int j=[Link]-1; j>I; --j)
If (data[j].compareTo(data[j-1])<0)
Swap(data,j,j-1);
}
Identify which algorithm the above code implements
Answer:- Bubble sort

41. Public static void reverse()


{
Char ch=getChar();
If(ch!=’\n’)
{
Reverse();
[Link](ch);
}
}
Assume that getChar() only reads one character of the input string every it is
called. What output if reverse is
executed and input string is “ABCDEF\n” 42. Void nontail(int i)
{
If(i>0)
{
Nontail(i+1);
[Link](i+””);
Nontail(i+1);
}
}
What is output if nontail is called with i=3
Answer:- Runtime error is issued

43. Void nontail(int i)


{
If(i>0)
{
Nontail(i-2);
[Link](i+””);
Nontail(i-2);
}
}
What is output if nontail is called with i=5
Answer:- 1315131

44. Protected void preorderVRL(BSTNode p) {


If (p!=null {
Visit(p);
preorderVRL([Link]);
preorderVRL([Link]);
}
}
What is output if preorderVRL is executed and structure of Binary Tree is the
following image:

Answer:- 2 6 3 15 8 10 1 11 12

45.

What is output if breadthFirst is executed and structure of Binary Tree is the


following image:

Answer:- 2 6 8 3 15 10 1 11 12

46.

Assume that sort is executed with array {9,4,2,5,8,10,3}. What is output after
iteration i=5 of the outer for loop
completed
Answer:- {2,4,5,8,9,10,3}

47.

Assume that sort is executed with array {19,14,6,5,18,10,15}. What is output after
iteration i=5 of the outer for loo
completed
Answer:- {19,18,14,6,5,10,15}

48. Let deleteFromHead be method used to delete the first element of generic singly
linked list class: Identify whether above code has error or not:
Answer:- There may be runtime error in some case

49.
Identify whether the code of pop method has error or not:
Answer:- There may be runtime error in some case

50.

Assume that getChar() only reads one character of the input string every it is
called. What output if reverse is executed and input string is “ABCDEF\n”
Answer:- \nFEDCBA

51. Which of the following about queue are true:


Answer:- A queue is an FIFO structure

52. Which of the following statement of queue are true


Answer:- All of the others: + Using array for queue implementation may not be the
best choice + A natural queue implementation is a linked list

53. Select false statement:


Answer:- In the array list, poping is executed in time O(n) to the worst case

54. In the doubly linked list implementation, enqueuing can be executed in time
O(n)
Answer:- False

55. Which of the following statements about heap are false:


Answer:- Heaps represented by array can be travered easily in depth-first - A
heap can be defined as an array heap of length n in which: - Heaps can be
implemented by arrays

56. Consider below recursive define about tree:


1. An empty structure is an empty tree. Answer:- True

57. Which of the following statements about elementary sorting is true:


Answer:- None of the others + In selection sort, for every iteration j of the
inner for loop, there are n-i+1 comparisons + The worst case of selection sort has
n-1 swap calls

58. Which of the following statements about efficient sorting is true:


Answer:- Insertion sort is applied to small portions of an array to improve
performance - Mergesort can be made more efficient by replacing recursion with
iteration

59. Select correct statements about Radix sort:


Answer:- bitRadixsort() can be improved by implementing array instead of using
queue - One of techniques radix sort uses is by looking at each number as a string
os bits so that all integers are of
equal length.

60. Which of the following statement is true:


Answer:- If hash function transforms different keys into different numbers, it is
called a perfect hash function

61. Select correct statements:


Answer:- In shift folding method, the key is usually divided into even parts of
some fixed size plus some remainder and added - The boundary folding method is
applied to number data

62. Which of the following statements are false:


Answer:- The best value of divisor can be any - The folding method is the
preferred choice for the hash function if very little is known about the keys
63. Each codeword corresponds to one or more symbols
Answer:- False

64. Run-length encoding is very efficient for text file in which only blank
character has a tendency to be repeated without using any technique
Answer:- True

65. Select correct statement about Ziv-Lempel Code


Answer:- All of the others: + Ziv-Lempel Code uses buffer of symbols + The
codeword of Ziv-Lempel Code is a triple

66. The length of the codeword for a given symbol mj should not less than the
length of the codeword of a less probable symbol m; that is, if then for
Answer:- False

67. In the array implementation, enqueuing can be executed in constant time O(1)
Answer:- True

68. Which of the following about stack are true:


Answer:- The most top element is the latest added element - Operations of stack
based on Last in First out structure

69. In the array implementation, dequeuing can be executed in O(n)


Answer:- False

70. Which of the following about queue are true:


Answer:- A queue is an FIFO structure

71. Select incorrect statement:


Answer:- The anchor or ground case allows for the construction of new objects out
of basic elements or objects that
have already been constructed

72.
What is the value of h(1):
Answer:- 14

73.
What is the value of A(3,1):
Answer:- 15

74. In all binary trees, there are 2i nodes at level i.


Answer:- False

75. Which of the following methods are used to traverse a tree without using any
stack or threads:
Answer:- Traversal through tree Transformation

76. Which operation is used in DSW Algorithm:


Answer:- Rotation

77. Which of the following are false:


Answer:- A path from v1 to vn is a sequence of edges (v1v2), edges (v2v3)…
edges(vn-1vn) and no edge is represented - A circuit is a cycle in which all
vertices must be different

78. Which graph representation is best?


Answer:- It depends on the problem
79. Which of the following statements about finding shortest path are true:
Answer:- For label-setting methods, in each pass through the vertices still to be
processed, one vertex is set to a value that remains unchanged to the end of the
execution - The methods solving the shortest path problem are divided into
classes; label-setting and label-correcting

80. Which of the following statements about graph coloring is true:


Answer:- Sequential coloring algorithm establishes the sequence of vertices and a
sequence of color before coloring them. - The complexity of sequential Coloring
algorithm is O(|V|
2
)

81. Which of the following statement about finding the shortest path is false:
Answer:- The complexity of WFI’s algorithm is |V|
3
that is good efficiency for any graph

82. In insertion sort algorithm, the number of times variables tmp is loaded and
unloaded in the outer for loop is not:
Answer:- All of the others: + Necessary in the worst case + Redundant in the best
case

83. Which of the following statements about Quick sort is true:


Answer:- Quick sort is recursive in nature - A strategy for selecting a bound is
to choose the element located in the middle of the array

84. Skip list helps avoiding sequential search


Answer:- True 85. Select correct statement(s): - A singly linked list is a node
that has a link only to its successor in this sequence - Inserting a new node at
the end of the singly linked list without tail field requires steps with n is the
number of
nodes

86. Which of the following operations are implemented in the LinkedList class
belongs to the [Link] package:
Answer:- All of the others: + Return the copy of the linked list without cloning
its elements + Add all the elements from one collection to the beginning of the
linked list

87. Let L1 (having n nodes) and L2 (having m nodes) be two linked list which are
managed by the heads and tails. The complexity of direct concatenating L2 to L1 is

Answer:- O(1)

88. Which of the following operations are not implemented in the ArrayList class
belongs to the [Link] package:
Answer:- None of the others: + Remove the object at given position + Copy all
objects from the array list to a newly created array

89. Elements of a linked list must be consecutive memory cells


Answer:- False

90. If an algorithm is constantly accessing only some elements such as the first,
the second, the last and the like, and if changing the structure is very important
to the algorithm then solution is using:
Answer:- Linked list
91. The advantages of array over linked lists is that they allow random accessing
Answer:- True

92. Which of the following operations are implemented in the ArrayList class
belongs to the [Link] package:
Answer:- All of the others: + Update one element in any position in the ArrayList
+ Add one element to any position in the ArrayList + Retrieve one element from any
position in the ArrayList

93. Linked lists allow easy insertion and deletion of information because such
operations have a local impact on the list
Answer:- True

94. In the doubly linked list implementation, dequeuing can be executed in constant
time O(1)
Answer:- True

95. Which of the following methods of queue are true:


Answer:- Enqueue(el) – Put the element el at the end of the queue - Dequeue() –
Take the first element from the queue

96. Consider the following recursive function, assuming n is even:

What is the value of h(20):


Answer:- 11

97. Which of the following statements are false:


Answer:- An activation record still exists after a method owning it ends - An
activation record contains code of method owning it

98. Which of the following statements about graph coloring is true: 99. Most of
the label-setting and label-correcting are used to find the shortest paths from one
vertex to all other
vertices
Answer:- False

100. Which of the following statements about Perfect Hash Functions are true:
Answer:- In a minimal perfect hash function, wasting time for collision resolution
and wasting space for unused table cells are avoided - The functioning in HCD
algorithm is found in three steps: mapping, ordering and searching

101. Hash function is function that can transform a particular key (K) (a string,
number or record) into an index in the table used for storing items of the same
type as K.
Answer:- True

102. Entropy of source M is defined by:


Answer:- false

103. Which of the following operations are not implemented in the ArrayList class
belongs to the [Link] package:
Answer:- Return the sub list of the array list containing copy of elements in the
array list

104. Insertion sort which case is only one comparison made for each position i:
Answer:- The data are already in order

105. What are number of additions and number of calls to find Fib(8) using
recursive definition
Answer:- 33 and 67

106. Which of the following statements about Quick sort is true:


Answer:- A strategy for selecting a bound is to choose the element located in the
middle of the array - Quick sort is recursive in nature

107. Which of the following statements about elementary sorting is true


Answer:- Advantage of using insertion ort that it sorts the array only when is
really necessary

108. Select correct statements:


Answer:- The middle part of the bit representation of the square of a key is
extracted using a mask and a shift operation- In practice, the mid-square method
is more efficient to the size of table that is a power of 2

Which of the following keywords are access modifier:


answer: Protected + Private

Select correct statements:


answer:[Link] or derived classes inherit the fields and methods from their
base class [Link] abstract data type can be part of a program in the form of an
interface

Which of the following statements are true:


answer:[Link] object can be saved in a life if its class type is stated to implement
in the Serializable interface [Link] the vector’s capacity is greater than its size,
then a new element can be inserted at the end of the vector
immediately

Which of sentences about singly linked list are true:


answer:[Link] a node at the beginning of the list takes constant time O(1)
[Link] the average, delete operation executes O(n) steps [Link] is no immediate
access to the predecessor of any node in list

Select correct statements about Doubly Linked List:


answer:[Link] node which is deleted from the list will be claimed by the garbage
collection [Link] a node at the end of the list takes constant time O(1)
[Link] for adding a node to the end of list includes six steps

Select incorrect statements about skip list:


answer:none of the others

Select incorrect statement about skip list:


answer:[Link] search time is O(lgn) in the worst case [Link] 20-element skip lists,
the node in position 3 points to the node in position 7

Select false statement:


answer:In the array list, poping is executed in O(lgn) to the worst case

Select true statements about stack:


answer:[Link] Java implementation of the stack is potentially fatal [Link] can be
implemented by linked list

Which of the following methods of queue are true:


answer:[Link]() - Check to see if the queue is empty [Link](el) - Put the
element el at the end of the queue [Link]() - Return the first element in the
queue without removing it
Which of the following can be executed in constant time O(n)
answer:[Link] deleting a node of a singly linked list in the average case [Link]
deleting a node of a singly linked list in the worst case

Which of the following statements are true:


answer:The recursive version increases program readability, improves self-
documentation and simplifies coding

When converting a method from a recursive version into an iterative version:


answer:[Link] brevity of program formulation lost. However, the brevity may not be
an issue in Java [Link] clarity can be diminished

Recursive definitions on most computers are eventually implemented using a run-time


stack and this implementation is done by the operating system.
answer:True

In all cases, nonrecursive implementation is faster recursive implementation.


answer:False

Which of the following concepts of tree are true:


answer:[Link] height of a nonempty tree is the maximum level of a node in the tree
[Link] level of a node is the length of the path from the root to the node plus 1
[Link] level of a node must be between 1 and height of the tree

Select correct statement:


answer:[Link] a binary tree with n nodes, there are n! different traversals [Link]
complexity of searching depends on the shape of the tree and the position of the
node in the tree [Link]-First traversal is implemented using queue

Select incorrect statement:


answer:[Link]-first traversal can not be implemented if not using stack 2.A
recursive implementation of preorder tree traversal uses stack explicitly [Link]
are six possible ordered depth-first traversal

Which of the following statements are true:


answer:[Link] notation eliminates all parentheses from formulas [Link] Polish
notation, all expressions have to be broken down unambiguous into separate
operations and p into their proper order. [Link] trees do not use
parentheses

Which of the following sentences are true:


answer:[Link] complexity of DFS is O(|V| + |E|), where |V| is number of vertices and
|E| is number of edges [Link] prevent loop from happen in an algorithm for
traversing a graph, each visited vertex can be marked

Which of the following statements about finding the shortest path are true:
answer:[Link] label-correcting method, information of any label can be changed
during application of method [Link] complexity of Dijkstra’s algorithm is O(|V|2)
[Link] complexity of Ford’s algorithm is O(|V||E|) for any graph

Which of the following statement about spanning tree is false:


answer:none of the others

Which of the following statements about graph coloring is true:


answer:[Link] complexity of sequential Coloring algorithm is O(|V|2) [Link]
Coloring algorithm establishes the sequence of vertices and a sequence of color
before coloring them

Which of the following statements about efficient sorting is false:


answer:Shell sort divides the original array into physical subarrays, sorting them
separately, then merging and dividi them again to sort the new subarray until the
whole array is sorted

Which of the following statements about efficient sorting is false:


answer:[Link] worst case is when the bound divides an array into subarrays of
approximately length n/2 [Link] best case of quick sort happens when bound is the
largest (the smallest) element of the array

Which of the following statements is true:


answer:All of the others

In Insertion Sort, the number of movements and comparison for a randomly ordered
array is closer to the best case.
answer:False

Which of the following statement about Open Addressing are false:


answer:[Link] linear probing of the open addressing method, the position in which key
can be stored is found by sequentially searching starting from the begin of table
[Link] quadratic probing gives much better results than linear probing and avoids
the problem

Which of the following statement are true:


answer:[Link] list can be used in Bucket Addressing [Link]-organizing linked
lists can be used improve performance in chaining [Link] hashing combines
linear probing with chaining

Which of the following statement about Perfect Hash Functions are true:
answer:[Link]’s method uses an exhaustive search [Link]’s method is used
to hash relatively small number of reserved words

Select correct statements:


answer:1.A reorganization of the file is avoided by using extendible hashing if the
directory overflows [Link] characteristic feature of extendible hashing is the
organization of the index, which is expandable table

Which of the following data structure can be implemented Huffman Coding


answer:[Link] linked list [Link] queue [Link] linked list

Select incorrect statements about Huffman Coding:


answer:[Link] tree is only implemented by non-recursive algorithm [Link]
Huffman’s algorithm may not be useful for sending some specialized files
[Link] Huffman coding uses breath-first left-to-right tree traversal generates
a list of nodes with nonincreasing frequency counter

Select correct statement about Run-length encoding.


answer:A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs

Identify whether below code has error or not:


answer:Abstract class AC1{ Int AC1f1() {return 0;} Void AC1f2(int i) {return;} Int
AC1f3(); } Compile error

Identify whether below code has error or not:


answer:Interface I2{ Void I2f1(); Double I2f3() {return 10;} Int n = 10; Private
double m;}-3 compile errors

Which of the following statements are true


answer:1.Object1.process2(‘N’) calls process2 of class ExtC 2.Object2.process1(1)
does not issue compile error 3.Object2.process3(‘N’) call process3 of class C

Identify which algorithm the above code implements


answer:For (int I = first, j; I <= last; i++) { - Insertion Sort

Identify which algorithm the above code implements


answer:Public <T extends Comparable<? Super T>> void XYZsort (T[] data) - Bubble
sort

Assume that getChar() only reads one character of the input string every it is
called. What output if reverse is executed and input string is “ABCDEF\n”
answer:FEDCBA

What is output if nontail is called with i=3


answer:Runtime error is issued

What is output if nontail is called with i=5


answer:1315131

What is output if preorderVRL is executed and structure of Binary Tree is the


following image:
answer:2 6 3 15 8 10 1 11 12

What is output if breadthFirst is executed and structure of Binary Tree is the


following image:
answer:2 6 8 3 15 10 1 11 12

Assume that sort is executed with array {9,4,2,5,8,10,3}. What is output after
iteration i=5 of the outer for loop completed
answer:{2,4,5,8,9,10,3}

Assume that sort is executed with array {19,14,6,5,18,10,15}. What is output after
iteration i=5 of the outer for lo completed
answer:19,18,14,6,5,10,15

Let deleteFromHead be method used to delete the first element of generic singly
linked list class:
answer:There may be runtime error in some case

Identify whether the code of pop method has error or not:


answer:There may be runtime error in some case

Assume that getChar() only reads one character of the input string every it is
called. What output if reverse is executed and input string is “ABCDEF\n”
answer:\nFEDCBA

Which of the following about queue are true:


answer:A queue is an FIFO structure

Which of the following statement of queue are true


answer:All of the others

Select false statement:


answer:In the array list, poping is executed in time O(n) to the worst case

In the doubly linked list implementation, enqueuing can be executed in time O(n)
answer:False

Which of the following statements about heap are false:


answer:[Link] represented by array can be travered easily in depth-first 2.A heap
can be defined as an array heap of length n in which: [Link] can be implemented
by arrays

Consider below recursive define about tree: [Link] empty structure is an empty tree.
answer:True

Which of the following statements about elementary sorting is true:


answer:None of the others

Which of the following statements about efficient sorting is true:


answer:[Link]() can be improved by implementing array instead of using
queue [Link] of techniques radix sort uses is by looking at each number as a string
os bits so that all integers are of equal length.

Which of the following statement is true:


answer:If hash function transforms different keys into different numbers, it is
called a perfect hash function

Select correct statements:


answer:[Link] shift folding method, the key is usually divided into even parts of
some fixed size plus some remainder an added [Link] boundary folding method is
applied to number data

Which of the following statements are false:


answer:[Link] best value of divisor can be any [Link] folding method is the
preferred choice for the hash function if very little is known about the keys

Each codeword corresponds to one or more symbols


answer:False

Run-length encoding is very efficient for text file in which only blank character
has a tendency to be repeated without using any technique
answer:True

Select correct statement about Ziv-Lempel Code


answer:All of the others

The length of the codeword for a given symbol mj should not less than the length of
the codeword of a less probable symbol m; that is,
answer:False

In the array implementation, enqueuing can be executed in constant time O(1)


answer:True

Which of the following about stack are true:


answer:[Link] most top element is the latest added element [Link] of stack
based on Last in First out structure

In the array implementation, dequeuing can be executed in O(n)


answer:False

Which of the following about queue are true:


answer:A queue is an FIFO structure

Select incorrect statement:


answer:The anchor or ground case allows for the construction of new objects out of
basic elements or objects that have already been constructed
What is the value of h(1):
answer:14

What is the value of A(3,1):


answer:15

In all binary trees, there are 2i nodes at level i.


answer:False

Which of the following methods are used to traverse a tree without using any stack
or threads:
answer:Traversal through tree Transformation

Which operation is used in DSW Algorithm:


answer:Rotation

Which of the following are false:


answer:1.A path from v1 to vn is a sequence of edges (v1v2), edges (v2v3)…
edges(vn-1vn) and no edge is represented 2.A circuit is a cycle in which all
vertices must be different

Which graph representation is best?


answer:It depends on the problem

Which of the following statements about finding shortest path are true:
answer:[Link] label-setting methods, in each pass through the vertices still to be
processed, one vertex is set to a value that remains unchanged to the end of the
execution [Link] methods solving the shortest path problem are divided into
classes; label-setting and label-correcting

Which of the following statements about graph coloring is true:


answer:[Link] coloring algorithm establishes the sequence of vertices and a
sequence of color before coloring them. [Link] complexity of sequential Coloring
algorithm is O(|V|2)

Which of the following statement about finding the shortest path is false:
answer:The complexity of WFI’s algorithm is |V|3 that is good efficiency for any
graph

In insertion sort algorithm, the number of times variables tmp is loaded and
unloaded in the outer for loop is not:
answer:All of the others

Which of the following statements about Quick sort is true:


answer:[Link] sort is recursive in nature 2.A strategy for selecting a bound is
to choose the element located in the middle of the array

Select correct statement(s):


answer:1.A singly linked list is a node that has a link only to its successor in
this sequence [Link] a new node at the end of the singly linked list without
tail field requires steps with n is the number o nodes

Which of the following operations are implemented in the LinkedList class belongs
to the [Link] package:
answer:All of the others

Let L1 (having n nodes) and L2 (having m nodes) be two linked list which are
managed by the heads and tails. complexity of direct concatenating L2 to L1 is …
answer:O(1)
Which of the following operations are not implemented in the ArrayList class
belongs to the [Link] package:
answer:None of the others

Elements of a linked list must be consecutive memory cells


answer:False

If an algorithm is constantly accessing only some elements such as the first, the
second, the last and the like, a if changing the structure is very important to the
algorithm then solution is using:
answer:Linked list

The advantages of array over linked lists is that they allow random accessing
answer:True

Which of the following operations are implemented in the ArrayList class belongs to
the [Link] package:
answer:All of the others

Linked lists allow easy insertion and deletion of information because such
operations have a local impact on the
answer:True

In the doubly linked list implementation, dequeuing can be executed in constant


time O(1)
answer:True

Which of the following methods of queue are true:


answer:[Link](el) - Put the element el at the end of the queue [Link]() -
Take the first element from the queue

What is the value of h(20):


answer:11

Which of the following statements are false:


answer:[Link] activation record still exists after a method owning it ends [Link]
activation record contains code of method owning it

Most of the label-setting and label-correcting are used to find the shortest paths
from one vertex to all other vertices
answer:False

Which of the following statements about Perfect Hash Functions are true:
answer:[Link] a minimal perfect hash function, wasting time for collision resolution
and wasting space for unused table cells are avoided [Link] functioning in HCD
algorithm is found in three steps: mapping, ordering and searching

Hash function is function that can transform a particular key (K) (a string, number
or record) into an inde the table used for storing items of the same type as K.
answer:True

Entropy of source M is defined by:


answer:False

Which of the following operations are not implemented in the ArrayList class
belongs to the [Link] package:
answer:Return the sub list of the array list containing copy of elements in the
array list
Insertion sort which case is only one comparison made for each position i:
answer:The data are already in order

What are number of additions and number of calls to find Fib(8) using recursive
definition
answer:33 and 67

Which of the following statements about Quick sort is true:


answer:1.A strategy for selecting a bound is to choose the element located in the
middle of the array [Link] sort is recursive in nature

Which of the following statements about elementary sorting is true


answer:Advantage of using insertion ort that it sorts the array only when is really
necessary

Select correct statements:


answer:[Link] middle part of the bit representation of the square of a key is
extracted using a mask and a shift operation [Link] practice, the mid-square method
is more efficient to the size of table that is a power of 2
1- Select correct statement about Run-length encoding.
Answer: A serious drawback of run-length encoding
2. ... will visit nodes of a tree starting from the highest (or lowest) level and
moving down (or up) level by level and at a level, it visits nodes from left to
right(or from right to left).
Answer: Breath-First Traversal
Select correct statement.
Answer: The keyword implements is used to specify that a class inherits from an
interface.
The operation for adding an entry to a stack is traditionally called:
Answer: push
2. Which of the following keywords are access modifier:
Answer: Protected, Private
Select correct statements:
Answer:- Subclasses or derived classes inherit the fields... , An abstract data
type can be part of a program in the form of an interface.
4. Which of the following statements are true:
Answer:- AN object can be saved in a life if its class type is stated, If the
vector’s capacity is greater than its size, then a new elem
5. Which of sentences about singly linked list are true:
Answer:- Deleting a node at the beginning of th ...time O(1) - On the average,
delete operatio... O(n) steps, There is no immediate access to the predecessor of
any node in list
6. Select correct statement(s) about Doubly Linked List:
Answer: - The node which is deleted from the list will ... e garbage collection,
Deleting a node at the end of...ant time O(1), Processing for adding a node to the
end of list includes six steps
8. Select incorrect statement about skip list:
Answer:- The search time is O(lgn) in the worst case , In 20-element skip lists,
the node in position 3 points to the
9. Select false statement:
Answer: - In the array list, poping is executed in O(lgn) to the worst case
10. Select true statements about stack:
Answer: - The Java implementation of the stack is potenti, Stack can be
implemented by linked list
11. Which of the following methods of queue are true:
Answer: isEmpty() – Check empty, enqueue(el) – Put at the end of the, firstEl() –
Return the first without removing it
12. Which of the following can be executed in constant time O(n)
Answer: - When deleting a node of a singly linked list in the average case , in
the worst case
13. Which of the following statements are true:
Answer: - The recursive version increases program readability, improves self-
documentation and simplifies coding
14. When converting a method from a recursive version into an iterative version
Answer: The brevity of program formulation lost. However, the brevity may not be an
issue in Java , Program clarity can be diminished
15. Recursive definitions on most computers are eventually implemented using a run-
time stack and this implementation is done by the operating system.
Answer: True
16. In all cases, nonrecursive implementation is faster recursive implementation.
Answer: False
17. Which of the following concepts of tree are true:
Answer: The height of a nonempty tree is the maximum level of node ,The level of a
node is the length of the path from the root to the node plus 1,The level of a node
must be between 1 and height of the tree
18. Select correct statement:
Answer: For a binary tree with n nodes, there are n! different traversals, The
complexity of searching depends on the shape of the tree and the,Breath-First
traversal
Select incorrect statement
Answer:Depth-first traversal can not be implemented if ,A recursive implementation
of preorder tree trav,There are six possible ordered depth-first trave
20. Which of the following statements are true:
Answer:Polish notation eliminates all parentheses from formu, Using Polish
notation, all expressions have to be brok,Expression trees do not use
21. Which of the following sentences are true:
Answer: The complexity of DFS is O(|V| + |E|), where |V| is number of ve, To
prevent loop from happen in an algorithm for traversing a gra
22. Which of the following statements about finding the shortest path are true:
Answer:For label-correcting method, information of any ,The complexity of
Dijkstra’s algorithm is O(|V|2) ,The complexity of Ford’s algorithm is O(|V||E|) fo
23. Which of the following statement about spanning tree is false:
Answer: None of the others
24. Which of the following statements about graph coloring is true:
Answer: The complexity of sequential Coloring algorithm is O(|V|2) ,Sequential
Coloring algorithm establishes the sequence of
25. Which of the following statements about efficient sorting is false:
Answer:Shell sort divides the original array into physical subarrays, s
26. Which of the following statements about efficient sorting is false:
Answer:The worst case is when the bound divides an array ,The best case of quick
sort happens when bound is
27. Which of the following statements is true:
Answer: All of the others: + All the sorting methods implemen
In Insertion Sort, the number of movements and comparison for a randomly ordered
array is closer to the best case.
Answer: False
Which of the following statement about Open Addressing are false:
Answer: In linear probing of the open addressing method, the position in which
key,Using quadratic probing gives much better results than line
30. Which of the following statement are true:
Answer: Linked list can be used in Bucket Addressing,Self-organizing linked lists
can be used impro,Coalesced hashing combines linear probing
31. Which of the following statement about Perfect Hash Functions are true:
Answer: Cichelli’s method uses an exhaustive search ,Cichelli’s method is used to
hash relatively sma
32. Select correct statements:
Answer: A reorganization of the file is avoided by using extendible hashing, The
characteristic feature of extendible hashing is the organizatio
33. Which of the following data structure can be implemented Huffman Coding
Answer: Singly linked list, Priority queue, Doubly linked list
34. Select incorrect statements about Huffman Coding:
Answer: Huffman tree is only implemented by non-recursive. David Huffman’s
algorithm may not be useful for se, Adaptive Huffman coding uses breath-first left-
to-rig
35. Select correct statement about Run-length encoding.
Answer: A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs
36. Identify whether below code has error or not: Abstract class AC1{
Answer: - Compile error
37. Identify whether below code has error or not:
Interface I2{
Answer: - 3 compile errors
ExtC object1 = new ExtC();
C object2 = new ExtC(), object3 = new ExtC();
Which of the following statements are true
Answer: Object1.process2(‘N’) calls process2 of class Ext, Object2.process1(1) does
not issue compile erro, Object2.process3(‘N’) call process3 of class C

Data[j] = data[j-1];
Data[j] = tmp;
}
Identify which algorithm the above code implements
Answer:- Insertion Sort

If (data[j].compareTo(data[j-1])<0)
Swap(data,j,j-1);
}
Identify which algorithm the above code implements
Answer: - Bubble sort

[Link](i+””);
Nontail(i+1);
}
}
What is output if nontail is called with i=3
Answer: - Runtime error is issued.

Nontail(i-2);
}
}
What is output if nontail is called with i=5
Answer: 1315131

preorderVRL([Link]);
}
}
What is output if preorderVRL is executed and structure of Binary Tree is the
following image:
Answer: 2 6 3 15 8 10 1 11 12
What is output if breadthFirst is executed and structure of Binary Tree is the
following image:
Answer: 2 6 8 3 15 10 1 11 12
Assume that sort is executed with array {9,4,2,5,8,10,3}. What is output after
iteration i=5 of the outer for loop completed
Answer: {2,4,5,8,9,10,3}
Assume that sort is executed with array {19,14,6,5,18,10,15}. What is output after
iteration i=5 of the outer for lo
Answer: - {19,18,14,6,5,10,15}
Let deleteFromHead be method used to delete the first element of generic singly
linked list class: Identify whether above code has error or not:
Answer:There may be runtime error in some case
dentify whether the code of pop method has error or not:
Answer: There may be runtime error in some case
Assume that getChar() only reads one character of the input string every it is
called. What output if reverse is
executed and input string is “ABCDEF\n”
Answer: - \nFEDCBA
51. Which of the following about queue are true
Answer: A queue is an FIFO structure
52. Which of the following statement of queue are true
Answer: All of the others: + Using array for queue implemen
53. Select false statement:
Answer: In the array list, poping is executed in time O(n) to the worst case
54. In the doubly linked list implementation, enqueuing can be executed in time
O(n)
Answer: False
55. Which of the following statements about heap are false:
Answer:Heaps represented by array can be travered easily in, A heap can be defined
as an array heap of length n in, Heaps can be implemented by arrays
56. Consider below recursive define about tree:
Answer: An empty structure is an empty tree
57. Which of the following statements about elementary sorting is true:
Answer: None of the others + In selection sort, for every iteration j of,+ The
worst case of selection sort has n-1
58. Which of the following statements about efficient sorting is true:
Answer: Insertion sort is applied to small portions of an array, Mergesort can be
made more efficient by replacing
59. Select correct statements about Radix sort:
Answer: bitRadixsort() can be improved by implementing array , One of techniques
radix sort uses is by looking at each
60. Which of the following statement is true:
Answer: If hash function transforms different keys into different numbers, it is
called a perfect hash function
61. Select correct statements:
Answer: In shift folding method, the key is usually divided into even, The boundary
folding method is applied to number data
62. Which of the following statements are false:
Answer: The best value of divisor can be any, The folding method is the preferred
choice for t
Each codeword corresponds to one or more symbols
Answer: False
Run-length encoding is very efficient for text file in which only blank character
has a tendency to be repeated without using any technique
Answer: True
65. Select correct statement about Ziv-Lempel Code
Answer: All of the others: + Ziv-Lempel Code uses buffer + The codeword of Ziv-
Lempel
The length of the codeword for a given symbol mj should not less than the length of
the codeword of a less probable symbol m; that is
Answer: False
67. In the array implementation, enqueuing can be executed in constant time O(1)
Answer: True
68. Which of the following about stack are true:
Answer: The most top element is the latest added element , Operations of stack
based on Last in First out structure.
69. In the array implementation, dequeuing can be executed in O(n)
Answer: False
71. Select incorrect statement:
Answer: The anchor or ground case allows for the construction of new objects out of
basic e
What is the value of h(1):
Answer: 14
What is the value of A(3,1):
Answer: 15
In all binary trees, there are 2i nodes at level i.
Answer: False
75. Which of the following methods are used to traverse a tree without using any
stack or threads:
Answer: Traversal through tree Transformation
76. Which operation is used in DSW Algorithm:
Answer: Rotation
77. Which of the following are false:
Answer: A path from v1 to vn is a sequence of edges (v1v2), edges (v2v3)…,A circuit
is a cycle in which all vertices must be different
78. Which graph representation is best?
Answer: It depends on the problem
79. Which of the following statements about finding shortest path are true:
Answer: For label-setting methods, in each pass through the vertices still, The
methods solving the shortest path problem are divided into
80. Which of the following statements about graph coloring is true:
Answer: Sequential coloring algorithm establishes the sequence of vertices, The
complexity of sequential Coloring algorithm is O(|V|2)
81. Which of the following statement about finding the shortest path is false:
Answer: - The complexity of WFI’s algorithm is |V|3 that is good efficiency for
any graph
82. In insertion sort algorithm, the number of times variables tmp is loaded and
unloaded in the outer for loop is not:
Answer: All of the others: + Necessary in the worst case + Redundant in the best
case
83. Which of the following statements about Quick sort is true:
Answer: Quick sort is recursive in nature A strategy for selecting a bound is to
choose the element located in the middle of the array

84. Skip list helps avoiding sequential search


Answer: True
85. Select correct statement(s):
Answer:A singly linked list is a node that has a link only to its successor ,
Inserting a new node at the end of the singly linked list without ta
86. Which of the following operations are implemented in the LinkedList class
belongs to the [Link] package:
Answer: All of the others: + Return the copy of the linked list without + Add all
the elements from one collection
Let L1 (having n nodes) and L2 (having m nodes) be two linked list which are
managed by the heads and tails. The complexity of direct concatenating L2 to L1 is
Answer: O(1)
88. Which of the following operations are not implemented in the ArrayList class
belongs to the [Link] package:
Answer: None of the others: + Remove the object at given position + Copy all
objects from the array list to
89. Elements of a linked list must be consecutive memory cells
Answer: False
90. If an algorithm is constantly accessing only some elements such as the first,
the second, the last and the like, an if changing the structure is very important
to the algorithm then solution is using:
Answer: Linked list
91. The advantages of array over linked lists is that they allow random accessing
Answer: True
92. Which of the following operations are implemented in the ArrayList class
belongs to the [Link] package:
Answer:All of the others: + Update one element in any+ Add one element to any po+
Retrieve one element from
93. Linked lists allow easy insertion and deletion of information because such
operations have a
Answer: True
94. In the doubly linked list implementation, dequeuing can be executed in constant
time O(1)
Answer: True
95. Which of the following methods of queue are true:
Answer: Enqueue(el) – Put the element el at, Dequeue() – Take the first element
Consider the following recursive function, assuming n is even: What is the value
of h(20):
Answer: 11
97. Which of the following statements are false:
Answer: An activation record still exists after a method, An activation record
contains code of method
99. Most of the label-setting and label-correcting are used to find the shortest
paths from one vertex to all other vertices
Answer: False
Which of the following statements about Perfect Hash Functions are true:
Answer: In a minimal perfect hash function, wasting time for collision resolu, The
functioning in HCD algorithm is found in three steps: mapping,
Hash function is function that can transform a particular key (K) (a string,
number or record) into an index the table used for storing items of the same type
as K.
Answer: True
Entropy of source M is defined by:
Answer: False
Which of the following operations are not implemented in the ArrayList class
belongs to the [Link] package:
Answer: Return the sub list of the array list containing copy of elements in the
array list
Insertion sort which case is only one comparison made for each position i:
Answer: - The data are already in order
What are number of additions and number of calls to find Fib(8) using recursive
definition
Answer: 33 and 67
Which of the following statements about Quick sort is true:
Answer: A strategy for selecting a bound is to choose the element , Quick sort is
recursive in nature.
107. Which of the following statements about elementary sorting is true
Answer: Advantage of using insertion ort that it sorts the array only when is
really necessary
Select correct statements:
Answer: The middle part of the bit representation of the square of a key is, In
practice, the mid-square method is more efficient to the size of
_class
$value$
zer@
Angs_trom
Answer: zer@

Which statement concerning the switch construct is true?


All switch statements must have a default label.
A character literal can be used as a value for a case label
The keyword continue can never occur within the body of a switch statement.
All of the others.
Answer: A character literal can be used as a value for a case label

If str denotes a String object with the string "73", which of these expressions
will convert the string to the int value 73?
Answer: new Integer(str)).intValue()

Select correct statements about a singly linked list.


Linked lists allow random access to any node.
A node with a specified value (info) can be found by traversing the list.
All of the others
None of the others.

Answer: A node with a specified value (info) can be found by traversing the list.

Advantages which linked list have over an array:


Answer: Size can be expanded and shrunk rapidly.

Which of the following methods take O(n) time for the worst case:
Answer: All of the others.

Select correct statements about a singly linked list.


A new node can be inserted into any position, except first position, without any
traversal.
Deleting a node at the beginning of a list involves setting head to point to
[Link].
All of the others.
None of the others.
Answer: Deleting a node at the beginning of a list involves setting head to point
to [Link].

Properties of a stack is:


Answer: Only one item can be accessed at once.

Properties of a queue are:


Answer: Only one item can be accessed at once.

In the array version of the Stack class, which operations require linear time for
their worst-case behavior?
Answer: None of these operations require linear time.

In the linked-list version of the Stack class, which operations require linear time
for their worst-case behavior? Assume that addtoTail, deletefromTail are used.
Answer: pop

Select wrong statements:


Recursion is always more efficient than loops.
Recursion can make the conceptual design of an algorithm’s implementation easier.
Recursion gone wrong can lead to overflow stack errors
Recursion can be only replaced by iteration.
Answer: is always more efficient than loops+ can be only replaced by iteration

In a single method declaration, what is the maximum number of statements that may
be recursive calls?
Answer: There is no fixed maximum

The problem of printing an input line in reverse order can be implemented using:
Answer: Recursion

Consider algorithm of the 8-queen problem:


Answer: The algorithm finds all solutions.

On average, what is the maximum number of comparisons needed to find a key in a


balanced binary search tree with 1 million nodes?
Answer: 20

To delete a node in a binary search tree that has two children, the Deletion by
Merging method requires to find what node?
Answer: The rightmost node of the left subtree of the deleted node.

Tree balancing can be performed locally after an element is inserted into or


deleted from the tree using………………….
Answer: AVL tree.

The DSW Algorithm uses:


Answer: Right + Left rotation.

The depth-first search algorithm for a graph:


Answer: Travels all possible paths from a vertex to see if it can find the
destination before it moves on to the adjacent vertices.

Select right statements:


Djikstra's shortest path algorithm can be applied to undirected graph.
The breadth-first search can be used to find the shortest path from a source vertex
to the destination vertex
All of the others.
None of the others.
Answer: All of the others.

Two algorithms which used for finding a minimum spanning tree are Kruskal and
Dijkstra. Which algorithm uses the cycle detection method?
Answer: Kruskal + Dijkstra algorithm.

Which of the following statements about shortest path finding algorithms are true:
Dijkstra’s algorithm is label-setting algorithm.
Dijkstra’s algorithm can be applied to graphs have negative weights.
The complexity of Dijkstra’s algorithm is O(|V|), where |V| is number of vertices
of graph.
All of the others.
Answer: Dijkstra’s algorithm is label-setting algorithm.

When is Insertionsort a good choice for sorting an array?


Answer: The array has only a few items out of place.

Mergesort makes two recursive calls. Which statement is true after these recursive
calls finish, but before the merge step?
Answer: Elements in each half of the array are sorted amongst themselves.

Suppose we are sorting an array of eight integers using a some quadratic (O(n2)))
sorting algorithm. After four iterations of the algorithm's main loop, the array
elements are ordered as shown here:
2 4 5 7 8 1 3 6
Which statement is correct?
Answer: The algorithm is not selectionsort, but it might be insertionsort.
In Quicksort, the bound value (pivot) is:
Answer: All of the others.

The more complex the hashing functions, the better it is


Answer: False

Which of the following methods are used to collision resolution:


Answer: Open addressing.

Which of the following hashing methods can cause collision:


Answer: All of the others.

Select incorrect statements:


Answer: In quadratic probing the offset from x is the square of the step number, so
the probe goes to x, x+1, x+2, x+3, x+4, and so on.

Assume that encoding of three symbols X, Y, W, Z is:


V: 10
X: 010
Y: 101
W: 100
Z: 110
Which of the following restrictions does this encoding violate:
Answer: No codeword is a prefix of another codeword.

Select incorrect statements about Data compression:


a Huffman algorithm can be implemented using priority queue.
b Huffman algorithm applied to case of the probabilities of symbol are known in
advance.
c Huffman algorithm can be only applied to text files.
d All of the others
Answer: Huffman algorithm can be only applied to text files.

The Huffman algorithm always produces a unique binary tree.


Answer: False

In an optimal system, there should not be any unused short codewords either a
stand-alone encodings or as prefixes for longer codewords.
Answer: True

Select incorrect statements about Data compression:


a Huffman tree can be only constructed bottom-up.
b In adaptive Huffman encoding, sibling property is retained assures the
Huffman tree under construction is still a Huffman tree.
c All of the others.
d None of the others.
Answer: Huffman tree can be only constructed bottom-up.

Which expressions will evaluate to true if preceded by the following code?


(a == "Hello")
(a == b)
(a == c)
[Link](b)
Answer: (a == c)+[Link](b)

What is output when calling TriangularNumber(4)


Answer: 10

What is maximum number of activation records (including its caller) in runtime


stack when calling TriangularNumber(10
Answer: 11

What is maximum number of activation records (including its caller) in runtime


stack when traversing the below tree using the above algorithm?
Answer: 5

What is maximum number of elements in queue when traversing the below tree using
the above algorithm?
Answer: 4

Assume array data[] = {2,8,6,1,10,15,3,12,11}. Array data after ending the first
loop.
Answer: {15,12,6,11,10,2,3,1,8}

In the first loop, moveDown is called n/2 times in any case.


The total number of moves in all executions of moveDown in the second phase is
O(lgn).
All of the others.
None of the others.
Answer: In the first loop, moveDown is called n/2 times in any case.

“this is g of A”
“this is g of C”
An error occurs when compiling the program.
Nothing is printed.
Answer: “this is g of C”

Assume array data[] = {4,10,8,3,12,17,5,14,13}. Array data after executing 4


iterations of outer loop.
Answer: {3,4,8,10,12,17,5,14,13}

How many times is number 840 printed out when call pattern(840)
Answer: 2

How many integers will the program print when calling nonTail(n), n > 0.
Answer: 2^n -1

Count number of even values in binary tree.


Print even numbers in binary tree.
Print even numbers in ascending order.
Print and count number of even values in binary tree.
Answer: Print even numbers in binary tree.

Count number of nodes in binary tree.


Calculate height of binary tree.
Count number of nonterminal nodes in binary tree.
None of the others
Answer: Calculate height of binary tree.

Check whether binary tree is balanced.


Check whether height of left subtree is greater than height of right subtree.
Check whether height of right subtree is greater than height of left subtree.
None of the others.
Answer: Check whether binary tree is balanced.

Select incorrect statements about Object — Oriented Programming:


Static methods and variables are associated with the class it self
and are called instance methods and instance variables
The combination of data and related operations is called
information hiding principle.
Answer: Static methods and variables+ The combination of data

Which of the following keywords are access modifier:


Answer: protected + private

Select correct statements:


a. A derived class can override the definition of a final method by
introducing its own definition
t. In an abstract class, methods are only declared but not defined
c. Subclasses or derived classes inherit the fields and methods
from their base class.
d. An abstract data type can be part of a program in the form of an
interface
Answer: Subclasses or derived classes inherit+ An abstract data type

An object can be saved in a file if its class type is stated toimplement the
Serializable interface,
d. If the vector’s capacity is greater than its size, then anew element
can be inserted at the end of the vector immediately.
Answer: An object + If the vector’s capacity

Which of sentences about singly linked list are true:


Answer: begin O(1)+ average O(n)+ is no immediate
a. Methods for processing doubly linked list are simpler than those
of singly linked list
b. The node which is deleted from the list will be claimed by the
garbage collector.
c Deleting a node at the end of the list takes constant time 0(1).
d. Inserting a new node at the end of the list requires 0 ( n) steps.
Answer: The node which is deleted+ Deleting a node at the end

Select incorrect statement about skip list:


Answer: None of the others.

Select incorrect statement about skip list:


The search time is O (ign) in the worst case.
Answer: search time is O (ign)+20 element

Select false statement:


Stack can be implemented using linked list.
Stack is applied to Java Virtual Machine,
In the array list, poping is executed in O (lgn) to the worst case.
In the array list, popping is executed in constant time 0(1)
Answer: poping is executed in O (lgn) to the worst case.

a. The Java implementation of the stack is potentially fatal.


b. pop () method returns copy of the top element in the stack
c. peek () method removes the top element of the stack and return it.
d. Stack can be implemented by linked list.
Answer: The Java implementation+ Stack can be implemented by linked list

Which of the following can be executed in constant time 0 ( n)


Answer: deleting singly linked list average case +worst case.

Which of the following statements are true:


Local variables must be stored in activation recordt.
the return address is address of the caller’s instruction immediately foil owing
the c al 1.

Answer: all-in the most case

When converting a method from a recursive version into an iterative version,

Answer: The brevity not be lost + diminished

Recursive definitions on most computers are eventually implemented using a run time
stack and this implementation is done by the operating system.
Answer: True

In all cases, nonrecursive implementation is faster recursive implementation.


Answer: False

Which of the following concepts of tree are true:


Answer: all -path is number of arcs

Select correct statement:


A search can takes 1g ( n) time units in the worst case.
Answer: all-A search lg ( n)worst case.+ for a binary tree

Select incorrect statement:


Depth-first traversal can be implemented using stack.
Depth-first traversal can not be implemented if not using stack
A recursive implementation of preorder free traversal uses stack p1icitly.
There are six possible ordered depth-first traversals.
Morris’s algorithm does not temporarily change free structure.
Answer: all-DF stack+ morris

Which of the following statements are true:


a. Polish notation eliminates all parentheses from formulas
b. Preorder, inorder and posorder tree traversal generate
unambiguous outputs.
Using Polish notation, all expressions have to be broken down
unambiguous into separate operations and put into their proper
order
d. In a expression tree, leaves are operators and nonterninal nodes
are operands.
e. Expression trees do not use parentheses.
f. Polish notation is only applied for compilers.

Answer: parentheses +Using Polish+ Expression

Which of the following statements about finding the shortest path are true:
a. The complexity of Ford’s algorithmis O(VWEh for any graph.
t. For label-correcting method, information of any label can be
changed during application of method.
c. Ford’s algorithm relies on label -setting method.
t The complexity of Dijkstra’s algorithm using heap is O(VlnV)
e. The complexity of Dijkstra’s algorithm is o( v12)
Answer: complexity Dijkstra’s +complexity Dijkstra’s + label-correcting

Which of the following statement about spanning tree is false:


a. The complexity of Kruskal’s algorithm depends on the
complexity of the sorting method applied
t. The complexity of Kruskal’s algorithm depends on the method
used for cycle detection.
c. All of the others.
t None of the others.

Answer: None of the others.

Which of the following statements about efficient sorting is false:


a. The worst case is when the bound divides an array into subarrays
of approximately length
b. In quick sort, a strategy for selecting a bound is to choose the
element located in the middle of the array.
c The best case of quick sort happens when bound is the largest
(the smallest) element of the array.
d. Quick sort is recursive in nature.

Answer: n/2 + best case

Which of the following statements is true;


a. All the sorting methods implemented in java is applied to any
basic data type.
t. For objects comparison, a comparison criterion must be
implemented by user for all classes.
c All of others.
t None of others.
Answer: All of others.

In Insertion Sort, the number of movements and comparisons for a randomly ordered
array is closer to the best case.
Answer: false

Which of the following statement are true:


Linked list can be used in Bucket Addressing.
In chaining, searches always fast if using linked lists.
Answer: All-in chaining

correct statements
a. Extendible hashing is directoryless technique
t. Extendible hashing is faster than and requires less space than
Linear hashing.
c. A reorganization of the file is avoided by using extendible
hashing if the directory overflows.
The characteristic feature of extendible hashing is the
organization of the index, which is expandable table.
e. Linear hashing is directory technique.
Answer: reorganization + characteristic

incorrect statements about Huffman Coding


Answer: all-Huffman tree can be built top-down.

correct statements about Run-length encoding.


Answer: A serious drawback of run-length encoding is that it reliesentirely on the
occurrences of runs

Identify whether below code has error or not:


Answer: Compile error.

Identify whether below code has error or not:


Answer: 3 Compile error.
objectiprocess2 (‘N’) calls process2 of class ExtC.
[Link] (1) does not issue compile error.
object2.process3 (‘N’) call process3 of class C.
object3.process2(’N’) call process2 of class C.
Answer: all-object3.process2(’N’) call process2 of class C.

Identify which alogrithm the above code implements


Insertion Sort
Bubble Sort
Selection Sort
Radix Sort
Answer: Insertion Sort

Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is “ABCDEF\n”
Answer: FEDCBA

What is output if nontail is called with j = 3


Runtime error is issued
1213121
12321
21312
Answer: Runtime error is issued

What is output if nontail is called with i = 5


1315131
13531
3135313
None of the others

Answer: 1315131

What is output if preorderVRL is executed and structure of Binary Tree is the


following image:
1211181021563
28 112 11106153
2631581011112
12 1111082 1536

Answer: 2631581011112

What is output if breadthFirst is executed and structure of Binary Tree is the


following image:
1211181021563
28 112 11106153
263 15 81011112
121111082 1536

Answer: 2 6 3 15 8 10 1 11 12

What is output if breadthFirst is executed and structure of Binary Tree is the


following image:
2863 15 10112 11
286110153 12 11
268 110 153 1112
2683 15 10 11112

Answer: 2683 15 10 11112


Assume that sort is executed with array {9,4,2,5,8,15,3}. What is output
after iteration i=5 of the outer for loop completed
Answer: {2,4,5,8,9,10,3)

Assume that sort is executed with array {19,14,6,5,18,1,15}. What is output after
iteration i=5 of the outer for loop completed
Answer: { 19, 18, 14,6,5,10, 15)

Let deleteFromHead be method used to delete the first element of generic singly
linked list class:
Identify whether above code has error or not:
There are some compile errors.
There may be runtime error in some case.
There always are runtime errors.
No error.
Answer: There may be runtime error in some case.

Identify whether the code of pop method has error or not:


Answer: There may be runtime error in some case.

Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string ¡s “ABCDEF\n’t
Answer: \nFEDCBA
Skip list helps avoiding sequential search
answer: true
A tree structure is not linked structure
answer: a singly lnked list + inserting a new model
Which of the following operations are implemented in the linkedlist class belongs
to the [Link] package
answer: all of the others
Which of the following operations are implemented in the Arraylist class belongs to
the [Link] package
answer: none of the others
Let L1 (having n nodes) and L2 (having m nodes) be two linked lists which are
managed by the heads and tails
answer: o(1)
In the array implementation, enqueuing can be executed in constant time o(1)
answer: true
Select true statement about stack:
answer: The Java implementation of the stack+ stack can be implemented by linked
list
Which of the following about stack are true
answer: the most top element + Operations of stack based
In the array implementation, dequeuing can be executed in o(n)
answer: false
Which of the following about queue are true:
answer: A queue is an FIFO structure
In the doubly linked list implementation, dequeuing ca be excuted in constant time
o(1)
answer: true
In the doubly linked list implementation, enqueuing ca be excuted in o(n)
answer: false
Which of the following methods of queue are true
answer: enqueue + dequeue(first) + isempty + firstel
Select true statements about stack
answer: Stack can be implemented by linked list + the java implementation of the
stack is potentially fatal
Which of the following statement about queue are true
answer: all of the other
Select false statement
answer: in the array list, poping is excuted in time o(n)to the worst case
Select correct statement about Doubly Linked List
answer: Deleting a node at the end of the list takes constant time o(1)+ processing
for adding a node
The advantage of arrays over linked lists is that they allow random accessing
answer: true
Inserting a new node at the end of the singly linked list
answer: a singly linked list is a node + A linked list is a collection of nodes
Which of the following operations are not implemented in the Arraylist class
belongs to the [Link] package
answer: return the sub list of the array list
Which of sentences about singly linked list are true:
answer: There is no immediate access to the predecesor+ on the average+ deleting a
node at the beginning of the list
Select incorrect statements about object- oriented programming:
answer: the combination of the data+ satic methods and variables
x=7; y=4*++x; z=5*x--; what the values of x,y,z
answer: x=7, y= 32, z= 40
characters are 16 bits long
answer: characters are 16 bits long+ for a postfix+ Character that constitute
variable
Seclect false statement about Java:
answer: Java is not case sensitive
Which of the follwing statements are invalid
answer: int c= {1,2,3,4,5}int []b= int[4]int e[5]
Java allows multi inheritance
answer: if the vector's capacity is greater than its size + a vector is a data
structure
Dynamic binding determines the type of response at compilation time
answer: polymorphism is implemented through static + the data structures field is
designed
A condition in if clause can be any value
answer: A condition in if clause can be any value + for a prefix operator + the
program continuws with a statement
In an abstract class, method
answer:In an abstract class, method+subclasses or derived classes+an abstract data
type
Java uses four access modifiers
answer: a package is a collection of classes + Java uses four access modifiers
When converting a method from a recursive version into an iterative version
answer: the brevity of program formulation lost+ program clarity can be diminished
Consider the following recursive function, asuming n is even
answer: 11
Recursive definitions serve generating new elements and testing whether an element
belongs to a set
answer: the anchor or ground case allows for the construction of new object
In all cases, nonrecursive implementation is faster recursive implementation
answer: false
The data area containing state information of one method is called an activation
record
answer: an activation record still exists + an activation record contains code of
method
What is the value of h(1)
answer: 14
What is the value of A(3,1)
answer: 13
What are number of additions and number of calls to find Fib(8)
answer: 34 and 67
Recursive definitions on most computers are eventually implemented using a run-time
stack
answer: true
Global variables must be stored in activation record
answer: the recursive version increases program readability+ the return address is
address
Consider below recursive define about tree
answer: true
Which of the following methods are used for Depth-First Traversal
answer: all of the other
Expreesion trees do not use parenthese
answer: Polish notation eliminates all parenthese from formulas+ Using polish
notation, all expressions have to be...+ Expression trees do not use parenthese
In all binary trees, there are 2 nodes at level i
answer: false
Which of the following concepts of tree are true
answer: The height of a nonempty tree is the maximum+ the level of is the length of
the path from+ the level of node
There are six possible ordered depth-first traversals
answer: Morris's algotrthm does not temporarily change tree structure+ a recursive
implementation + depth first traversal can not be
Which of the following statements about heap are false
answer: heap represented by array+ a heap can be defineed as an array+ heaps can be
implemented by array
Which of the following methods are used to traverse a tree without using any stack
or threads
answer: traversal through tree transformation
Which operation is used in DSW algorithm
answer: rotation
A pseudograph is multigraph which allows for loops to occur
answer: a path from v1 to vn + a circuit is a cycle
Which graph representation is best
answer: it depends on the problem
Which of the following statements about finding the shortest path are true
answer: For label-setting methods, in each pass through+ the methods solving the
shortest path problem are
Which of the following statements about graph coloring is true
answer: sequential coloring algorithm + the comlexity of sequential
Which of the following statements about finding shortest path is false
answer: the complexity of WFI's algorithm is V3
The chromatic number of the cycle
answer: the choromatic number of the complete+ in Brelaz's algorithm
Most of the label-setting and label- correcting methods are used to find the
shortest paths from one vertex
answer: true
Which of the following statements about elementary sorting is true
answer: none of the other
Which of the following statements about efficient sorting is true
answer: Insertion sort is applied+ Mergesort can be made more
In insertion sort, the number of movements and comparisons for a randomly ordered
array is closer to the best case
answer: false
Which of the following statements about efficent sorting is true
answer: all of the other
Select correct statements about Radix sort
answer: bitradixsort() can be improved + One of techniques radix sort
In insertion sort algorithm, the number of times variable tmp
answer: all of the other
Which of the following statements about quick sort is true
answer: quick sort is recursive in nature + a strategy for selecting a bound is to
choose
Mergesort don't consume much memory
answer: Mergesort can be made more efficient + Insertion sort is applied to small
portions
To create a hash function, the table has to contain at least the same number of
positions
answer: if hash function transforms different keys into different numbers
Which of the following statements about open addressing are false
answer: using quadratic probing gives much better results than linear probing and
avoids the problem+ in linear probing of the open
Linear hashing is directory technique
answer: the characteristic feature of extendiable+ a reorganization of the file
Linked list can be used in bucket addressing
answer: coalesced hashing combines linear probing with chaning+ linked list can be
used
The mid-square method is applied only to number data
answer: the middle part of the bit representation of the square of a key + in
practice, the mid-square
The shift folding method is applied to string data
answer: in shift folding method+ the boundary folding method
The best value of divisor can be any
answer: The best value of divisor can be any+ the folding method is the preferred
choice
Which of the following statements about perfect hash functions are true
answer: in a minimal perfect hash function+ the function g in FHCD
Hash function is function that can transform a particular key
answer: true
Each codeword corresponds to one or more symbols
answer: false
Run- lenght encoding is very efficient for text file in which only blank character
answer: true
Select correct statement about Ziv-Lempel code
answer: all of the others
Select correct statement about run-length encoding
answer: A serious drawback of run length encoding
The length of the codeword for a given symbol mj shoukd not less than the length
answer: false
Select incorrect statements about huffman coding
answer: huffman tree is only implemented+ adaptive huffman coding uses breath-first
1. Select incorrect statements about Object - Oriented Programming
answer: [static methods and variables are...][The combination of data and...]
2. Which of the following keywords are access modifier:
answer: [protected][private]
3. Select correct statements
answer: [Subclasses or derived classes inherit...][An abstract data type can be
part of a...]
4. Which of following statements are true
answer: [an object can be saved in a file if..][If the vector's capacity is greater
than its size,..]
5. Which of sentences about singly linked list are true:
answer: [Deleting a node at the beginning...O(1)][On the average,...O(n)step][there
is no immediate..]
6. Select correct statement(s) about Doubly Linked List
answer: [The node which is deleted...garbage collector][Deleting a node at the
end...O(1)]
7. Select incorrect statement about skip list
answer: None
8. Select incorrect statement about skip list
answer: [The search time is O(lgn)...worst case][In 20-element skip
list...3points...position 7]
9. Select false statement
answer: In the array list, poping is executed in O(lgn) to the worst case
10. Select true statements about stack
answer: [The Java implementation .... fatal][Stack can be implemented by linked
list]
11. Which of the following methods of queue are true
answer: [isEmpty() - Check to see...][enqueue(el)-put the element..][firstEl() -
Return the first..]
12. Which of the following can be executed in constant time O (n)
answer: [when deleting a node...average case][when deleting a node...worst case]
13. Which of the following statements are true
answer: [Local variables...activation record][The return address...following the
call][The recursive ver...]
14. When converting a method from a recursive version into an iterative version
answer: [The brevity of program formulation lost... may not be.. Java][Program
clarity can be diminished]
15. Recursive definitions on most computers are eventually implemented using a run-
time stack and this implementation is done by the operating system.
answer: true
16. In all cases, nonrecursive implementation is faster recursive implementation
answer: false
17. Which of the following concepts of tree are true
answer: [The height of nonempty tree is the max...][The level of a node is the
length ...root..node plus 1][The level of a node must be ...1 and height..]
18. Select correct statement
answer:[The complexity of searching a node...][The complexity of searching
depends...][Breath-First ...using queue]
19. Select incorrect statement
answer: [Depth-first traversal can not be ... if not using track][A recursive
implementation preorder...uses stack...][There are six possible ordered...]
20. Which of the following statements are true
answer: [Polish notation eliminates all ...][Using Polish notation,...broken
down....proper oder][Expresstion trees do not use pare...]
21. Which of the following sentences are true
answer: [The complexity of DFS is O(|V|+|E|)...][To prevent loop from happen in
an ... can be marked]
22. Which of the following statements about finding the shortest path are true
anwer: [For label-correcting method, ....][The complexity of Dijkstra's....is O(|V|
ln|V|)][The complexity of Dijkstra's....is O(|V|^2)]
23. Which of the following statement about spanning tree is false
answer: None
24. Which of the following statements about graph coloring is true
answer: [The complexity of sequential .... O(|V|^2)][Sequential Coloring
establishes ....before coloring them]
25. Which of the following statements about efficient sorting is false
answer: [Shell sort divides the original array into physical .... array is sorted]
[Only inscrtion sort is appllied ...]
26. Which of the following statements about efficient sorting is false
answer: [The worst case is when the bound divides... length n/2][The best case of
quick sort happens... element of the array]
27. Which of the statement is true
answer: [All the sorting methods implemented...basic data type][For objects
comparison...by user for all classes]
28. In Insertion Sort, the number of movements and comparisions for a randomly
ordered array is closer to the best case
answer: false
29. Which of the following statement about Open Addressing are false
answer: [For quadratic probing, the size of table should not be ...][Using
quadratic probing gives much better....linear and avoids ... cluster buildup]
30. Which of the following statement are true
answer: [Linked list can be used in Bucket Addressing][Self-organizing linked
list ...improve performance in chaining][Coalesced hasing combines linear probing
with chaning]
31. Which of the following statement about Perfect Hash are true
answer: [Cichelli's method uses an exhaustive search][Cichelli's method is used to
hash relatively small number...]
32. Select correct statements
answer: [A reorganization of the file is avoided ... overflows][The characteristic
feature of extendible hashing... expandable table]
33. Which of the following data structure can be implement Huffman Coding
answer: [Singly linked list][Priority queue][Doubly linked list]
34. Select incorrect statements about Huffman Coding
answer: [Huffman tree is only imp.... non-recursive..][David Huffman's ...may not
be useful for sending..][Adaptive Huffman coding uses breath-first left-to-right...
counter]
35. Select correct statement about Run-length encoding
answer: A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs
36. Identify whether below code has error or not
answer: abstract class AC1{ int AC1f1() {return 0;}void AC1f2(int i) {return ;} int
AC1f3();} ==> compile error
37. Identify whether below code has error or not
answer: interface I2{ double I2f1(); void I2f2(int i); void I2f1(); double I2f3()
{return 10;}; int n =10; pri double m;} ==>3 compile errors
38. Which of the following statements are true
answer: [object1.process2('N') calls process2 of class ExtC][object2.process1(1)
does not issue compile error][object2.process3('N') call process 3 of class C]
39. Identify which alogrithm the above code implements
answer: for(int i = first, j; i<=last; i++){int tmp = data[i]; for(j=i; j>0 &&
tmp<data[j-1];j--) data[j] = data[j-1]; data[j] = tmp;} ==> Insertion Sort
40. Identify which alogrithm the above code implements
answer: pulic <T> extends Com........{ for(int i=0;i<[Link]-1;i++) for (int j
= [Link]-1;j>i;--j) if(data[j].compareTo(data[j-1]) < 0) swap(data,j,j-1);}
==> Bubble sort
41. Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is "ABCDEF\n"
answer: public.... reverse(){char ch = getChar(); if(ch != '\n'){ reverse();
sout(ch);}} ==>FEDCBA
42. What is output if nontail is called with i = 3
answer: void nontail(int i){if(i>0){nontail(i+1); sout(i+""); nontail(i+1);} ==>
Runtime error
43. What is output if nontail is called with i = 5
answer: void nontail(int i){if(i>0){nontail(i-2); sout(i+""); nontail(i-2);} ==>
1315131
44. What is output if preorderVRL is executed and structure of Binary Tree is the
following image
answer: 2 6 3 15 8 10 1 11 12 (lay ben phai roi lay ben trai)
45. What is output if breadthFirst is executed and structure of Binary Tree is the
following image
answer: 2 6 8 3 15 10 1 11 12 (Tu tren xuong duoi, tu phai qua trai)
46. Assume that sort is executed with array {9,4,2,5,8,10,3}. What is output after
iteration i=5 of the outer for loop completed
answer: {2,4,5,8,9,10,3}
47. Assume that sort is executed with array {19,14,6,5,18,10,15}. What is output
after iteration i=5 of the outer for loop completed
answer: {19,18,14,10,6,5,15} or //{19,18,14,6,5,10,15}//
48. Let deleteFromHead be method used to delete the first element of generic singly
linked list class. Identify whether above code has error or not
answer: public T dele...(){T el = [Link]; if(head==tail) head = tail=null; else
head=[Link]; return el;} ==> There may be runtime error in some case
49. Identify whether the code of pop method has error or not
answer: public class Stack<T>{ pri [Link].... pool = new [Link].....; ...
public T pop(){return [Link]([Link]()-1); ==> may be runtime error in some
case
50. Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is "ABCDEF\n"
answer: public.... reverse(){char ch = getChar(); if(ch != '\n') reverse();
sout(ch);} (sout ngoai if) ==> \nFEDCBA

1. Consider the following soft algorithm


answer: public<T> extends...... void insertionsort....{for(int i=1,j;i<[Link];
i++){ T tmp = data[i]; for(j=i....... j--) data[j]=data[j-1]; data[j] =tmp;}} ==>
descending order
2. Which of the following strategies fit to binary Search trees that only have some
elements constantly accessed?
answer: [Use the DSW][Use Self-Restructuring][Use the AVL]
3. What is output after executing unknown(s,0,12), where s = "1352467642135"?
answer: Stack overflow error
4. What is the worst-case time for finding an element in a Binary tree?
answer: O(n^2}
5. Which of the following problems may use the recursion technique
answer: detect a cycle in a graph
6. Identify which alogrithm the above code implements
answer: moveDown(data,0,i-1) ==> bubble sort
7. When a method call is executed, which information does it activation record
contain?
answer: None
8. Which of the following algorithms in graphs can be implemented by extending
Depth First Search algorithm
answer: All of the others
9. Which of the following problems may use stacks implicitly or explicitly
answer: All
10. Which of the following statements are true
answer: [The complexity of Breadth First.... is O(|V|+|E|)][The Depth First Search
for graph traversal.... nectivity and undirected]
11. Suppose temp refers to the third node in the doubly linked list that has more
than 5 nodes. What statament changes temp so that it refers to the first node
answer: temp = [Link]
12. A queue is implemented using a doubly linked list, which of the following
operations require O(n) time?
answer: clear(remove all elements from the queue)
13. Which traversal method is used in Adaptive Huffman tree?
answer: Breadth First traversal

15. What is the complexity of inserting a node in a perfectly balanced tree for
worst case?
answer: O(lgn)
16. This method is used to
answer: {.... return [Link](0,1)+unknown(s,substring(1),ch);}return "";}
==>removes the first occurrence of the specified character from the string ...
17. In the array implementation of the queue, which operations require constant
time?
answer: isEmpty
18. Which of the following statements about the Stack are true
answer: [Clear operation in the linked list .... constant time O(1)][Popping
operation in the linked list ....constant time O(1)]
19. Suppose that obj is an Object variable and that it refers to an Integer object.
If s is a String variable, then which statement is correct about the assignment
"s=(String) obj;"?
answer: The statement will compile, but there will be a run-time exception
20. A chained hash table has an array size of 1024. What is the maximum number of
entries that can be placed in the table
answer: There is no maximum
21. Which of the following definitions about a collision in a hash table are
incorrect
answer: Two entries with different data have the exact same key
22. Which of the following statements about Run-Length encoding are false
answer: run-length encoding cannot be applied to compress fax images
23. A recursive method may be eliminated by using
answer: [Iteration statements][Stacks]
24. "What is number of comparisons in the worst case for mergesort to sort an array
of n elements?"
answer: O(n^2)
25. Which of these operations are likely to have a constant time for worst-case in
the singly linked lists?
answer: None
26. Which of the following Sorting algorithms have complexity of O(n) in best case
answer: All
27. Which of the following Sorting algorithms use Divide and Conquer strategy
answer: Quick sort
28. What is the number of comparisons and swaps in the best case for creating a
heap using top down method (William's method)
answer: The number of comparisons is 2.[n/2] and swaps is zero
29. Which of the following statements about Merge sort method are incorrect
answer: Merge sort can be made more efficient by replacing recursion with iteration
30. Which of the statements about Ziv-Lampel Code are false
answer: None
31. Select incorrect statement about skip list
answer: [Insertion and Deletion are very inefficient][The search time is O(lgn) in
the worst case
32. Select correct statement about Ziv-Lemepel Code
answer: [uses buffer of symbols][The codeword of Ziv-Lemepel Code is a triple]
33. Algorithms are applied to graphs
answer: [Depth First Search][Breadth first Search]
34. Suppose temp refers to some node in a doubly linked list. What boolean
expression can be used to check whether temp refers to the first node of the list
answer: [Link] == null
35. Suppose that obj is an Object variable and that it refers to an Integer object.
If s is a String variable, then which statement is correct about the assignment "s
= (String) obj;"?
answer: The statement will compile and run with no exception
36. When a method call is executed, which information is not saved in the
activation record
answer: Location where the method should return when done
What is written to the screen for the input "HowAre***You**To***Day"?
answer: HowAreYou
Given a weighted graph below and you are using the Dijkstra algorithm to find the
shortest path from the vertex A to the vertex F. What are the correct order of
vertices selected into the set S until the vertex F is selected?
answer: A,C,D,F
Consider the binary tree below. Which statement is correct?
answer: The tree is neither complete nor full
7 5 6 4 3 9 8 2
answer: 7 5 6 4 3 9 8 2 1
Consider the AVL tree below. What is the breadth first traversal of the tree after
inserting a node with value 22?
answer: 35,20,45,10,25,40,22,30
Suppose we are considering a singly linked list and p is some node in the list
which has successor node. Select the most correct java code snippet that deletes
the successor node of p(the node after p).
anser: Node q =[Link]; [Link]=[Link].
Suppose a doubly linked list of integers is given below and tail is a reference to
the last node in the list: (head) 7 1 6 4 3 9 8 2 (tail)
answer: 7 1 6 4 3 9 8 5 2
Specify the correct implementation of dequeue() menthod of a queue. This queue uses
[Link] for storing data and the head of the list is treated as the
head of the queue.
answer: Object dequeue() {if(isEmpty()) return(null);return([Link]());}
void fun(int n)
{ if(n < 0)
{
[Link]("-");
fun(-n);
}
else if( n<15 )[Link]
}
answer: n >= 15
7, 5, 11, 12, 3, 10, 2, 4, 8, 6
answer: 2,3,11,12,5,10,7,4,8,6
Specify the correct statement about hashing algorithm?
answer: If the coalesced method is used for collision resolution, insertion and
searching(and sometimes deletion)always take constanttime:0(1)
B: 32%
C: 28%
D: 16%
E: 6%
F: 18%
answer: 001
Suppose a G is given below(view picture). Which of the followings is the Hamilton
cycle from the vertex B, created by above algorithm?
answer: B A F D E C B
What is the value of the Boundary Folding Hash Function if K = 42-65-76-7 and TSize
= 100?
answer: 82
Suppose we are considering a binary search tree. Select the most correct java code
snippet that search a node with value x.
answer: Node search(int x){Node p = root; While(p!=null && [Link]!=x)
if(x>[Link])p=[Link]; else p=[Link];}
Select the statement that is the most correct.
answer: For a recursive method to terminate there must be on or more limit
conditions
Given a weighted graph below and you are using the Dijkstra algorithm to 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?
answer: 17
Select the most correct statement about the complexity of insertion sort
answer: the best case is O(n), and the worst case is O(n2)
consider the AVL tree below. What is the breadth first traversal of the tree after
inserting a node with value 28
answer: 35 20 45 10 28 40 25 30
The operation for adding an entry to a queue is traditionally called:
answer: enqueue
1 0 1
answer: int n,k; n=13
4 9 9
answer: int a,b; void set(int a1, int b1)
What is the breadth-first traversal of a tree below after deleting the node 5 by
merging?
answer: 4 2 7 1 3 6 8
What is the value of the Shift Folding Hash Function if the key K =44-65-76-8 and
TSize=100
answer: 90
In a real computer, what will happen if you make a recursive call without making
the problem smaller?
answer: the results are nondeterministic
To implement an AVL tree, aconcept balance factor is introduced(bal =
height(right)-hight(left)).Suppose an AVL tree is created by inserting to the tree
the folowing keys sequentially: 6, 4, 7, 3 ,5 ,2 What is the balance factor of the
node 4
answer: -'
16, 5, 2, 11, 10, 8, 12, 3, 8, 6
answer: 2 5 16 11 10 8 12 3 8 6
Consider the AVL tree below. What is the preorder traversal of the tree af ter
deleting the node with value 40?
answer: 12 22 27 32 35 45
Which of the following methods is used to collision resolution:
answer: Cicheli's method
The operation of visiting each element in the list exactly once is know as
answer: Traverse
Specify the correct statement about the fun() method in the code above
answer: It removes the first element of the list
6, 4, 9, 10, 8, 3, 7, 5
answer: 3 4 5 6 8 7 9 10
Suppose the f(n) function is defined on the set of integer numbers as below. What
is the valuse of f(-5)?
answer: 3
State True or False:"In a binary search tree, all the nodes that are left
descendants of the node A have key values greater than A; all the node that are A's
right descendants have key values less than (or equal to)A."
answer: False
Suppose we are considering a singly linked list which has at least 2 nodes. Select
the most correct java code snippet that inserts new node with value x before the
last node
answer: dek biet
Given a graph below. What is the output of depth-first traversal from vertex B?
(visit nodes in ABc order if there are some nodes having the same selection
ability)
answer: B A E G C F D
Given araw message 'BBBUUUUBBBUUBBBBBUU'
answer: 3B4U4B3U2B5UU2
What is maximum nuber of activation records( including its caller ) in runtime
stack when calling TriangularNumber(10)
answer: 9
Node q = [Link];
[Link] = [Link];
answer: It deletes the node after p
Given a weighted graph below and you are using the Dijkstra algorithm to 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?
answer: B C D F
The complexity of heap sort is
answer: 2
fun(-1012)
answer: int fun(int n)
6, 4, 9, 10, 2, 8, 1, 3, 7, 5
answer: 4 6 9 2 8 1 3 7 5 10
Integer "j" is not initialized
answer: for(int i=0;i<14;i++)
5 100 100
answer: (A h = new A(5))
B: 32%
C: 28%
D: 16%
E: 6%
F: 18%
Using Huffman encoding, what is the code for character D?
answer: 0'
Given a weighted graph below and you are using the Dijkstra algorithm to find the
shortest path from the vertex A to the vertex F. what is the label of the vertex E
when the shortest path from A to F is determined?
answer: infinity
Node p1,p2;p1 = [Link];// prev is a link to previous node
answer: It deletes the node p
Select the statement that is most correct. Which of the following applications may
use a stack
answer: store a waiting list of printing jobs
Specify the most correct statement about chaining method for handing collision
answer: in chaining, some positions of the table is associated with a linked list
or chain of ...
n>=0&&n<15
answer: void fun(int n)
what is output when calling Triangularnumber(4)
answer: 10
Suppose a graph G is given by the adjacency matrix below. Which of the followings
is the Hamilton cycle
answer: A D E C B A
Select incorrect statement about Data compression
answer: Huffman algorithm applied to case of the probabilities of symbol are known
in advance
Specify the statement that is most correct about a circular linked list
answer: Cicurlar linked list is a linked list in which the last node of the list
points to the first node in the list
What is written to the screen for the input"Good**Morn**in***g"?
answer: GoMg
Specify the correct statement about open addressing method for handling collision
answer: The collision is resloved by finding an available table entry orther that
the position to which the colliding key is originally hashed
Assume in direted graph edge uv means "vertex v depends on vertex u".What is valid
topological sort the graph shown below:
answer: A B D C E F G H
Given a graph below. What is the output of breadth-fist traversal from vertex C ?
answer: C B D A E F G
6, 7, 3, 1, 2, 5, 8
answer: 6 3 7 1 5 8 2
8, 5, 11, 12, 3, 10, 2, 4, 9, 6
answer: 2 3 11 12 5 10 8 4 9 6
Fill in blank to form a correct statement: " A recursive method is a method that
invokes itself directly or indirectly. For a recursive method to terminate there
must be one or more ___________".
answer: Limit conditions
What is the breadth-first traversal of a tree below after deleting the node 5 by
copying?
answer: 4 2 7 1 3 6 8
Suppose a multigraph G is given by the adjacency matrix below. Which of the
foolowings is the Euler cycle?
answer: A B C B D A
Select incorect statement about Object - Oriented Programming
answer: Static methods and avariables are associated
Which of the following keywords are access modifier
answer: protected , private
Select correct satements
answer: In an abstract class , subclasses or derived classes , An abstract data
type
Which following statements are true
answer: [2] An object can be saved , If the vector's
Which the sentences about singly linked list are true
answer: [3] Deleting a node ; On the average ; There is no immediate
Select correct statement(s) about Doubly Linked list
answer: [2] the node which ; Deleting a node
Select incorrect statement about skip list
answer: None of others
Select incorrect statement about skip list
answer: The search time is 0(lgn)
Select false statement
answer: In the array list, poping is executed in 0(lgn)
Select true statements about stack
answer: The java ; Stack can be implemented
Which of the following methods of queue are true
answer: isEmpty(); enqueue(el); firstEL()
Which of the following can be executed in constant time O( n )
answer: When deleting a node , when deleting a node
Which of the folowing statements are true
answer: The return address; The recursive version
When converting a method from a recursive version into an iterative version
answer: The brevity of program formulaion; Program clarity
Recursive definition on most computers are eventually implemented using a run-time
stack and this implementation is done by the operating system
answer: true
In all cases, nonrecursive implementation is faster recursive implementation
answer: true
Which of the following concepts of the tree are true
answer: the height ; the level ; the lever
Select correct statement
answer: The complrxity of searching depends on the shape of the tree and the
position of the node in the tree ; Breath-First; For a binary tree
Select incorect statement
answer: Depth-first traversal can not be implemented if not using stack ; A
recursive ; Morri's algorithm
Which of the following statement are true
answer: Polish notaion ; Using polish notation; Expression trees
Which of the following sentences are true
answer: the complexity of DFS is O(|V|+|E|); To prevent loop
Which of the statements about fiding the shortest path are true
answer: For label ; Ford's ; the complexity of Dijkstra's algorithm is O(|v|2)
Which of the sollowing statement about spanning tree is false
answer: none of other
Which of the following statements about graph coloring is true
answer: In sequential coloring algorithm vertices must be ordered according to
indices already to the vertices ; The complexity ; Sequential
Which of the following statements about efficient sorting is false
answer: Shell sort divides the original array into physical ; Only insertion
Which of the following statements about efficient sorting is false
answer: The worst case; The best case
Which of the following statement is true
answer: for obiject comparison
In Insertion Sort, the number of moovements and comparisons for a radomly ardered
array is closer to the besr case
answer: False
Which of the following statement about Open Addressing are false
answer: Using quadratic probing ; Which key can be stored
Which of the following statement are true
answer: Linked list ; Self-organizing; Coalesced
Which of the following statement about Perfect Hash Function are true
answer: Cichelli's method uses an exhaustive search ; Cichelli's method is used to
hash relatively
Select correct statements
answer: A reorganization ; The characteristic
Which of the following data structure can be implement Huffman Coding
answer: Sigly linked list ; Priority queue ; Doubly linked list
Select incorrect statements about Huffman Coding
answer: Huffman tree is only implemented ; Adaptive Huffman coding
Select correct statement about Run-lenght encoding
answer: A serious drawback of run-length encoding
Indentify whether below code has error or not
answer: Compile error
Assume the getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is "ABCDEF\n"
answer: FEDCBA
What is output if nontail is called with i = 3
answer: runtime error is issued
What is output if nontail is called with i = 5
answer: 1315131
what is output if preorderVRL is executed and structure of Binary Tree is the
following image
answer: 2 6 3 15 8 10 1 11 12
what is output if breadthFirst is executed and structure of Binary Tree is the
following image
answer: 2 6 8 3 15 10 1 11 12
{19,14,6,5,18,10,15}
answer: {19,18,14,6,5,10,15}
{9,4,2,5,8,10,3}
answer: {2,4,5,8,9,10,3}
Identify whether above code has error or not
answer: There may be runtime error in some case
Identify whether the code of opo method has error or not
answer: There may be runtime error in some case
Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is"ABCDEF\n"
answer: \nFEDCBA
Which statements are true about inheritance?
a In Java the extends clause is used to specify inheritance
b A subclass must define all the methods from the superclass.
c A class can extend any number of other classes.
d All of the others.

Answer: In Java the extends clause is used to specify inheritance

Which statements are true about interfaces?


a The keyword implements is used to specify that a class inherits from an
interface.
b Members of an interface can always be declared static.
c Interfaces can extend any number of other interfaces.
d None of the others.

Answer: Interfaces can extend any number of other interfaces.

Which one of these for statements is valid


a for (int i=10; i=0; i--) {}
b for (int i=0, j=100; i<j; i++, --j) {;}
c int i, j; for (j=100; i<j; j--) { i += 2; }
d int i=100; for ((i>0); i--) {}

Answer: for (int i=0, j=100; i<j; i++, --j) {;}

Which statements are false about modifiers?


a A final methods or field cannot be changed by derived classes.
b Methods and fields declared public can be used by any other object.
c The default modifier means that a method or a field is a accessible to
derived classes.
d None of the others.

Answer: The default modifier means that a method or a field is a accessible to


derived classes.

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?
a (temp == null)
b ([Link] == null)
c ([Link] == null)
d None of the above.

Answer: ([Link] == null)

Suppose temp refers to a node in a linked list (using the SLLNode class with
instance variables called info and next). What statement changes temp so that it
refers to the next node?
a temp ++;
b temp = next;
c temp += next;
d temp = [Link];

Answer: temp = [Link];

Which boolean expression indicates whether the data in two nodes (p and q) are the
same. Assume that neither p nor q is null.
a p == q
b [Link] == [Link]
c [Link] == [Link]
d None of the others.

Answer: [Link] == [Link]

Which of these operations are likely to have a constant time for worst-case in the
linked lists?
a addBefore (add a new element into before an element in the list).
b countOccurrences (count number of an element’s present times in the list).
c Delete (remove an element in the list).
d None of the others.

Answer: None of the others.

The operation for adding an entry to a stack is traditionally called:


a add
b append
c insert
d push

Answer: push

In the array version of the Queue, which operations require O(n) time for their
worst-case behavior?
a dequeue
b insert when the capacity has not yet been reached
c isEmpty
d None of the others

Answer: None of the others

Which of the following applications may use a stack?


a A parentheses balancing program.
b Keeping track of local variables at run time.
c Syntax analyzer for a compiler.
d All of the others.

Answer: All of the others.

In the linked-list version of the Queue, which operations require linear time for
their worst-case behavior?
a dequeue
b insert
c isEmpty
d None of the others

Answer: None of the others

When a method call is executed, which information is not saved in the activation
record?
a Local variables
b Location where the method should return when done.
c Current depth of recursion.
d Values for all parameters to the method.

Answer: Current depth of recursion.

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

Answer: None of the others.

Select correct statements about recursion


Any iterative program can be written recursively.
Every recursive method can be converted into an iterative version.
Quicksort and mergesort are recursive in nature.
All of the others.

Answer: All of the others.

Select the one TRUE statement.


a Every binary tree is either balanced or perfect balanced.
b Every balanced binary tree is also a perfect balanced binary tree.
c Every perfect balanced binary tree is also a balanced binary tree.
d No binary tree is both balanced and perfect balanced.

Answer: Every perfect balanced binary tree is also a balanced binary tree.

……………………… is visiting node starting from the highest (or lowest) level and moving
down (or up) level by level, visiting nodes on each level from left to right (or
from right to left).
a Breath-First Traversal
b Depth-First Traversal
c Stackless Depth-First Traversal
d None of the others

Answer: Breath-First Traversal

……………..rebalances the tree globally; each and every node could have been involved
in rebalancing either by moving data from nodes or by creasing new values to
reference fields.
a The DSW Algorithm
b One classical method has been proposed by Adel’son – Vel’skii and Landis (AVL
tree).
c All of the others
d None of the others

Answer: The DSW Algorithm

A heap is an exellent way to implement a ……………..


a stack
b queue
c priority queue
d tree.

Answer: priority queue

What is the expected number of operations needed to loop through all the edges
terminating at a particular vertex given an adjacency matrix representation of the
graph? (Assume n vertices are in the graph and m edges terminate at the desired
node).
a O(m)
b O(n)
c O(m2)
d O(n2)

Answer: O(n)

What graph traversal algorithm uses a queue to keep track of vertices which need to
be processed?
a Breadth-first search.
b Depth-first search.

Answer: Breadth-first search.


Suppose you have a directed graph representing all the flights that an airline
flies. What algorithm might be used to find the best sequence of connections from
one city to another?
a Breadth first search.
b Depth first search.
c A cycle-finding algorithm.
d A shortest-path algorithm.

Answer: A shortest-path algorithm.

The final exams at a university can be scheduled so that no


student has two exams at the same time by applying ……………
a Graph coloring
b Matching
c Topological sort
d Eulerian graph

Answer: Graph coloring

What is the worst-case time for mergesort to sort an array of n elements?


a O(nlgn)
b O(n)
c O(n2)
d O(lgn)

Answer: O(nlgn)

What is the worst-case time for bublesort to sort an array of n elements?


a O(nlgn)
b O(n)
c O(n2)
d O(lgn)

Answer: O(n2)

Answer: What is the worst-case time for heapsort to sort an array of n elements?
a O(nlgn)
b O(n)
c O(n2)
d O(lgn)

Answer: O(nlgn)

In a selectionsort of n elements, how many times are the array elements moved in
the worst case?
a O(nlgn)
b O(n)
c O(n2)
d None of the others

Answer: O(n)

What is the worst-case time for binary search finding a single item in an array?
a Constant time
b Logarithmic time
c Linear time
d Quadratic time
Answer: Logarithmic time

What is the best definition of a collision in a hash table?


a Two entries are identical except for their keys.
b Two entries with different data have the exact same key.
c Two entries with different keys have the same exact hash value.
d Two entries with the exact same key have different hash values.

Answer: Two entries with different keys have the same exact hash value.

A chained hash table has an array size of 512. What is the maximum number of
entries that can be placed in the table?
a 256
b 511
c 512
d 1024
e There is no maximum

Answer: There is no maximum

Suppose you place m items in a hash table with an array size of s. What is the
correct formula for the load factor?
a s + m
b s/m
c s * m
d m/s
e m - s

Answer: m/s

Which of the following data structure can be implement Huffman Coding


b Singly linked list.
c Priority queue.
d All of the others
e Doubly linked list.

Answer: Doubly linked list.

Select incorrect statements about restrictions need to be imposed on the


prospective codes:
a Each codeword may corresponds to one or many symbols.
b Assume that symbols and have probabilities of occurrence , . If ,
then , where and .
c Decoding should not require any look ahead.
d There should not be any unused short codewords either as stand-alone
encodings or as prefixes for longer codewords.

Answer: Each codeword may corresponds to one or many symbols.

Answer: Select correct statement about Run-length encoding.


a A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs.
b Run-length encoding is very useful when applied to files that are almost
guaranteed to have many runs of at least five characters.
c All of the others.
d None of the others.
Answer: A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs.

Select correct statement about Ziv-Lempel Code.


a Ziv-Lempel Code uses buffer of symbols.
b The codeword of Ziv-Lempel Code is a triple.
c All of the others.
d None of the others.

Answer: All of the others.

Which statement is true about the following code?


a Interface1 and Interface2 do not match, therefore, MyClass cannot implement
them both.
b The declarations of void g() in the two interfaces conflict, therefore, the
code will not compile.
c The declarations of int VAL_B in the two interfaces conflict, therefore, the
code will not compile.
d Nothing is wrong with the code, it will compile without errors.

Answer: Nothing is wrong with the code, it will compile without errors.

What will be the result of attempting to compile and run the following program?
a The program will fail to compile.
b The program will compile without error and print 0 when run.
c The program will compile without error and print 1 when run.
d The program will compile without error and print 2 when run.

Answer: The program will compile without error and print 2 when run.

Which digits, and in which order, will be printed when the following program is
run?
a The program will only print 1 and 4, in that order.
b The program will only print 1, 4, and 5, in that order.
c The program will only print 3 and 5, in that order.
d The program will only print 1, 2, 4, and 5, in that order.

Answer: The program will only print 1, 4, and 5, in that order.

Consider the following pseudocode:


What is written to the screen for the input "ABBAABBA"?
a ABABABAB
b BABABABA
c ABBAABBA
d BAABBAAB

Answer: ABBAABBA

Consider the following method:


What values of number are directly handled by the stopping case?
a number < 0
b number < 10
c number >= 0 && number < 10
d number > 10

Answer: number >= 0 && number < 10

Consider the following sort algorithm:


Number of comparisons of keys and comparisons of i and least is:
a (n(n-1))/2
b n-1
c ((n-1)(n+2))/2
d None of the others.

Answer: ((n-1)(n+2))/2

Consider the following sort algorithm:


Assume that this algorithm is executed with array {7,1,2,3,4,5,6}. What is output
after iteration i=4 of the outer for loop completed
a 1, 2, 3, 4, 5, 6, 7
b 1, 2, 3, 7, 4, 5, 6
c 1, 2, 3, 4, 5, 7, 6
d 1, 2, 3, 4, 7, 5, 6

Answer: 1, 2, 3, 4, 5, 7, 6

Consider the following sort algorithm:


Number of comparisons of keys is
(n(n-1))/2
Answer: (n(n-1))/2

Consider the following algorithm:


Which traversal does the above algorithm implement?
a Breadth-first traversal
b Inorder tree traversal
c Postorder tree traversal
d Preorder tree traversal

Answer: Preorder tree traversal

Consider the following sort algorithm:


Select correct statements when applying this algorithm to a n-element array:
a moveDown() is called times to create the heap in the first phase.
b The heap is restored times in the second phase.
c In the second phase, this algorithm exchanges times the root with the
element in position.
d All of the others.

Answer: All of the others.

Consider this method declaration:


How many asterisks are printed by the method call quiz(5)?
a 8
b 4
c 7
d None of the others.

Answer: 7

Consider the following traversal algorithm:


What is output if this algorithm is executed on the following binary tree:
a 40 30 7 10 11 3 1 2 14
b 1 3 2 7 10 40 30 11 14
c 1 2 3 14 7 10 11 40 30
d 14 2 1 3 11 10 7 30 40

Answer: 40 30 7 10 11 3 1 2 14
Consider the following algorithm
What is output if this algorithm is executed on the following binary tree
a 3
b 9
c 5
d 8

Answer: 5

Which statement, when inserted at the indicated position in the following code,
will cause a runtime exception?
a x = y;
b z = x;
c y = (B) x;
d z = (C) y;
e y = (A) y;

Answer: y = (B) x;

A method within a class is only accessible by classes that are defined within the
same package as the class of the method. How can such a restriction be enforced?
a Declare the method with the keyword public.
b Declare the method with the keyword protected.
c Declare the method with the keyword private.
d Do not declare the method with any accessibility modifiers.

Answer: Do not declare the method with any accessibility modifiers.

Which are invalid identifiers?


a _class
b $value$
c zer@
d Angs_trom

Answer: zer@

Which statement concerning the switch construct is true?


a All switch statements must have a default label.
b A character literal can be used as a value for a case label
c The keyword continue can never occur within the body of a switch statement.
d All of the others.

Answer: A character literal can be used as a value for a case label

If str denotes a String object with the string "73", which of these expressions
will convert the string to the int value 73?
a (new Integer(str)).intValue()
b [Link](str)
c [Link](str)
d ((int) str)

Answer: (new Integer(str)).intValue()

Select correct statements about a singly linked list.


a Linked lists allow random access to any node.
b A node with a specified value (info) can be found by traversing the list.
c All of the others
d None of the others.
Answer: A node with a specified value (info) can be found by traversing the list.

Advantages which linked list have over an array:


a Quick searching.
b All of the others.
c None of the others.
d Size can be expanded and shrunk rapidly.

Answer: Size can be expanded and shrunk rapidly.

Which of the following methods take O(n) time for the worst case:
a Insert a node into any position in Linked List.
b Delete a node in position which is followed by the last node.
c All of the others.
d None of the others.

Answer: All of the others.

Select correct statements about a singly linked list.


a A new node can be inserted into any position, except first position, without
any traversal.
b Deleting a node at the beginning of a list involves setting head to point to
[Link].
c All of the others.
d None of the others.

Answer: Deleting a node at the beginning of a list involves setting head to point
to [Link].

Propertie of a stack is:


a Multiple-items can be accessed at once.
b Only one item can be accessed at once.
c None of the others.

Answer: Only one item can be accessed at once.

Properties of a queue are:


a Only one item can be accessed at once.
b Multiple-items can be accessed at once.
c None of the others.

Answer: Only one item can be accessed at once.

In the array version of the Stack class, which operations require linear time for
their worst-case behavior?
a is_empty
b topEl
c pop
d push when the array is not yet full.
e None of these operations require linear time.

Answer: None of these operations require linear time.

In the linked-list version of the Stack class, which operations require linear time
for their worst-case behavior? Assume that addtoTail, deletefromTail are used.
a is_empty
b topEl
c pop
d push.
e None of these operations require linear time.

Answer: pop

Select wrong statements:


a Recursion is always more efficient than loops.
b Recursion can make the conceptual design of an algorithm’s implementation
easier.
c Recursion gone wrong can lead to overflow stack errors
d Recursion can be only replaced by iteration.

Answer: Recursion can be only replaced by iteration.

In a single method declaration, what is the maximum number of statements that may
be recursive calls?
a 1
b 2
c n (where n is the argument).
d There is no fixed maximum

Answer: There is no fixed maximum

The problem of printing an input line in reverse order can be implemented using:
a Recursion.
b Iteration.
c Stack.
d All of the others.

Answer: All of the others.

Consider algorithm of the 8-queen problem:


putQueen(row)
for every position col on the same row
if position col is available
place the next queen in position col;
if (row < 8)
putQueen(row+1);
else success;
remove the queen from position col;
Which of the following statements are true:
a The algorithm end after finding one solution.
b The algorithm does not find symmetric solutions.
c The algorithm finds all solutions.

Answer: The algorithm finds all solutions.

On average, what is the maximum number of comparisons needed to find a key in a


balanced binary search tree with 1 million nodes?
a 10
b 15
c 20
d 30

Answer: 20

To delete a node in a binary search tree that has two children, the Deletion by
Merging method requires to find what node?
a The rightmost node of the left subtree of the deleted node.
b The smallest sibling node.
c The parent node.
d None of the others.

Answer: The rightmost node of the left subtree of the deleted node.

Tree balancing can be performed locally after an element is inserted into or


deleted from the tree using………………….
a The DSW algorithm.
b AVL tree.
c Creating a binary search tree from an ordered array.
d None of the others.

Answer: AVL tree.

The DSW Algorithm uses:


a Right rotation.
b Left rotation.
c All of the others.
d None of the others.

Answer: All of the others.

The depth-first search algorithm for a graph:


a Searches for the minimal edges needed to visit each vertex in the graph.
b Travels all possible paths from a vertex to see if it can find the
destination before it moves on to the adjacent vertices.
c Checks all adjacent vertices before moving down the paths to find the
destination.
d None of the others.

Answer: Travels all possible paths from a vertex to see if it can find the
destination before it moves on to the adjacent vertices.

Select right statements:


a Djikstra's shortest path algorithm can be applied to undirected graph.
b The breadth-first search can be used to find the shortest path from a source
vertex to the destination vertex
c All of the others.
d None of the others.

Answer: All of the others.

Two algorithms which used for finding a minimum spanning tree are Kruskal and
Dijkstra. Which algorithm uses the cycle detection method?
a The Kruskal algorithm.
b The Dijkstra algorithm.
c All of the others.
d None of the others.

Answer: All of the others.

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

Answer: Dijkstra’s algorithm is label-setting algorithm.


When is Insertionsort a good choice for sorting an array?
a Each component of the array requires a large amount of memory.
b Each component of the array requires a small amount of memory.
c The array has only a few items out of place.
d The processor speed is fast.

Answer: The array has only a few items out of place.

Mergesort makes two recursive calls. Which statement is true after these recursive
calls finish, but before the merge step?
a The array elements form a heap.
b Elements in each half of the array are sorted amongst themselves.
c Elements in the first half of the array are less than or equal to elements in
the second half of the array.
d None of the others

Answer: Elements in each half of the array are sorted amongst themselves.

Suppose we are sorting an array of eight integers using a some quadratic (O(n2)))
sorting algorithm. After four iterations of the algorithm's main loop, the array
elements are ordered as shown here:
2 4 5 7 8 1 3 6
Which statement is correct?
a The algorithm might be either selectionsort or insertionsort.
b The algorithm might be selectionsort, but it is not insertionsort.
c The algorithm is not selectionsort, but it might be insertionsort.
d The algorithm is neither selectionsort nor insertionsort.

Answer: The algorithm is not selectionsort, but it might be insertionsort.

In Quicksort, the bound value (pivot) is:


a The first item of array.
b The middle item of array.
c The last item of array.
d All of the others.

Answer: All of the others.

The more complex the hashing functions, the better it is


a True
b False

Answer: False

Which of the following methods are used to collision resolution:


a Folding.
b Cichelli’s method.
c Open addressing.
d FHCD

Answer: Open addressing.

Which of the following hashing methods can cause collision:


a Division
b Folding
c Mid-Square
d Extraction
e All of the others.
Answer: All of the others.

Select incorrect statements:


a Quadratic probing eliminates primary clustering but suffers from the less
severe secondary clustering.
b In double hashing the step size depends on the key and is obtained from a
secondary hash function.
c In quadratic probing the offset from x is the square of the step number, so
the probe goes to x, x+1, x+2, x+3, x+4, and so on.
d None of the others.

Answer: In quadratic probing the offset from x is the square of the step number, so
the probe goes to x, x+1, x+2, x+3, x+4, and so on.

Assume that encoding of three symbols X, Y, W, Z is:


V: 10
X: 010
Y: 101
W: 100
Z: 110
Which of the following restrictions does this encoding violate:
a Each codeword corresponds to exactly one symbol.
b No codeword is a prefix of another codeword.
c The length of the codeword for a given symbol mj should not exceed the length
of the codeword of a less probable symbol m¬i.

Answer: No codeword is a prefix of another codeword.

Select incorrect statements about Data compression:


a Huffman algorithm can be implemented using priority queue.
b Huffman algorithm applied to case of the probabilities of symbol are known in
advance.
c Huffman algorithm can be only applied to text files.
d All of the others

Answer: Huffman algorithm can be only applied to text files.

Answer: The Huffman algorithm always produces a unique binary tree.


a True
b False

Answer: False

In an optimal system, there should not be any unused short codewords either a
stand-alone encodings or as prefixes for longer codewords.
a True
b False

Answer: True

Select incorrect statements about Data compression:


a Huffman tree can be only constructed bottom-up.
b In adaptive Huffman encoding, sibling property is retained assures the
Huffman tree under construction is still a Huffman tree.
c All of the others.
d None of the others.
Answer: Huffman tree can be only constructed bottom-up.

Given the following interface definition, which definition is valid?


interface B extends I{ void increment(); }

Answer: interface B extends I{ void increment(); }

Which expressions will evaluate to true if preceded by the following code?


a (a == "Hello")
b (a == b)
c (a == c)
d [Link](b)

Answer: (a == c) || [Link](b)

Consider the following alogorithm:


What is output when calling TriangularNumber(4)
a 6
b 10
c 15
d 20

Answer: 10

Consider the following alogorithm:


What is maximum number of activation records (including its caller) in runtime
stack when calling TriangularNumber(10)
a 7
b 9
c 11
d 13

Answer: 11

Consider the following alogorithm:


What is maximum number of activation records (including its caller) in runtime
stack when traversing the below tree using the above algorithm?
a 4
b 5
c 3
d 6

Answer: 5

Consider the following alogorithm:


What is maximum number of elements in queue when traversing the below tree using
the above algorithm?
a 4
b 5
c 6
d 3

Answer: 4

onsider the following alogorithm:


Assume array data[] = {2,8,6,1,10,15,3,12,11}. Array data after ending the first
loop.
a {15,12,2,11,10,6,3,1,8}
b {15,12,6,11,10,2,3,1,8}
c {8,12,6,11,10,2,3,1,15}
d None of the others

Answer: {15,12,6,11,10,2,3,1,8}

Consider the following alogorithm:


Select right statements:
a In the first loop, moveDown is called n/2 times in any case.
b The total number of moves in all executions of moveDown in the second phase
is O(lgn).
c All of the others.
d None of the others.

Answer: In the first loop, moveDown is called n/2 times in any case.

What will be printed when the following program is run?


a 0
b 1
c 2
d An error occurs when compiling the program.

Answer: 2

What will be printed when the following program is run?


a “this is g of A”
b “this is g of C”
c An error occurs when compiling the program.
d Nothing is printed.

Answer: “this is g of C”

Consider the following alogorithm:


Assume array data[] = {4,10,8,3,12,17,5,14,13}. Array data after executing 4
iterations of outer loop.
a {3,4,8,10,12,17,5,14,13}
b {3,4,10,8,12,17,5,14,13}
c {10,8,4,3,12,17,5,14,13}
d {3,4,5,8,10,12,13,14,17}

Answer: {3,4,8,10,12,17,5,14,13}

Consider the following alogorithm


How many times is number 840 printed out when call pattern(840)
a 2
b 4
c 6
d 8

Answer: 2

Consider the following alogorithm:


How many integers will the program print when calling nonTail(n), n > 0.
a 2n
b 2n - 1
c 2n
d 2n -1

Answer: 2n - 1
Consider the following alogorithm:
The above algorithm is used to:
a Count number of even values in binary tree.
b Print even numbers in binary tree.
c Print even numbers in ascending order.
d Print and count number of even values in binary tree.

Answer: Print even numbers in binary tree.

Consider the following alogorithm:


a Count number of nodes in binary tree.
b Calculate height of binary tree.
c Count number of nonterminal nodes in binary tree.
d None of the others.

Answer: Calculate height of binary tree.

Consider the following alogorithm:


The above algorithm is used to:
a Check whether binary tree is balanced.
b Check whether height of left subtree is greater than height of right subtree.
c Check whether height of right subtree is greater than height of left subtree.
d None of the others.

Answer: Check whether binary tree is balanced.


Question 1:Which statements are true about inheritance?
[Link] Java the extends clause is used to specify inheritance
b.A subclass must define all the methods from the superclass.
c.A class can extend any number of other classes.
[Link] of the others.
Answer:In Java the extends clause is used to specify inheritance

Question 2:Which statements are true about interfaces?


[Link] keyword implements is used to specify that a class inherits from an interface
[Link] of an interface can always be declared static.
[Link] can extend any number of other interfaces.
[Link] of the others.
Answer:Interfaces can extend any number of other interfaces.

Question 3:Which statements are false about modifiers?


[Link] (int i=10; i=0; i--) {}
[Link] (int i=0, j=100; i<j; i++, --j) {;}
[Link] i, j; for (j=100; i<j; j--) { i += 2; }
[Link] i=100; for ((i>0); i--) {}
Answer:for (int i=0, j=100; i<j; i++, --j) {;}

Question 4: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?
a.(temp == null)
b.([Link] == null)
c.([Link] == null)
[Link] of the above.
Answer:([Link] == null)

Question 5:Suppose temp refers to a node in a linked list (using the SLLNode class
with instance variables called info and next). What statement changes temp so that
it refers to the next node?
[Link]++;
[Link]=next;
[Link]+=next;
[Link]=[Link];
Answer:temp=[Link];

Question 6:Which boolean expression indicates whether the data in two nodes (p and
q) are the same. Assume that neither p nor q is null.
a.p==q;
[Link]==[Link];
[Link]=[Link];
[Link] of the others
Answer:.[Link]==[Link];

Question 7:Which of these operations are likely to have a constant time for worst-
case in the linked lists?
[Link] (add a new element into before an element in the list)..
[Link] (count number of an element’s present times in the list).
[Link] (remove an element in the list).
[Link] of the others.
Answer:None of the others.

Question 8:The operation for adding an entry to a stack is traditionally called:


[Link]
[Link]
[Link]
[Link]
Answer:push

Question 9:In the array version of the Queue, which operations require O(n) time
for their worst-case behavior?
[Link]
[Link] when the capacity has not yet been reached
[Link]
[Link] of the others
Answer:None of the others

Question 10:Which of the following applications may use a stack?


a.A parentheses balancing program.
[Link] track of local variables at run time.
[Link] analyzer for a compiler.
[Link] of the others.
Answer:All of the others.

Question 11:In the linked-list version of the Queue, which operations require
linear time for their worst-case behavior?
[Link]
[Link]
[Link]
[Link] of the others
Answer:None of the others

Question 12:When a method call is executed, which information is not saved in the
activation record?
[Link] variables
[Link] where the method should return when done.
[Link] depth of recursion.
[Link] for all parameters to the method.
Answer:Current depth of recursion.
Question 13:When the compiler compiles your program, how is a recursive call
treated differently than a non-recursive method call?
[Link] values are all treated as reference variables
[Link] variables are all treated as primitive values
[Link] is no duplication of local variables
[Link] of the others
Answer:None of the others

Question 14:
a.
b.
c.
d.
Answer:

Question 15:Select the one TRUE statement.


[Link] binary tree is either balanced or perfect balanced.
[Link] balanced binary tree is also a perfect balanced binary tree.
[Link] perfect balanced binary tree is also a balanced binary tree.
[Link] binary tree is both balanced and perfect balanced.
Answer:Every perfect balanced binary tree is also a balanced binary tree.

Question 16:________ is visiting node starting from the highest (or lowest) level
and moving down (or up) level by level, visiting nodes on each level from left to
right (or from right to left).
[Link]-First Traversal
[Link]-First Traversal
[Link] Depth-First Traversal
[Link] of the others
Answer:Breath-First Traversal

Question 17:________ rebalances the tree globally; each and every node could have
been involved in rebalancing either by moving data from nodes or by creasing new
values to reference fields.
[Link] DSW Algorithm
[Link] classical method has been proposed by Adel’son – Vel’skii and Landis (AVL
tree).
[Link] of the others
[Link] of the others
Answer:The DSW Algorithm

Question 18:A heap is an exellent way to implement a ________


[Link]
[Link]
[Link] queue
[Link].
Answer:priority queue

Question 19:What is the expected number of operations needed to loop through all
the edges terminating at a particular vertex given an adjacency matrix
representation of the graph? (Assume n vertices are in the graph and m edges
terminate at the desired node).
a.O(m)
b.O(n)
c.O(m2)
d.O(n2)
Answer:O(n)

Question 20:What graph traversal algorithm uses a queue to keep track of vertices
which need to be processed?
[Link]-first search.
[Link]-first search.
c.
d.
Answer:Breadth-first search.

Question 21:Suppose you have a directed graph representing all the flights that an
airline flies. What algorithm might be used to find the best sequence of
connections from one city to another?
[Link] first search.
[Link] first search.
c.A cycle-finding algorithm.
d.A shortest-path algorithm.
Answer:A shortest-path algorithm.

Question 22:The final exams at a university can be scheduled so that no


student has two exams at the same time by applying __________
[Link] coloring
[Link]
[Link] sort
[Link] graph
Answer:Graph coloring

Question 23:What is the worst-case time for mergesort to sort an array of n


elements?
a.O(nlgn)
b.O(n)
c.O(n2)
d.O(lgn)
Answer:O(nlgn)

Question 24:What is the worst-case time for bublesort to sort an array of n


elements?
a.O(nlgn)
b.O(n)
c.O(n2)
d.O(lgn)
Answer:O(n2)

Question 25:What is the worst-case time for heapsort to sort an array of n


elements?
a.O(nlgn)
b.O(n)
c.O(n2)
d.O(lgn)
Answer:O(nlgn)

Question 26:In a selectionsort of n elements, how many times are the array elements
moved in the worst case?
a.O(nlgn)
b.O(n)
c.O(n2)
d.O(lgn)
Answer:O(n)

Question 27:What is the worst-case time for binary search finding a single item in
an array?
[Link] time
[Link] time
[Link] time
[Link] time
Answer:Logarithmic time

Question 28:What is the best definition of a collision in a hash table?


[Link] entries are identical except for their keys.
[Link] entries with different data have the exact same key.
[Link] entries with different keys have the same exact hash value
[Link] entries with the exact same key have different hash values.
Answer:have the same exact hash value

Question 29:A chained hash table has an array size of 512. What is the maximum
number of entries that can be placed in the table?
a.256
b.511
c.512
d.1024
[Link] is no maximum
Answer:There is no maximum

Question 30:Suppose you place m items in a hash table with an array size of s. What
is the correct formula for the load factor?
a.s + m
b.s/m
c.s * m
d.m/s
e.m - s
Answer:m/s

Question 31:Which of the following data structure can be implement Huffman Coding
[Link] linked list.
[Link] queue.
[Link] of the others
[Link] linked list.
Answer:All of the others

Question 32:Select incorrect statements about restrictions need to be imposed on


the prospective codes:
[Link] codeword may corresponds to one or many symbols.
[Link] that symbols and have probabilities of occurrence , . If , then ,
where and .
[Link] should not require any look ahead.
[Link] should not be any unused short codewords either as stand-alone encodings or
as prefixes for longer codewords.
Answer:Each codeword may corresponds to one or many symbols.

Question 33:Select correct statement about Run-length encoding.


a.A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs.
[Link]-length encoding is very useful when applied to files that are almost
guaranteed to have many runs of at least five characters.
[Link] of the others.
[Link] of the others.
Answer:A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs.

Question 34:Select correct statement about Ziv-Lempel Code.


[Link]-Lempel Code uses buffer of symbols.
[Link] codeword of Ziv-Lempel Code is a triple.
[Link] of the others.
[Link] of the others.
Answer:All of the others.

Question 35:Which statement is true about the following code?


a.Interface1 and Interface2 do not match, therefore, MyClass cannot implement them
both.
[Link] declarations of void g() in the two interfaces conflict, therefore, the code
will not compile.
[Link] declarations of int VAL_B in the two interfaces conflict, therefore, the code
will not compile.
[Link] is wrong with the code, it will compile without errors.
Answer:Nothing is wrong with the code, it will compile without errors.

Question 36:What will be the result of attempting to compile and run the following
program?
[Link] program will fail to compile.
[Link] program will compile without error and print 0 when run.
[Link] program will compile without error and print 1 when run.
[Link] program will compile without error and print 2 when run.
Answer:and print 2 when run

Question 37:Which digits, and in which order, will be printed when the following
program is run?
[Link] program will only print 1 and 4, in that order.
[Link] program will only print 1, 4, and 5, in that order.
[Link] program will only print 3 and 5, in that order.
[Link] program will only print 1, 2, 4, and 5, in that order.
Answer:1, 4, and 5, in that order.

Question 38:What is written to the screen for the input "ABBAABBA"?


[Link]
[Link]
[Link]
[Link]
Answer:ABBAABBA

Question 39:What values of number are directly handled by the stopping case?
[Link] < 0
[Link] < 10
[Link] >= 0 && number < 10
[Link] > 10
Answer:number >= 0 && number < 10

Question 40:Number of comparisons of keys and comparisons of i and least is:


a.n(n-1)\2
b.n-1
c.(n-1)(n+2)\2
[Link] of the others.
Answer:(n-1)(n+2)\2

Question 41:Assume that this algorithm is executed with array {7,1,2,3,4,5,6}. What
is output after iteration i=4 of the outer for loop completed
a.1, 2, 3, 4, 5, 6, 7
b.1, 2, 3, 7, 4, 5, 6
c.1, 2, 3, 4, 5, 7, 6
d.1, 2, 3, 4, 7, 5, 6
Answer:1, 2, 3, 4, 5, 7, 6
Question 42:Number of comparisons of keys is
a.n(n+1)\2
b.n(n-1)\2
c.n^2
d.n^2\2
Answer:n(n-1)\2

Question 43:Which traversal does the above algorithm implement?


[Link]-first traversal
[Link] tree traversal
[Link] tree traversal
[Link] tree traversal
Answer:Preorder tree traversal

Question 44:Select correct statements when applying this algorithm to a n-element


array:
[Link]() is called times to create the heap in the first phase.
[Link] heap is restored times in the second phase.
[Link] the second phase, this algorithm exchanges times the root with the element in
position.
[Link] of the others.
Answer:All of the others.

Question 45:How many asterisks are printed by the method call quiz(5)?
a.8
b.4
c.7
[Link] of the others.
Answer:7

Question 46:What is output if this algorithm is executed on the following binary


tree:
a.40 30 7 10 11 3 1 2 14
b.1 3 2 7 10 40 30 11 14
c.1 2 3 14 7 10 11 40 30
d.14 2 1 3 11 10 7 30 40
Answer:40 30 7 10 11 3 1 2 14

Question 47:What is output if this algorithm is executed on the following binary


tree2:
a.3
b.9
c.5
d.8
Answer:5

Question 48:Which statement, when inserted at the indicated position in the


following code, will cause a runtime exception?
a.x = y;
b.z = x;
c.y = (B) x;
d.z = (C) y;
e.y = (A) y;
Answer:

Question 49:Which statements are false about modifiers?


a.A final methods or field cannot be changed by derived classes.
[Link] and fields declared public can be used by any other object.
[Link] default modifier means that a method or a field is a accessible to derived
classes.
[Link] of the others.
Answer:The default modifier means that a method or a field is a accessible to
derived classes.

Question 50:A method within a class is only accessible by classes that are defined
within the same package as the class of the method. How can such a restriction be
enforced?
[Link] the method with the keyword public.
[Link] the method with the keyword protected.
[Link] the method with the keyword private.
[Link] not declare the method with any accessibility modifiers.
Answer:Do not declare the method with any accessibility modifiers.

Question 51:Which are invalid identifiers?


a._class
b.$value$
[Link]@
d.Angs_trom
Answer:zer@

Question 52:Which statement concerning the switch construct is true?


[Link] switch statements must have a default label.
b.A character literal can be used as a value for a case label
[Link] keyword continue can never occur within the body of a switch statement.
[Link] of the others.
Answer:A character literal can be used as a value for a case label

Question 53:If str denotes a String object with the string "73", which of these
expressions will convert the string to the int value 73?
a.(new Integer(str)).intValue()
[Link](str)
[Link](str)
d.((int) str)
Answer:(new Integer(str)).intValue()

Question 54:Select correct statements about a singly linked list.


[Link] lists allow random access to any node.
b.A node with a specified value (info) can be found by traversing the list.
[Link] of the others
[Link] of the others
Answer:A node with a specified value (info) can be found by traversing the list.

Question 55:Advantages which linked list have over an array:


[Link] searching.
[Link] of the others.
[Link] of the others.
[Link] can be expanded and shrunk rapidly.
Answer:Size can be expanded and shrunk rapidly.

Question 56:Which of the following methods take O(n) time for the worst case:
[Link] a node into any position in Linked List.
[Link] a node in position which is followed by the last node.
[Link] of the others.
[Link] of the others.
Answer:All of the others

Question 57:Select correct statements about a singly linked list.


a.A new node can be inserted into any position, except first position, without any
traversal.
[Link] a node at the beginning of a list involves setting head to point to
[Link].
[Link] of the others.
[Link] of the others.
Answer:Deleting a node at the beginning of a list involves setting head to point to
[Link].

Question 58:Propertie of a stack is:


[Link]-items can be accessed at once.
[Link] one item can be accessed at once.
[Link] of the others.
d.
Answer:Only one item can be accessed at once.

Question 59:Properties of a queue are:


[Link] one item can be accessed at once.
[Link]-items can be accessed at once.
[Link] of the others.
d.
Answer:Only one item can be accessed at once.

Question 60:In the array version of the Stack class, which operations require
linear time for their worst-case behavior?
a.is_empty
[Link]
[Link]
[Link] when the array is not yet full.
[Link] of these operations require linear time.
Answer:None of these operations require linear time.

Question 61:In the linked-list version of the Stack class, which operations require
linear time for their worst-case behavior? Assume that addtoTail, deletefromTail
are used.
a.is_empty
[Link]
[Link]
[Link] when the array is not yet full.
[Link] of these operations require linear time.
Answer:pop

Question 62:Select wrong statements:


[Link] is always more efficient than loops.
[Link] can make the conceptual design of an algorithm’s implementation easier.
[Link] gone wrong can lead to overflow stack errors
[Link] can be only replaced by iteration.
Answer:Recursion is always more efficient than loops.

Question 63:In a single method declaration, what is the maximum number of


statements that may be recursive calls?
a.1
b.2
c.n (where n is the argument).
[Link] is no fixed maximum
Answer:There is no fixed maximum

Question 64:The problem of printing an input line in reverse order can be


implemented using:
[Link].
[Link].
[Link].
[Link] of others
Answer:Recursion

Question 65:Which of the following statements are true:


[Link] algorithm end after finding one solution.
[Link] algorithm does not find symmetric solutions.
[Link] algorithm finds all solutions.
d.
Answer:The algorithm finds all solutions.

Question 66:On average, what is the maximum number of comparisons needed to find a
key in a balanced binary search tree with 1 million nodes?
a.10
b.15
c.20
d.30
Answer:20

Question 67:To delete a node in a binary search tree that has two children, the
Deletion by Merging method requires to find what node?
[Link] rightmost node of the left subtree of the deleted node.
[Link] smallest sibling node.
[Link] parent node.
[Link] of the others.
Answer:The rightmost node of the left subtree of the deleted node.

Question 68:Tree balancing can be performed locally after an element is inserted


into or deleted from the tree using………………….
[Link] DSW algorithm.
[Link] tree.
[Link] a binary search tree from an ordered array.
[Link] of the others.
Answer:AVL tree.
Question 69:The DSW Algorithm uses:
[Link] rotation.
[Link] rotation.
[Link] of the others.
[Link] of the others.
Answer:All of the others.

Question 70:The depth-first search algorithm for a graph:


[Link] for the minimal edges needed to visit each vertex in the graph.
[Link] all possible paths from a vertex to see if it can find the destination
before it moves on to the adjacent vertices.
[Link] all adjacent vertices before moving down the paths to find the
destination.
[Link] of the others.
Answer:Travels all possible paths from a vertex to see if it can find the
destination before it moves on to the adjacent vertices.

Question 71:Select right statements:


[Link]'s shortest path algorithm can be applied to undirected graph.
[Link] breadth-first search can be used to find the shortest path from a source
vertex to the destination vertex
[Link] of the others.
[Link] of the others.
Answer:All of the others.

Question 72:Two algorithms which used for finding a minimum spanning tree are
Kruskal and Dijkstra. Which algorithm uses the cycle detection method?
[Link] Kruskal algorithm.
[Link] Dijkstra algorithm.
[Link] of the others.
[Link] of the others.
Answer:All of the others.

Question 73:Which of the following statements about shortest path finding


algorithms are true:
[Link]’s algorithm is label-setting algorithm.
[Link]’s algorithm can be applied to graphs have negative weights.
[Link] complexity of Dijkstra’s algorithm is O(|V|), where |V| is number of vertices
of graph.
[Link] of the others.
Answer:Dijkstra’s algorithm is label-setting algorithm.

Question 74:When is Insertionsort a good choice for sorting an array?


[Link] component of the array requires a large amount of memory.
[Link] component of the array requires a small amount of memory.
[Link] array has only a few items out of place.
[Link] processor speed is fast.
Answer:The array has only a few items out of place.

Question 75:Mergesort makes two recursive calls. Which statement is true after
these recursive calls finish, but before the merge step?
[Link] array elements form a heap.
[Link] in each half of the array are sorted amongst themselves.
[Link] in the first half of the array are less than or equal to elements in the
second half of the array.
[Link] of the others
Answer:Elements in each half of the array are sorted amongst themselves.

Question 76:Suppose we are sorting an array of eight integers using a some


quadratic (O(n2))) sorting algorithm. After four iterations of the algorithm's main
loop, the array elements are ordered as shown here:
2 4 5 7 8 1 3 6
Which statement is correct?
[Link] algorithm might be either selectionsort or insertionsort.
[Link] algorithm might be selectionsort, but it is not insertionsort.
[Link] algorithm is not selectionsort, but it might be insertionsort.
[Link] algorithm is neither selectionsort nor insertionsort.
Answer:not selectionsort, but it might be insertionsort.

Question 77:In Quicksort, the bound value (pivot) is:


[Link] first item of array.
[Link] middle item of array.
[Link] last item of array.
[Link] of the others.
Answer:All of the others.

Question 78:The more complex the hashing functions, the better it is


[Link]
[Link]
c.
d.
Answer:[Link]
Question 79:Which of the following methods are used to collision resolution:
[Link]
[Link]’s method.
[Link] addressing.
[Link]
Answer:Open addressing.

Question 80:Which of the following hashing methods can cause collision:


[Link]
[Link]
[Link]-Square
[Link]
[Link] of others
Answer:All of others

Question 81:Select incorrect statements:


[Link] probing eliminates primary clustering but suffers from the less severe
secondary clustering.
[Link] double hashing the step size depends on the key and is obtained from a
secondary hash function.
[Link] quadratic probing the offset from x is the square of the step number, so the
probe goes to x, x+1, x+2, x+3, x+4, and so on.
[Link] of the others.
Answer:In quadratic probing the offset from x is the square of the step number, so
the probe goes to x, x+1, x+2, x+3, x+4, and so on.

Question 82:Assume that encoding of three symbols X, Y, W, Z is:


V: 10
X: 010
Y: 101
W: 100
Z: 110
Which of the following restrictions does this encoding violate:
[Link] codeword corresponds to exactly one symbol.
[Link] codeword is a prefix of another codeword.
[Link] length of the codeword for a given symbol mj should not exceed the length of
the codeword of a less probable symbol m¬i.
[Link] of otehrs
Answer:No codeword is a prefix of another codeword.

Question 83:Select incorrect statements about Data compression:


[Link] algorithm can be implemented using priority queue.
[Link] algorithm applied to case of the probabilities of symbol are known in
advance.
[Link] algorithm can be only applied to text files.
[Link] of the others
Answer:Huffman algorithm can be only applied to text files.

Question 84:The Huffman algorithm always produces a unique binary tree.


[Link]
[Link]
c.
d.
Answer:False

Question 85:Select incorrect statements about Data compression:


[Link] tree can be only constructed bottom-up.
[Link] adaptive Huffman encoding, sibling property is retained assures the Huffman
tree under construction is still a Huffman tree.
[Link] of the others.
[Link] of the others.
Answer:Huffman tree can be only constructed bottom-up.

Question 86:Given the following interface definition, which definition is valid?


Which expressions will evaluate to true if preceded by the following code?
a.(a == "Hello")
b.(a == b)
c.(a == c)
[Link](b)
Answer:[Link](b);(a == c)

Question 87:is output when calling TriangularNumber(4)


a.6
b.10
c.15
d.20
Answer:10

Question 88:What is maximum number of activation records (including its caller) in


runtime stack when calling TriangularNumber(10)
a.7
b.9
c.11
d.13
Answer:11

Question 89:What is maximum number of activation records (including its caller) in


runtime stack when traversing the below tree using the above algorithm?
a.4
b.5
c.3
d.6
Answer:5

Question 90:Assume array data[] = {2,8,6,1,10,15,3,12,11}. Array data after ending


the first loop.
a.{15,12,2,11,10,6,3,1,8}
b.{15,12,6,11,10,2,3,1,8}
c.{8,12,6,11,10,2,3,1,15}
[Link] of the others
Answer:{15,12,6,11,10,2,3,1,8}

Question 91:Select right statements:


[Link] the first loop, moveDown is called n/2 times in any case.
[Link] total number of moves in all executions of moveDown in the second phase is
O(lgn).
[Link] of the others.
[Link] of the others.
Answer:In the first loop, moveDown is called n/2 times in any case.

Question 92:What will be printed when the following program is run?


a.0
b.1
c.2
[Link] error occurs when compiling the program.
Answer:
Question 93:What will be printed when the following program is run?
a.“this is g of A”
b.“this is g of C”
[Link] error occurs when compiling the program.
[Link] is printed.
Answer: this is g of C

Question 94:Assume array data[] = {4,10,8,3,12,17,5,14,13}. Array data after


executing 4 iterations of outer loop.
a.{3,4,8,10,12,17,5,14,13}
b.{3,4,10,8,12,17,5,14,13}
c.{10,8,4,3,12,17,5,14,13}
d.{3,4,5,8,10,12,13,14,17}
Answer:{3,4,8,10,12,17,5,14,13}

Question 95:How many times is number 840 printed out when call pattern(840)
a.2
b.4
c.6
d.8
Answer:2

Question 96:How many integers will the program print when calling nonTail(n), n >
0.
a.2^n
b.2^n-1
c.2n
d.2n-1
Answer:2^n-1

Question 97:The above algorithm is used to:


[Link] number of even values in binary tree.
[Link] even numbers in binary tree.
[Link] even numbers in ascending order.
[Link] and count number of even values in binary tree.
Answer:in binary tree.

Question 98:The above algorithm is used to:


[Link] number of nodes in binary tree.
[Link] height of binary tree.
[Link] number of nonterminal nodes in binary tree.
[Link] of the others.
Answer:Calculate height of binary tree.

Question 99:above algorithm is used to:


[Link] whether binary tree is balanced.
[Link] whether height of left subtree is greater than height of right subtree.
[Link] whether height of right subtree is greater than height of left subtree.
[Link] of the others.
Answer:Check whether binary tree is balanced.

Question 100:
a.
b.
c.
d.
Answer:
Quiz Chapter 03
Question 1
Marks: 1
Which of the following operations are implemented in the ArrayList class belongs to
the [Link] package:
Choose one answer.
a. Update one element in any position in the ArrayList.
b. Add one element to any position in the ArrayList.
c. All of the others.
d. Retrieve one element from any position in the ArrayList.
Answer: All of the others.
Question 2
Marks: 1
If an algorithm is constantly accessing only some elements such as the first, the
second, the last and the like, and if changing the structure is very important to
the algorithm then solution is using:
Choose one answer.
a. Linked list.
b. Array.
c. None of the others
Answer: Linked list.
Question 3
Marks: 1
Select correct statement(s) about Doubly Linked List:
Choose at least one answer.
a. Deleting a node at the end of the list takes time O(1) .
b. Methods for processing doubly linked list are simpler than those of singly
linked list.
c. Inserting a new node at the end of the list requires O( n ) steps.
d. Processing for adding a node to the end of list includes six steps.
Answer: Deleting a node O(1)+ Inserting a new node O( n )
Question 4
Marks: 1
The advantage of arrays over linked lists is that they allow random accessing.
Answer: True
Question 5
Marks: 1
Elements of a linked list must be consecutive memory cells.
Answer: False

Quiz Chapter 04
Question 1
Marks: 1
In the array implementation, enqueuing can be executed in constant time O(1)
Answer: True
Question 2
Marks: 1
Select false statement:
Choose one answer.
a. All of the others.
b. In the array list implementation, popping is executed in constant time
O(1).
c. In the array list implementation, poping is executed in O(lgn) to the
worst case.
d. Stack can be implemented using linked list.
Answer: In the array list implementation, poping is executed in O(lgn) to the worst
case.
Question 3
Marks: 1
Which of the following about queue are true:
Choose one answer.
a. A queue is a structure in which adding and removing elements only take
place at one end.
b. None of the others.
c. A queue is an FIFO structure.
d. A queue is a structure in which each end can be used for adding new
elements and removing them.
Answer: A queue is an FIFO structure.
Question 4
Marks: 1
In the array implementation, dequeuing can be executed in time O(n)
Answer: False
Question 5
Marks: 1
In the doubly linked list implementation, enqueuing can be executed in time O(n)
Answer: False

Quiz Chapter 05
Question 1
Marks: 1
Select incorrect statement:
Choose one answer.
a. Recursive definitions are frequently used to define functions and
sequences of numbers.
b. None of the others
c. Recursive definitions serve generating new elements and testing whether an
element belongs to a set.
d. The anchor or ground case allows for the construction of new objects out
of basic elements or objects that have already been constructed.
Answer: The anchor or ground case allows for the construction of new objects out of
basic elements or objects that have already been constructed.
Question 2
Marks: 1
Consider the following recursive function, assuming n is even:
h(n)={1ifn=01+h(n-2)n>1
What is the value of h(20):
Choose one answer.
a. 9
b. 11
c. 12
d. 10
Answer: 11
Question 3
Marks: 1
When converting a method from a recursive version into an iterative version,
Choose at least one answer.
a. The program always runs slower.
b. The brevity of program formulation lost. However, the brevity may not be
an issue in Java.
c. Program clarity can be diminished.
d. The brevity of program formulation lost.
Answer: Program clarity+the brevity of program formulation lost
Question 4
Marks: 1
In all cases, nonrecursive implementation is faster than recursive implementation.
Answer: False
Question 5
Marks: 1
Which of the following statements are true:
Choose at least one answer.
a. The recursive version increases program readability, improves self-
documentation and simplifies coding.
b. The return address is address of the caller's instruction immediately
following the call.
c. In the most cases, the code of nonrecursive implementation is shorter than
it is in the recursive implementation.
d. Global variables are stored in activation record.
Answer: The recursive version increases + The return address is address

Quiz Chapter 06
Question 1
Marks: 1
Which of the following statements about heap are false:
Choose one answer.
a. Heap represented by array can be traversed easily in depth-first.
b. Heaps can be implemented by arrays.
c. John Williams's algorithm uses top-down method which extends the heap by
enqueuing new elements in the heap.
d. Floyd's algorithm uses bottom-up method which merges repetitively small
heaps into larger heaps.
Answer: Heap represented by array can be traversed easily in depth-first.
Question 2
Marks: 1
Which of the following statements are true:
Choose at least one answer.
a. Preorder, inorder and postorder tree traversal generate unambiguous
outputs.
b. Expression trees do not use parentheses.
c. Polish notation is only applied for compilers.
d. In a expression tree, leaves are operators and nonterminal nodes are
operands and.
e. Polish notation eliminates all parentheses from formulas.
Answer: Polish notation eliminates all parentheses from formulas.+ Expression trees
do not use parentheses.
Question 3
Marks: 1
Which operation is used in DSW Algorithm:
Choose one answer.
a. Rotation
b. None of the others
c. All of the others
d. Sorting
Answer: Rotation
Question 4
Marks: 1
Which of the following methods are used to traverse a tree without using any stack
or threads:
Choose one answer.
a. None of the others
b. Traversal through Tree Transformation
c. Recursion
Answer: Traversal through Tree Transformation
Question 5
Marks: 1
Which of the following concepts of binary tree are true:
Choose one answer.
a. The level of a node must be between 1 and height of the tree.
b. The level of a node is the length of the path from the root to the node
plus 1.
c. The height of a nonempty tree is the maximum level of a node in the tree.
d. All of the others
Answer: All of the others

Quiz Chapter 08
Question 1
Marks: 1
Which graph representation is best?
Choose one answer.
a. It depends on the problem.
b. Adjacency matrix
c. Incidence matrix
d. Adjacency list
e. None of the others.
Answer: It depends on the problem.
Question 2
Marks: 1
Which of the following statements about finding the shortest path are true:
Choose one answer.
a. The complexity of Dijkstra's algorithm is O(|V|2)
b. Ford's algorithm relies on label-setting method.
c. The complexity of Ford's algorithm is O(|V||E|) for any graph.
d. The complexity of Dijkstra's algorithm using heap is O(|V|ln|V|)
Answer: The complexity of Dijkstra's algorithm is O(|V|2)
Question 3
Marks: 1
Which of the following sentences are true:
Choose at least one answer.
a. The complexity of DFS for graph traveral is O(|V|+|E|) .
b. The complexity of DFS for graph traversal is (O|V|lg|V|) if an adjacency
matrix is used
c. To prevent loop from happen in an algorithm for traversing a graph, each
visited vertex can be marked.
d. All algorithms are more efficient if the underlying graph traversal is not
BFS but DFS.
Answer: DFS O(|V|+|E|) + prevent loop from happen in an algorithm for traversing a
graph, each visited vertex can be marked.
Question 4
Marks: 1
Which of the following statements about graph coloring is true:
Choose at least one answer.
a. In sequential coloring algorithm, vertices must be ordered according to
indices already to the vertices.
b. The complexity of sequential Coloring algorithm is O(|V|2) .
c. In sequential coloring algorithm, vertices must be ordered according to
degree of vertices.
d. Sequential Coloring algorithm establishes the sequence of vertices and a
sequence of color before coloring them.
Answer: Coloring algorithm is O(|V|2) + the sequence of vertices and a sequence of
color before coloring them.
Question 5
Marks: 1
Most of the label-setting and label-correcting methods are used to find the
shortest paths from one vertex to all other vertices.
Answer: True

Quiz Chapter 09
Question 1
Marks: 1
Which of the following statements about efficient sorting is true:
Choose at least one answer.
a. Only insertion sort is apllied in all h-sorts of shell sort.
b. There is no which sequence of increments is optimal.
c. Shell sort is more efficient than insertion sort even if in case there are
only two increments.
d. Shell sort divides physically the original array into subarrays and sorts
them separately.
Answer: divides physically+Only insertion sort
Question 2
Marks: 1
Which of the following statements about elementary sorting is true:
Choose one answer.
a. All of others.
b. Advantage of using insertion sort is that it sorts the array only when is
really necessary.
c. In the worst case of bubble sort, number of swaps is n(n-1)4
Answer: Advantage of using insertion sort is that it sorts the array only when is
really necessary.
Question 3
Marks: 1
Select correct statements about Radix sort:
Choose at least one answer.
a. bitRadixsort() is faster than radixsort().
b. bitRadixsort() can be improved by implementing array instead of using
queue.
c. Radix sort is used only for string sorting.
d. One of techniques radix sort uses is by looking at each number as a string
of bits so that all integers are of equal length.
Answer: bitRadixsort() array instead of using queue. + by looking at each number as
a string of bits
Question 4
Marks: 1
In Insertion sort, which case is only one comparison made for each position i:
Choose one answer.
a. The data are in reverse order
b. None of the others.
c. The data are in random order.
d. The data are already in order.
Answer: The data are already in order.
Question 5
Marks: 1
Consider Insertion sort algorithm for a n-element array. The number of times
variable tmp is loaded and unloaded in the outer for loop is:
Choose one answer.
a. 2(n-1) in the best case.
b. 2(n-1) in the worst case.
x c. All of the others.
Answer: All of the others.

Quiz Chapter 10
Question 1
Marks: 1
Which of the following statement about Perfect Hash Functions are true:
Choose at least one answer.
a. The searching process in Cichelli's algorithm is linear.
b. Cichelli's algorithm guarantees that a perfect hash function can be found.

c. Cichelli's method uses an exhaustive search.


d. Cichelli's method is used to hash relatively small number of reserved
words.
Answer: exhaustive search.+hash relatively
Question 2
Marks: 1
Which of the following statement is true:
Choose one answer.
a. To create a hash function, the hashing table has to contain at least the
same number of positions as the number of elements being hashed.
b. If hash function transforms different keys into different numbers, it is
called a perfect hash function.
c. All of the others.
Answer: All of the others.
Question 3
Marks: 1
Select correct statements:
Choose at least one answer.
a. In shift folding method, the key is usually divided into even parts of
some fixed size plus some remainder and added.
b. The shift folding method can be applied to string data.
c. In boundary folding method, the key is usually divided into even parts of
not fixed size plus some remainder and added.
d. The boundary folding method can not be applied to string data.
Answer: shift ,plus some remainder and added+ boundary , can not be applied to
string data.
Question 4
Marks: 1
Which of the following statement about Open Addressing are false:
Choose at least one answer.
a. In linear probing of the open addressing method, the position in which key
can be stored is found by sequentially searching starting from the begin of table.
b. Using quadratic probing gives much better results than linear probing and
avoids the problem of cluster buildup.
c. For quadratic probing, the size of table should not be an even number.
d. Linear probing has a tendency to create clusters in the table.
Answer: In linear probing of the open addressing+ Using quadratic probing
Question 5
Marks: 1
Hash function is function that can transform a particular key (K) (a string, number
or record) into an index in the table used for storing items of the same type as K.
Answer: True

Quiz Chapter 11
Question 1
Marks: 1
The length of the codeword for a given symbol mj should not less than the length of
the codeword of a less probable symbol mi; that is, if P(mi)=P(mj), then
L(mi)=L(mj) for 1=i, j=n
Answer: False
Question 2
Marks: 1
In data compression, no special punctuation is required to separate two codewords
in a coded message.
Answer: True
Question 3
Marks: 1
Select correct statement about Ziv-Lempel Code.
Choose one answer.
a. Ziv-Lempel Code uses buffer of symbols.
b. All of the others.
c. The codeword of Ziv-Lempel Code is a triple.
Answer: All of the others.
Question 4
Marks: 1
Which of the following data structure can be used to implement Huffman Coding
Choose at least one answer.
a. Heap.
b. Doubly linked list.
c. Binary tree.
d. Stack list.
e. Queue.
Answer: Heap + Doubly linked list + Binary tree.
Question 5
Marks: 1
Run-length encoding is very efficient for text file in which only blank character
has a tendency to be repeated without using any technique.
Answer: True

Q1 Which statements are true about inheritance?


Answer: In Java the extends clause is used to specify inheritance

Q2 Which statements are true about interfaces?


Answer: Interfaces can extend any number of other interfaces.

Q3 Which one of these for statements is valid


Answer: for (int i=0, j=100; i<j; i++, --j) {;}

Q4 Which statements are false about modifiers?


Answer: The default modifier means that a method or a field is a accessible to
derived classes.

Q5 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?
Answer: ([Link] == null)

Q6 Suppose temp refers to a node in a linked list (using the SLLNode class with
instance variables called info and next). What statement changes temp so that it
refers to the next node?
Answer: temp = [Link];

Q7 Which boolean expression indicates whether the data in two nodes (p and q) are
the same. Assume that neither p nor q is null.
Answer: [Link] == [Link]

Q8 The operation for adding an entry to a stack is traditionally called:


Answer: push

Q9 Which of these operations are likely to have a constant time for worst-case in
the linked lists?
Answer: None of the others.

Q10 In the array version of the Queue, which operations require O(n) time for their
worst-case behavior?
Answer: None of the others

Which of the following applications may use a stack?


Answer: All of the others.

In the linked-list version of the Queue, which operations require linear time for
their worst-case behavior?
Answer: None of the others

When a method call is executed, which information is not saved in the activation
record?
Answer: Current depth of recursion.

When the compiler compiles your program, how is a recursive call treated
differently than a non-recursive method call?
Answer: None of the others.

Select the one TRUE statement.


Every binary tree is either balanced or perfect balanced.
Every balanced binary tree is also a perfect balanced binary tree.
Every perfect balanced binary tree is also a balanced binary tree.
No binary tree is both balanced and perfect balanced.
Answer: Every perfect balanced binary tree is also a balanced binary tree.

……………………… is visiting node starting from the highest (or lowest) level and moving
down (or up) level by level, visiting nodes on each level from left to right (or
from right to left).
Answer: Breath-First Traversal

……………..rebalances the tree globally; each and every node could have been involved
in rebalancing either by moving data from nodes or by creasing new values to
reference fields.
Answer: DSW Algorithm

A heap is an exellent way to implement a ……………..


Answer: priority queue

What is the expected number of operations needed to loop through all the edges
terminating at a particular vertex given an adjacency matrix representation of the
graph? (Assume n vertices are in the graph and m edges terminate at the desired
node).
Answer: O(n)

What graph traversal algorithm uses a queue to keep track of vertices which need to
be processed?
Answer: Breadth-first search.

Suppose you have a directed graph representing all the flights that an airline
flies. What algorithm might be used to find the best sequence of connections from
one city to another?
Answer: A shortest-path algorithm.

The final exams at a university can be scheduled so that no


student has two exams at the same time by applying ……………
Answer: Graph coloring

What is the worst-case time for mergesort to sort an array of n elements?


Answer: O(nlgn)

What is the worst-case time for bublesort to sort an array of n elements?


Answer: O(n2)
What is the worst-case time for heapsort to sort an array of n elements?
Answer: O(nlgn)

In a selectionsort of n elements, how many times are the array elements moved in
the worst case?
Answer: O(n)

What is the worst-case time for binary search finding a single item in an array?
Answer: Logarithmic time

What is the best definition of a collision in a hash table?


Answer: Two entries with different keys have the same exact hash value.

A chained hash table has an array size of 512. What is the maximum number of
entries that can be placed in the table?
Answer: m/s

Which of the following data structure can be implement Huffman Coding


Answer: All of the others

Select incorrect statements about restrictions need to be imposed on the


prospective codes:
Answer: Each codeword may corresponds to one or many symbols.

Select correct statement about Run-length encoding.


Answer: A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs.

Select correct statement about Ziv-Lempel Code.


Answer: All of the others.

What is written to the screen for the input "ABBAABBA"?


Answer: ABBAABBA

What values of number are directly handled by the stopping case?


number < 0
number < 10
number >= 0 && number < 10
number > 10
Answer: number >= 0 && number < 10

Number of comparisons of keys and comparisons of i and least is:


Answer: ((n-1)(n+2))/2

Assume that this algorithm is executed with array {7,1,2,3,4,5,6}. What is output
after iteration i=4 of the outer for loop completed
Answer: 1, 2, 3, 4, 5, 7, 6

Number of comparisons of keys is


Answer: n*(n-1)/2

Which traversal does the above algorithm implement?


Breadth-first traversal
Inorder tree traversal
Postorder tree traversal
Preorder tree traversal
Answer: Preorder
Select correct statements when applying this algorithm to a n-element array:
moveDown() is called times to create the heap in the first phase.
The heap is restored times in the second phase.
In the second phase, this algorithm exchanges times the root with the element in
position.
All of the others.
Answer: All of the others.

How many asterisks are printed by the method call quiz(5)?


Answer: 7

What is output if this algorithm is executed on the following binary tree:


40 30 7 10 11 3 1 2 14
1 3 2 7 10 40 30 11 14
1 2 3 14 7 10 11 40 30
14 2 1 3 11 10 7 30 40

Answer: 40 30 7 10 11 3 1 2 14

3
9
5
8
Answer: 5

Which statement, when inserted at the indicated position in the following code,
will cause a runtime exception?
x = y;
z = x;
y = (B) x;
z = (C) y;
y = (A) y;
Answer: y = (B) x;

A method within a class is only accessible by classes that are defined within the
same package as the class of the method. How can such a restriction be enforced?
Answer: Do not declare the method with any accessibility modifiers.

Which are invalid identifiers?


_class
$value$
zer@
Angs_trom
Answer: zer@

Which statement concerning the switch construct is true?


All switch statements must have a default label.
A character literal can be used as a value for a case label
The keyword continue can never occur within the body of a switch statement.
All of the others.
Answer: A character literal can be used as a value for a case label

If str denotes a String object with the string "73", which of these expressions
will convert the string to the int value 73?
Answer: new Integer(str)).intValue()

Select correct statements about a singly linked list.


Linked lists allow random access to any node.
A node with a specified value (info) can be found by traversing the list.
All of the others
None of the others.

Answer: A node with a specified value (info) can be found by traversing the list.

Advantages which linked list have over an array:


Answer: Size can be expanded and shrunk rapidly.

Which of the following methods take O(n) time for the worst case:
Answer: All of the others.

Select correct statements about a singly linked list.


A new node can be inserted into any position, except first position, without any
traversal.
Deleting a node at the beginning of a list involves setting head to point to
[Link].
All of the others.
None of the others.
Answer: Deleting a node at the beginning of a list involves setting head to point
to [Link].

Properties of a stack is:


Answer: Only one item can be accessed at once.

Properties of a queue are:


Answer: Only one item can be accessed at once.

In the array version of the Stack class, which operations require linear time for
their worst-case behavior?
Answer: None of these operations require linear time.

In the linked-list version of the Stack class, which operations require linear time
for their worst-case behavior? Assume that addtoTail, deletefromTail are used.
Answer: pop

Select wrong statements:


Recursion is always more efficient than loops.
Recursion can make the conceptual design of an algorithm’s implementation easier.
Recursion gone wrong can lead to overflow stack errors
Recursion can be only replaced by iteration.
Answer: is always more efficient than loops+ can be only replaced by iteration

In a single method declaration, what is the maximum number of statements that may
be recursive calls?
Answer: There is no fixed maximum

The problem of printing an input line in reverse order can be implemented using:
Answer: Recursion

Consider algorithm of the 8-queen problem:


Answer: The algorithm finds all solutions.

On average, what is the maximum number of comparisons needed to find a key in a


balanced binary search tree with 1 million nodes?
Answer: 20

To delete a node in a binary search tree that has two children, the Deletion by
Merging method requires to find what node?
Answer: The rightmost node of the left subtree of the deleted node.
Tree balancing can be performed locally after an element is inserted into or
deleted from the tree using………………….
Answer: AVL tree.

The DSW Algorithm uses:


Answer: Right + Left rotation.

The depth-first search algorithm for a graph:


Answer: Travels all possible paths from a vertex to see if it can find the
destination before it moves on to the adjacent vertices.

Select right statements:


Djikstra's shortest path algorithm can be applied to undirected graph.
The breadth-first search can be used to find the shortest path from a source vertex
to the destination vertex
All of the others.
None of the others.
Answer: All of the others.

Two algorithms which used for finding a minimum spanning tree are Kruskal and
Dijkstra. Which algorithm uses the cycle detection method?
Answer: Kruskal + Dijkstra algorithm.

Which of the following statements about shortest path finding algorithms are true:
Dijkstra’s algorithm is label-setting algorithm.
Dijkstra’s algorithm can be applied to graphs have negative weights.
The complexity of Dijkstra’s algorithm is O(|V|), where |V| is number of vertices
of graph.
All of the others.
Answer: Dijkstra’s algorithm is label-setting algorithm.

When is Insertionsort a good choice for sorting an array?


Answer: The array has only a few items out of place.

Mergesort makes two recursive calls. Which statement is true after these recursive
calls finish, but before the merge step?
Answer: Elements in each half of the array are sorted amongst themselves.

Suppose we are sorting an array of eight integers using a some quadratic (O(n2)))
sorting algorithm. After four iterations of the algorithm's main loop, the array
elements are ordered as shown here:
2 4 5 7 8 1 3 6
Which statement is correct?
Answer: The algorithm is not selectionsort, but it might be insertionsort.

In Quicksort, the bound value (pivot) is:


Answer: All of the others.

The more complex the hashing functions, the better it is


Answer: False

Which of the following methods are used to collision resolution:


Answer: Open addressing.

Which of the following hashing methods can cause collision:


Answer: All of the others.

Select incorrect statements:


Answer: In quadratic probing the offset from x is the square of the step number, so
the probe goes to x, x+1, x+2, x+3, x+4, and so on.

Assume that encoding of three symbols X, Y, W, Z is:


V: 10
X: 010
Y: 101
W: 100
Z: 110
Which of the following restrictions does this encoding violate:
Answer: No codeword is a prefix of another codeword.

Select incorrect statements about Data compression:


a Huffman algorithm can be implemented using priority queue.
b Huffman algorithm applied to case of the probabilities of symbol are known in
advance.
c Huffman algorithm can be only applied to text files.
d All of the others
Answer: Huffman algorithm can be only applied to text files.

The Huffman algorithm always produces a unique binary tree.


Answer: False

In an optimal system, there should not be any unused short codewords either a
stand-alone encodings or as prefixes for longer codewords.
Answer: True

Select incorrect statements about Data compression:


a Huffman tree can be only constructed bottom-up.
b In adaptive Huffman encoding, sibling property is retained assures the
Huffman tree under construction is still a Huffman tree.
c All of the others.
d None of the others.
Answer: Huffman tree can be only constructed bottom-up.

Which expressions will evaluate to true if preceded by the following code?


(a == "Hello")
(a == b)
(a == c)
[Link](b)
Answer: (a == c)+[Link](b)

What is output when calling TriangularNumber(4)


Answer: 10

What is maximum number of activation records (including its caller) in runtime


stack when calling TriangularNumber(10
Answer: 11

What is maximum number of activation records (including its caller) in runtime


stack when traversing the below tree using the above algorithm?
Answer: 5

What is maximum number of elements in queue when traversing the below tree using
the above algorithm?
Answer: 4

Assume array data[] = {2,8,6,1,10,15,3,12,11}. Array data after ending the first
loop.
Answer: {15,12,6,11,10,2,3,1,8}

In the first loop, moveDown is called n/2 times in any case.


The total number of moves in all executions of moveDown in the second phase is
O(lgn).
All of the others.
None of the others.
Answer: In the first loop, moveDown is called n/2 times in any case.

“this is g of A”
“this is g of C”
An error occurs when compiling the program.
Nothing is printed.
Answer: “this is g of C”

Assume array data[] = {4,10,8,3,12,17,5,14,13}. Array data after executing 4


iterations of outer loop.
Answer: {3,4,8,10,12,17,5,14,13}

How many times is number 840 printed out when call pattern(840)
Answer: 2

How many integers will the program print when calling nonTail(n), n > 0.
Answer: 2^n -1

Count number of even values in binary tree.


Print even numbers in binary tree.
Print even numbers in ascending order.
Print and count number of even values in binary tree.
Answer: Print even numbers in binary tree.

Count number of nodes in binary tree.


Calculate height of binary tree.
Count number of nonterminal nodes in binary tree.
None of the others
Answer: Calculate height of binary tree.

Check whether binary tree is balanced.


Check whether height of left subtree is greater than height of right subtree.
Check whether height of right subtree is greater than height of left subtree.
None of the others.
Answer: Check whether binary tree is balanced.

Select incorrect statements about Object — Oriented Programming:


Static methods and variables are associated with the class it self
and are called instance methods and instance variables
The combination of data and related operations is called
information hiding principle.
Answer: Static methods and variables+ The combination of data

Which of the following keywords are access modifier:


Answer: protected + private

Select correct statements:


a. A derived class can override the definition of a final method by
introducing its own definition
t. In an abstract class, methods are only declared but not defined
c. Subclasses or derived classes inherit the fields and methods
from their base class.
d. An abstract data type can be part of a program in the form of an
interface
Answer: Subclasses or derived classes inherit+ An abstract data type

An object can be saved in a file if its class type is stated toimplement the
Serializable interface,
d. If the vector’s capacity is greater than its size, then anew element
can be inserted at the end of the vector immediately.
Answer: An object + If the vector’s capacity

Which of sentences about singly linked list are true:


Answer: begin O(1)+ average O(n)+ is no immediate
a. Methods for processing doubly linked list are simpler than those
of singly linked list
b. The node which is deleted from the list will be claimed by the
garbage collector.
c Deleting a node at the end of the list takes constant time 0(1).
d. Inserting a new node at the end of the list requires 0 ( n) steps.
Answer: The node which is deleted+ Deleting a node at the end

Select incorrect statement about skip list:


Answer: None of the others.

Select incorrect statement about skip list:


The search time is O (ign) in the worst case.
Answer: search time is O (ign)+20 element

Select false statement:


Stack can be implemented using linked list.
Stack is applied to Java Virtual Machine,
In the array list, poping is executed in O (lgn) to the worst case.
In the array list, popping is executed in constant time 0(1)
Answer: poping is executed in O (lgn) to the worst case.

a. The Java implementation of the stack is potentially fatal.


b. pop () method returns copy of the top element in the stack
c. peek () method removes the top element of the stack and return it.
d. Stack can be implemented by linked list.
Answer: The Java implementation+ Stack can be implemented by linked list

Which of the following can be executed in constant time 0 ( n)


Answer: deleting singly linked list average case +worst case.

Which of the following statements are true:


Local variables must be stored in activation recordt.
the return address is address of the caller’s instruction immediately foil owing
the c al 1.

Answer: all-in the most case

When converting a method from a recursive version into an iterative version,

Answer: The brevity not be lost + diminished

Recursive definitions on most computers are eventually implemented using a run time
stack and this implementation is done by the operating system.
Answer: True
In all cases, nonrecursive implementation is faster recursive implementation.
Answer: False

Which of the following concepts of tree are true:


Answer: all -path is number of arcs

Select correct statement:


A search can takes 1g ( n) time units in the worst case.
Answer: all-A search lg ( n)worst case.+ for a binary tree

Select incorrect statement:


Depth-first traversal can be implemented using stack.
Depth-first traversal can not be implemented if not using stack
A recursive implementation of preorder free traversal uses stack p1icitly.
There are six possible ordered depth-first traversals.
Morris’s algorithm does not temporarily change free structure.
Answer: all-DF stack+ morris

Which of the following statements are true:


a. Polish notation eliminates all parentheses from formulas
b. Preorder, inorder and posorder tree traversal generate
unambiguous outputs.
Using Polish notation, all expressions have to be broken down
unambiguous into separate operations and put into their proper
order
d. In a expression tree, leaves are operators and nonterninal nodes
are operands.
e. Expression trees do not use parentheses.
f. Polish notation is only applied for compilers.

Answer: parentheses +Using Polish+ Expression

Which of the following statements about finding the shortest path are true:
a. The complexity of Ford’s algorithmis O(VWEh for any graph.
t. For label-correcting method, information of any label can be
changed during application of method.
c. Ford’s algorithm relies on label -setting method.
t The complexity of Dijkstra’s algorithm using heap is O(VlnV)
e. The complexity of Dijkstra’s algorithm is o( v12)
Answer: complexity Dijkstra’s +complexity Dijkstra’s + label-correcting

Which of the following statement about spanning tree is false:


a. The complexity of Kruskal’s algorithm depends on the
complexity of the sorting method applied
t. The complexity of Kruskal’s algorithm depends on the method
used for cycle detection.
c. All of the others.
t None of the others.

Answer: None of the others.

Which of the following statements about efficient sorting is false:


a. The worst case is when the bound divides an array into subarrays
of approximately length
b. In quick sort, a strategy for selecting a bound is to choose the
element located in the middle of the array.
c The best case of quick sort happens when bound is the largest
(the smallest) element of the array.
d. Quick sort is recursive in nature.

Answer: n/2 + best case

Which of the following statements is true;


a. All the sorting methods implemented in java is applied to any
basic data type.
t. For objects comparison, a comparison criterion must be
implemented by user for all classes.
c All of others.
t None of others.
Answer: All of others.

In Insertion Sort, the number of movements and comparisons for a randomly ordered
array is closer to the best case.
Answer: false

Which of the following statement are true:


Linked list can be used in Bucket Addressing.
In chaining, searches always fast if using linked lists.
Answer: All-in chaining

correct statements
a. Extendible hashing is directoryless technique
t. Extendible hashing is faster than and requires less space than
Linear hashing.
c. A reorganization of the file is avoided by using extendible
hashing if the directory overflows.
The characteristic feature of extendible hashing is the
organization of the index, which is expandable table.
e. Linear hashing is directory technique.
Answer: reorganization + characteristic

incorrect statements about Huffman Coding


Answer: all-Huffman tree can be built top-down.

correct statements about Run-length encoding.


Answer: A serious drawback of run-length encoding is that it reliesentirely on the
occurrences of runs

Identify whether below code has error or not:


Answer: Compile error.

Identify whether below code has error or not:


Answer: 3 Compile error.

objectiprocess2 (‘N’) calls process2 of class ExtC.


[Link] (1) does not issue compile error.
object2.process3 (‘N’) call process3 of class C.
object3.process2(’N’) call process2 of class C.
Answer: all-object3.process2(’N’) call process2 of class C.

Identify which alogrithm the above code implements


Insertion Sort
Bubble Sort
Selection Sort
Radix Sort
Answer: Insertion Sort
Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is “ABCDEF\n”
Answer: FEDCBA

What is output if nontail is called with j = 3


Runtime error is issued
1213121
12321
21312
Answer: Runtime error is issued

What is output if nontail is called with i = 5


1315131
13531
3135313
None of the others

Answer: 1315131

What is output if preorderVRL is executed and structure of Binary Tree is the


following image:
1211181021563
28 112 11106153
2631581011112
12 1111082 1536

Answer: 2631581011112

What is output if breadthFirst is executed and structure of Binary Tree is the


following image:
1211181021563
28 112 11106153
263 15 81011112
121111082 1536

Answer: 2 6 3 15 8 10 1 11 12

What is output if breadthFirst is executed and structure of Binary Tree is the


following image:
2863 15 10112 11
286110153 12 11
268 110 153 1112
2683 15 10 11112

Answer: 2683 15 10 11112

Assume that sort is executed with array {9,4,2,5,8,15,3}. What is output


after iteration i=5 of the outer for loop completed
Answer: {2,4,5,8,9,10,3)

Assume that sort is executed with array {19,14,6,5,18,1,15}. What is output after
iteration i=5 of the outer for loop completed
Answer: { 19, 18, 14,6,5,10, 15)

Let deleteFromHead be method used to delete the first element of generic singly
linked list class:
Identify whether above code has error or not:
There are some compile errors.
There may be runtime error in some case.
There always are runtime errors.
No error.
Answer: There may be runtime error in some case.

Identify whether the code of pop method has error or not:


Answer: There may be runtime error in some case.

Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string ¡s “ABCDEF\n’t
Answer: \nFEDCBA

A method within a class is only accessible by classes that are defined within the
same package as the Answer: class of the method. How can such a restriction be
enforced?
Answer: Do not declare the method with any accessibility modifiers.
Which are invalid identifiers?
Answer: zer@
Which statement concerning the switch construct is true?
Answer: A character literal can be used as a value for a case label
If str denotes a String object with the string "73", which of these expressions
will convert the string to the int value 73?
Answer: (new Integer(str)).intValue()
Select correct statements about a singly linked list.
Answer: A node with a specified value (info) can be found by traversing the list.
Advantages which linked list have over an array:
Answer: Size can be expanded and shrunk rapidly.
Which of the following methods take O(n) time for the worst case:
Answer: All of the others.
Select correct statements about a singly linked list.
Answer: Deleting a node at the beginning of a list involves setting head to point
to [Link].
Propertie of a stack is:
Answer: Only one item can be accessed at once.
Properties of a queue are:
Answer: Only one item can be accessed at once.
In the array version of the Stack class, which operations require linear time for
their worst-case behavior?
Answer: None of these operations require linear time.
In the linked-list version of the Stack class, which operations require linear time
for their worst-case behavior? Assume that addtoTail, deletefromTail are used.
Answer: pop
Select wrong or incorrect statements:
Answer: Recursion is always more efficient than loops.
In a single method declaration, what is the maximum number of statements that may
be recursive calls?
Answer: There is no fixed maximum
The problem of printing an input line in reverse order can be implemented using:
Answer: All of the others.
Which of the following statements are true:
Answer: The algorithm finds all solutions.
On average, what is the maximum number of comparisons needed to find a key in a
balanced binary search tree with 1 million nodes?
Answer: 20
To delete a node in a binary search tree that has two children, the Deletion by
Merging method requires to find what node?
Answer: The rightmost node of the left subtree of the deleted node.
Tree balancing can be performed locally after an element is inserted into or
deleted from the tree using………………….
Answer: AVL tree.
The DSW Algorithm uses:
Answer: All of the others.
The depth-first search algorithm for a graph:
Answer: Travels all possible paths from a vertex to see if it can find the
destination before it moves on to the adjacent vertices.
Select right or correct statements:Djikstra's shortest path algorithm can be
applied to undirected [Link] breadth-first search can be used to find the
shortest path from a source vertex to the destination vertex. None of the others.
Answer: All of the others.
Two algorithms which used for finding a minimum spanning tree are Kruskal and
Dijkstra. Which algorithm uses the cycle detection method?
Answer: All of the others.
Which of the following statements about shortest path finding algorithms are true:
Answer: Dijkstra’s algorithm is label-setting algorithm.
When is Insertionsort a good choice for sorting an array?
Answer: The array has only a few items out of place.
Mergesort makes two recursive calls. Which statement is true after these recursive
calls finish, but before the merge step?
Answer: Elements in each half of the array are sorted amongst themselves.
Suppose we are sorting an array of eight integers using a some quadratic (O(n2)))
sorting algorithm. After four iterations of the algorithm's main loop, the array
elements are ordered as shown here:
2 4 5 7 8 1 3 6
Which statement is correct?
Answer: The algorithm is not selectionsort, but it might be insertionsort.
In Quicksort, the bound value (pivot) is:
The first item of array.
The middle item of array.
The last item of array.
Answer: All of the others.
The more complex the hashing functions, the better it is
Answer: False
Which of the following methods are used to collision resolution:
Answer: Open addressing.
Which of the following hashing methods can cause collision:
All of the others.
Select incorrect statements:
Answer: In quadratic probing the offset from x is the square of the step number, so
the probe goes to x, x+1, x+2, x+3, x+4, and so on.
Assume that encoding of three symbols X, Y, W, Z is:
V: 10
X: 010
Y: 101
W: 100
Z: 110
Which of the following restrictions does this encoding violate:
Answer: No codeword is a prefix of another codeword.
Select incorrect statements about Data compression:
Answer: Huffman algorithm can be only applied to text files.
The Huffman algorithm always produces a unique binary tree.
Answer: False
In an optimal system, there should not be any unused short codewords either a
stand-alone encodings or as prefixes for longer codewords.
Answer: True
Select incorrect statements about Data compression:
Answer: Huffman tree can be only constructed bottom-up.
Given the following interface definition, which definition is valid?
Answer: interface B extends I { void increment (); }
Which expressions will evaluate to true if preceded by the following code?
Answer: (a == c) ; [Link](b)
Consider the following alogorithm: What is output when calling TriangularNumber(4)
Answer: 10
What is maximum number of activation records (including its caller) in runtime
stack when calling TriangularNumber(10)
Answer: 11
What is maximum number of activation records (including its caller) in runtime
stack when traversing the below tree using the above algorithm?
Answer: 5
What is maximum number of elements in queue when traversing the below tree using
the above algorithm?
Answer: 4
Assume array data[] = {2,8,6,1,10,15,3,12,11}. Array data after ending the first
loop.
Answer: {15,12,6,11,10,2,3,1,8}
Select right or correct statements:
Answer: In the first loop, moveDown is called n/2 times in any case.
What will be printed when the following program is run? 0 1 An error occurs when
compiling the program.
Answer: 2
What will be printed when the following program is run? “this is g of A” An error
occurs when compiling the program. Nothing is printed.
Answer:“this is g of C”
Assume array data[] = {4,10,8,3,12,17,5,14,13}. Array data after executing 4
iterations of outer loop. {3,4,10,8,12,17,5,14,13} {10,8,4,3,12,17,5,14,13}
{3,4,5,8,10,12,13,14,17}
Answer: {3,4,8,10,12,17,5,14,13}
How many times is number 840 printed out when call pattern(840)
Answer: 2
How many integers will the program print when calling nonTail(n), n > 0.
Answer: 2n - 1
The above algorithm is used to: Count number of even values in binary tree. Print
even numbers in binary tree. Print even numbers in ascending order. Print and count
number of even values in binary tree.
Answer: Print even numbers in binary tree.
The above algorithm is used to: Check whether binary tree is balanced. Check
whether height of left subtree is greater than height of right subtree. Check
whether height of right subtree is greater than height of left subtree. None of the
others.
Answer: Check whether binary tree is balanced.
Which statements are true about inheritance?
Answer: In Java the extends clause is used to specify inheritance
Which statements are true about interfaces?
Answer: Interfaces can extend any number of other interfaces.
Which one of these for statements is valid
Answer: for (int i=0, j=100; i<j; i++, --j) {;}
Which statements are false about modifiers?
Answer: The default modifier means that a method or a field is a accessible to
derived classes.
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?
Answer: ([Link] == null)
Suppose temp refers to a node in a linked list (using the SLLNode class with
instance variables called info and next). What statement changes temp so that it
refers to the next node?
Answer: temp = [Link];
Which boolean expression indicates whether the data in two nodes (p and q) are the
same. Assume that neither p nor q is null.
Answer: [Link] == [Link]
Which of these operations are likely to have a constant time for worst-case in the
linked lists? addBefore (add a new element into before an element in the list).
countOccurrences (count number of an element’s present times in the list). Delete
(remove an element in the list).
Answer: None of the others.
The operation for adding an entry to a stack is traditionally called:
Answer: push
In the array version of the Queue, which operations require O(n) time for their
worst-case behavior?
Answer:None of the others
Which of the following applications may use a stack?A parentheses balancing
program. Keeping track of local variables at run [Link] analyzer for a
[Link] of the others.
Answer:All of the others.
In the linked-list version of the Queue, which operations require linear time for
their worst-case behavior?
Answer:None of the others
When a method call is executed, which information is not saved in the activation
record?
Answer:Current depth of recursion.
When the compiler compiles your program, how is a recursive call treated
differently than a non-recursive method call?
Answer:None of the others.
Select correct statements about recursion
Answer:All of the others.
Select the one TRUE statement. Every binary tree is either balanced or perfect
balanced. Every balanced binary tree is also a perfect balanced binary tree. Every
perfect balanced binary tree is also a balanced binary tree. No binary tree is both
balanced and perfect balanced.
Answer:Every perfect balanced binary tree is also a balanced binary tree.
……………………… is visiting node starting from the highest (or lowest) level and moving
down (or up) level by level, visiting nodes on each level from left to right (or
from right to left).
Answer:Breath-First Traversal
……………..rebalances the tree globally; each and every node could have been involved
in rebalancing either by moving data from nodes or by creasing new values to
reference fields.
Answer: The DSW Algorithm
A heap is an exellent way to implement a ……………..
Answer: priority queue
What is the expected number of operations needed to loop through all the edges
terminating at a particular vertex given an adjacency matrix representation of the
graph? (Assume n vertices are in the graph and m edges terminate at the desired
node).
Answer: O(n)
What graph traversal algorithm uses a queue to keep track of vertices which need to
be processed?
Answer: Breadth-first search.
Suppose you have a directed graph representing all the flights that an airline
flies. What algorithm might be used to find the best sequence of connections from
one city to another?
Answer: A shortest-path algorithm.
The final exams at a university can be scheduled so that no student has two exams
at the same time by applying ……………
Answer:Graph coloring
What is the worst-case time for merge sort to sort an array of n elements?
Answer: O(nlgn)
What is the worst-case time for bublesort to sort an array of n elements?
Answer: O(n2)
What is the worst-case time for heapsort to sort an array of n elements?
Answer: O(nlgn)
In a selectionsort of n elements, how many times are the array elements moved in
the worst case?
Answer: O(n)
What is the worst-case time for binary search finding a single item in an array?
Answer: Logarithmic time
What is the best definition of a collision in a hash table?
Answer: Two entries with different keys have the same exact hash value.
A chained hash table has an array size of 512. What is the maximum number of
entries that can be placed in the table?
Answer:There is no maximum
Suppose you place m items in a hash table with an array size of s. What is the
correct formula for the load factor?
Answer:m/s
Which of the following data structure can be implement Huffman Coding
Answer: All of the others
Select incorrect statements about restrictions need to be imposed on the
prospective codes:
Answer:Each codeword may corresponds to one or many symbols.
Select correct statement about Run-length encoding.
Answer:A serious drawback of run-length encoding is that it relies entirely on the
occurrences of runs.
Select correct statement about Ziv-Lempel Code.
Answer:All of the others.
Which statement is true about the following code?Interface1 and Interface2 do not
match, therefore, MyClass cannot implement them [Link] declarations of void g()
in the two interfaces conflict, therefore, the code will not [Link]
declarations of int VAL_B in the two interfaces conflict, therefore, the code will
not [Link] is wrong with the code, it will compile without errors.
Answer:Nothing is wrong with the code, it will compile without errors.
What will be the result of attempting to compile and run the following program?The
program will fail to compile. The program will compile without error and print 0
when [Link] program will compile without error and print 1 when run. The program
will compile without error and print 2 when run.
Answer:The program will compile without error and print 2 when run.
Which digits, and in which order, will be printed when the following program is
run?The program will only print 1 and 4, in that [Link] program will only print
1, 4, and 5, in that [Link] program will only print 3 and 5, in that [Link]
program will only print 1, 2, 4, and 5, in that order.
Answer:The program will only print 1, 4, and 5, in that order.
Consider the following pseudocode:ABABABAB BABABABA
ABBAABBA BAABBAAB
Answer:ABBAABBA
What values of number are directly handled by the stopping case? number < 0 number
< 10
number >= 0 && number < 10 number > 10
Answer:number >= 0 && number < 10
Number of comparisons of keys and comparisons of i and least is: n(n-1)/2 ; n-1;
(n-1)(n+2)/2 ; none of the others
Answer: (n-1)(n+2)/2
Assume that this algorithm is executed with array {7,1,2,3,4,5,6}. What is output
after iteration i=4 of the outer for loop completed. 1, 2, 3, 4, 5, 6, 7 ; 1, 2, 3,
7, 4, 5, 6
; 1, 2, 3, 4, 5, 7, 6 ; 1, 2, 3, 4, 7, 5, 6
Answer:1, 2, 3, 4, 5, 7, 6
Number of comparisons of keys is : n(n+1)/2 ; n(n-1)/2 ; n^2; n^2 /2
Answer: n(n-1)/2
Which traversal does the above algorithm implement? Breadth-first traversal
Inorder tree traversal
Postorder tree traversal
Preorder tree traversal
Answer: Preorder tree traversal
Select correct statements when applying this algorithm to a n-element array:
moveDown() is called n/2 times to create the heap in the first phase.
The heap is restored n-1 times in the second phase.
In the second phase, this algorithm exchanges n-1 times the root with the element
in [Link] of the others.
Answer: All of the others.
How many asterisks are printed by the method call quiz(5)? 8
4
7
None of the others.
Answer:7
What is output if this algorithm is executed on the following binary tree: 40 30 7
10 11 3 1 2 14
1 3 2 7 10 40 30 11 14
1 2 3 14 7 10 11 40 30
14 2 1 3 11 10 7 30 40
Answer: 40 30 7 10 11 3 1 2 14
What is output if this algorithm is executed on the following binary tree:
a 3
b 9
c 5
d 8
Answer: 5
Which statement, when inserted at the indicated position in the following code,
will cause a runtime exception?
a x = y;
b z = x;
c y = (B) x;
d z = (C) y;
e y = (A) y;
Answer: c y = (B) x;
Select incorrect statements about Object – Oriented Programming:
Answer: The combination of data and related operations is called information hiding
[Link] methods and variables are associated with the class itself and are
called instance methods and instance variables.
Which of the following keywords are access modifier:
Answer:public private
Select correct statements:
a An abstract data type can be part of a program in the form of an interface.
b In an abstract class, methods are only declared but not defined.
c Subclasses or derived classes inherit the fields and methods from their base
class.
d A derived class can override the definition of a final method by introducing
its own definition.
Answer:An abstract data type can be part of a program in the form of an interface.;
Subclasses or derived classes inherit the fields and methods from their base class.
Which of following statements are true:
a If the vector’s capacity is greater than its size, then a new element can be
inserted at the end of the vector immediately.
b A vector is a data structure with a uncontiguous block of memory, just like
an array.
c Java use explicit pointers, object access is implemented in terms of
pointers.
d An object can be saved in a file if its class type is stated to implement the
Serializable interface.
e Java allow multi inheritance.
Answer: If the vector’s capacity is greater than its size, then a new element can
be inserted at the end of the vector immediately.; An object can be saved in a file
if its class type is stated to implement the Serializable interface.
Which of sentences about singly linked list are true:
a Deleting a node at the beginning of the list takes constant time .b
Deleting last node of the list always takes time.c On the average, delete
operation executes steps.d Search operation takes time in the best case.e
There is no immediate access to the predecessor of any node in list.
Answer:Deleting a node at the beginning of the list takes constant time .; On the
average, delete operation executes steps.; There is no immediate access to the
predecessor of any node in [Link] correct statement(s) about Doubly Linked
List:
a Deleting a node at the end of the list takes constant time .b Inserting a
new node at the end of the list requires steps.
c The node which is deleted from the list will be claimed by the garbage
collector.
d Methods for processing doubly linked list are simpler than those of singly
linked list.
Answer: Deleting a node at the end of the list takes constant time .; The node
which is deleted from the list will be claimed by the garbage [Link]
incorrect statement about skip list:
Answer: The number of reference fields indicates the level of each node, and the
number of levels is maxLevel= + 1Select incorrect statement about skip list:
a Searching is efficient.
b Insertion and Deletion are very inefficient.
c The search time is in the worst case.d maxLevel of skip list which has 20
elements is 5
e In 20-element skip list, the node in position 3 points to the node in
position 7
Answer: The search time is in the worst case.; In 20-element skip list, the node
in position 3 points to the node in position 7Select false statement:
a Stack is applied to Java Virtual Machine.
b Stack can be implemented using linked list.
c In the array list, popping is executed in constant time .d In the array list,
poping is executed in to the worst case.
Answer:In the array list, poping is executed in to the worst case.
Select true statements about stack:
Answer:Stack can be implemented by linked list.; The Java implementation of the
stack is potentially fatal.
Which of the following methods of queue are true:
a push(el) — Put the element el on the top of the queue.
b isEmpty() — Check to see if the queue is empty.
c enqueue(el) — Put the element el at the end of the queue.
d dequeue() — Take the last element from the queue.
e firstEl() — Return the first element in the queue without removing it.
lastEl() — Return the last element in the queue without removing it.
Answer:isEmpty() — Check to see if the queue is empty.; enqueue(el) — Put the
element el at the end of the queue.; firstEl() — Return the first element in the
queue without removing it.
Which of the following can be executed in constant time a when deleting a node of
a singly linked list in the worst case.
b when deleting a node of a singly linked list in the average case.
c when searching is executed in a skip list in the ideal situation.
d when insertion sort is executed in the worst case.
Answer: when deleting a node of a singly linked list in the worst case.; when
deleting a node of a singly linked list in the average case.
Recursive definitions on most computers are eventually implemented using a run-time
stack and this implementation is done by the operating system.
Answer:True
Which of the following statements are true:
a Local variables must be stored in activation record.
b The recursive version increases program readability, improves self-
documentation and simplifies coding.
c The return address is address of the caller’s instruction immediately
following the call.
d In the most cases, the code of nonrecursive implementation is shorter than it
is in the recursive implementation.
Answer:The recursive version increases program readability, improves self-
documentation and simplifies coding.; The return address is address of the caller’s
instruction immediately following the call.
In all cases, nonrecursive implementation is faster recursive implementation.
Answer:False
When converting a method from a recursive version into an iterative version,
Answer:Program clarity can be diminished.; The brevity of program formulation
[Link], the brevity may not be an issue in Java.
Which of the following concepts of tree are true:
Answer:The level of a node is the length of the path from the root to the node plus
1;The height of a nonempty tree is the maximum level of a node in the tree;The
level of a node must be between 1 and height of the tree.
Select correct statement:
a Breath-First traversal is implemented using queue.
b For a binary tree with n nodes, there are n! different traversals.
c The complexity of searching a node is the length of the path leading to this
node.
d A search can takes time units in the worst case.e The complexity of
searching depends on the shape of the tree and the position of the node in the
tree.
Answer:Breath-First traversal is implemented using queue;For a binary tree with n
nodes, there are n! different traversals;The complexity of searching depends on the
shape of the tree and the position of the node in the tree.
Select incorrect statement:
a There are six possible ordered depth-first traversals.
b Depth-first traversal can be implemented using stack.
c Depth-first traversal can not be implemented if not using stack.
d A recursive implementation of preorder tree traversal uses stack explicitly.
e Morris’s algorithm does not temporarily change tree structure.
Answer:Depth-first traversal can not be implemented if not using stack;A recursive
implementation of preorder tree traversal uses stack explicitly;Morris’s algorithm
does not temporarily change tree structure.
Which of the following statements are true:
a Polish notation eliminates all parentheses from formulas.
b Preorder, inorder and postorder tree traversal generate unambiguous outputs.
c Polish notation is only applied for compilers.
d Using Polish notation, all expressions have to be broken down unambiguous
into separate operations and put into their proper order.
e In a expression tree, leaves are operators and nonterminal nodes are operands
and.
f Expression trees do not use parentheses.
Answer:Polish notation eliminates all parentheses from formulas;Using Polish
notation, all expressions have to be broken down unambiguous into separate
operations and put into their proper order;Expression trees do not use parentheses.
Which of the following sentences are true:
a The complexity of DFS is O(|V|+|E|), where |V|is number of vertices and |E|is
number of edges.b The complexity of DFS is (O|V|^2)c All algorithms are more
efficient if the underlying graph traversal is not BFS but DFS.
d To prevent loop from happen in an algorithm for traversing a graph, each
visited vertex can be marked.
Answer:The complexity of DFS is O(|V|+|E|) , where |V| is number of vertices and |
E| is number of edges;The complexity of DFS is (O|V|^2)
Which of the following statements about finding the shortest path are true:
a For label-correcting method, information of any label can be changed during
application of method.
b The complexity of Dijkstra’s algorithm is 0(|V|^2)c The complexity of
Dijkstra’s algorithm using heap is 0(|V|ln|V|)d Ford’s algorithm relies on label-
setting method.
e The complexity of Ford’s algorithm is 0(|V||E|) for any graph.
Answer:For label-correcting method, information of any label can be changed during
application of method;The complexity of Dijkstra’s algorithm using heap is 0(|V|ln|
V|)
Which of the following statement about spanning tree is false:
a The complexity of Kruskal’s algorithm depends on the complexity of the
sorting method applied.
b The complexity of Kruskal’s algorithm depends on the method used for cycle
detection.
c All of the others.
d None of the others.
Answer:None of the others.
Which of the following statements about graph coloring is true:
a The complexity of sequential Coloring algorithm is 0(|V|^2).b Sequential
Coloring algorithm establishes the sequence of vertices and a sequence of color
before coloring them.
c In sequential coloring algorithm, vertices must be ordered according to
indices already to the vertices.
d In sequential coloring algorithm, vertices must be ordered according to
degree of vertices.
Answer:The complexity of sequential Coloring algorithm is 0(|V|^2);Sequential
Coloring algorithm establishes the sequence of vertices and a sequence of color
before coloring them.
In Insertion Sort, the number of movements and comparisons for a randomly ordered
array is closer to the best case.
Answer:False.
Which of the following statements about efficient sorting is false:
a Shell sort divides the original array into physical subarrays, sorting them
separately, then merging and dividing them again to sort the new subarrays until
the whole array is sorted.
b Only insertion sort is apllied in all h-sorts of shell sort.
c There is no formal proof indicating which sequence of increments is optimal.
d Shell sort is more efficient than insertion sort even if in case there are
only two increments.
Answer:Shell sort divides the original array into physical subarrays, sorting them
separately, then merging and dividing them again to sort the new subarrays until
the whole array is sorted.;Only insertion sort is apllied in all h-sorts of shell
sort.
Which of the following statements about efficient sorting is false:
a Quick sort is recursive in nature.
b A strategy for selecting a bound is to choose the element located in the
middle of the array.
c The best case of quick sort happens when bound is the largest (the smallest)
element of the array.
d The worst case is when the bound divides an array into subarrays of
approximately length n/[Link]:The best case of quick sort happens when bound is
the largest (the smallest) element of the array; The worst case is when the bound
divides an array into subarrays of approximately length n/2
Which of the following statements is true:
All the sorting methods implemented in java is applied to any basic data type.
For objects comparison, a comparison criterion must be implemented by user for all
classes.
All of others.
None of others.
Answer:None of others.
Which of the following statement about Open Addressing are false:
Answer:In linear probing of the open addressing method, the position in which key
can be stored is found by sequentially searching starting from the begin of
table;Using quadratic probing gives much better results than linear probing and
avoids the problem of cluster buildup.
Which of the following statement are true:
a Coalesced hashing combines linear probing with chaning.
b In chaining, searches always fast if using linked lists.
c Self-organizing linked lists can be used to improve performance in chaining.
d Linked list can be used in Bucket Addressing.
Answer:Coalesced hashing combines linear probing with chaning;Linked list can be
used in Bucket Addressing.
Which of the following statement about Perfect Hash Functions are true:
Answer:Cichelli’s method is used to hash relatively small number of reserved
words;Cichelli’s method uses an exhaustive search.
Select correct statements:
a Extendible hashing is directoryless technique.
b Linear hashing is directory technique.
c The characteristic feature of extendible hashing is the organization of the
index, which is expandable table.
d A reorganization of the file is avoided by using extendible hashing if the
directory overflows.
e Extendible hashing is faster than and requires less space than Linear
hashing.
Answer:The characteristic feature of extendible hashing is the organization of the
index, which is expandable table; A reorganization of the file is avoided by using
extendible hashing if the directory overflows.
Which of the following data structure can be implement Huffman Coding
Answer:Singly linked list;Priority queue;Doubly linked list.
Select incorrect statements about Huffman Coding:
Answer:Huffman tree is only implemented by non-recursive algorithm;Adaptive Huffman
coding uses breath-first left-to-right tree traversal generates a list of nodes
with nonincreasing frequency counter.
Identify whether below code has error or not:
a Compile error.
b Runtime error.
c No error.
Answer:Compile error.
Identify whether below code has error or not:
a Runtime error.
b 3 compile errors.
c No error.
d 2 compile errors
Answer:3 compile errors.
Which of the following statements are true
a object2.process1 (1) does not issue compile error.
b object1.process2 (‘N’) calls process2 of class ExtC.
c object3.process2(‘N’) call process2 of class C.
d object2.process3 (‘N’) call process3 of class C.
Answer:object1.process2 (‘N’) calls process2 of class ExtC;object2.process3 (‘N’)
call process3 of class C.
Identify which alogrithm the above code implements
a Selection Sort
b Insertion Sort
c Bubble Sort
d Radix Sort
Answer:Insertion Sort
Identify which alogrithm the above code implements
a Heap sort
b Bubble sort
c Quick sort
d Radix Sort
Answer:Bubble sort
Assume that getChar() only reads one character of the input string every it is
called. What is output if reverse is executed and input string is “ABCDEF\n”
a ABCDEF
b CBADEF
c FEDCBA
d DEFCBA
Answer:FEDCBA
What is output if nontail is called with i = 3
a 12321
b 1213121
c 21312
d Runtime error is issued.
Answer:Runtime error is issued.
What is output if nontail is called with i = 5
a 1315131
b 13531
c 3135313
d None of the others
Answer:1315131
What is output if preorderVRL is executed and structure of Binary Tree is the
following image:
a 2 6 3 15 8 10 1 11 12
b 2 8 1 12 11 10 6 15 3
c 12 1 11 8 10 2 15 6 3
d 12 11 1 10 8 2 15 3 6
Answer:2 6 3 15 8 10 1 11 12
Assume that sort is executed with array {9,4,2,5,8,10,3}. What is output after
iteration i=4 of the outer for loop completed
a {2,4,5,8,9,10,3}
b {2,4,5,9,8,10,3}
c {9,8,5,4,2,10,3}
d {2,3, 4,5,8,9,10}
Answer:{2,4,5,8,9,10,3}
Assume that sort is executed with array {19,14,6,5,18,10,15}. What is output after
iteration i=4 of the outer for loop completed
a {19,18,14,6,5,10,15}
b {5,6,14,18,19,10,15}
c {5,6,10,14,15,18,19}
d {19,18,15,14,10,6,5}
Answer:{19,18,14,6,5,10,15}
Let deleteFromHead be method used to delete the first element of generic singly
linked list class:Identify whether above code has error or not:
a No error.
b There may be runtime error in some case.
c There are some compile errors.
d There always are runtime errors.
Answer:There may be runtime error in some case.
Identify whether the code of pop method has error or not:
a No error.
b There may be runtime error in some case.
c There are some compile errors.
d There always are runtime errors.
Answer:There may be runtime error in some case.
Assume that getChar() only reads one character of the input string every it is
called.
Skip list helps avoiding sequential search
answer: true
A tree structure is not linked structure
answer: a singly lnked list + inserting a new model
Which of the following operations are implemented in the linkedlist class belongs
to the [Link] package
answer: all of the others
Which of the following operations are implemented in the Arraylist class belongs to
the [Link] package
answer: none of the others
Let L1 (having n nodes) and L2 (having m nodes) be two linked lists which are
managed by the heads and tails
answer: o(1)
In the array implementation, enqueuing can be executed in constant time o(1)
answer: true
Select true statement about stack:
answer: The Java implementation of the stack+ stack can be implemented by linked
list
Which of the following about stack are true
answer: the most top element + Operations of stack based
In the array implementation, dequeuing can be executed in o(n)
answer: false
Which of the following about queue are true:
answer: A queue is an FIFO structure
In the doubly linked list implementation, dequeuing ca be excuted in constant time
o(1)
answer: true
In the doubly linked list implementation, enqueuing ca be excuted in o(n)
answer: false
Which of the following methods of queue are true
answer: enqueue + dequeue(first) + isempty + firstel
Select true statements about stack
answer: Stack can be implemented by linked list + the java implementation of the
stack is potentially fatal
Which of the following statement about queue are true
answer: all of the other
Select false statement
answer: in the array list, poping is excuted in time o(n)to the worst case
Select correct statement about Doubly Linked List
answer: Deleting a node at the end of the list takes constant time o(1)+ processing
for adding a node
The advantage of arrays over linked lists is that they allow random accessing
answer: true
Inserting a new node at the end of the singly linked list
answer: a singly linked list is a node + A linked list is a collection of nodes
Which of the following operations are not implemented in the Arraylist class
belongs to the [Link] package
answer: return the sub list of the array list
Which of sentences about singly linked list are true:
answer: There is no immediate access to the predecesor+ on the average+ deleting a
node at the beginning of the list
Select incorrect statements about object- oriented programming:
answer: the combination of the data+ satic methods and variables
x=7; y=4*++x; z=5*x--; what the values of x,y,z
answer: x=7, y= 32, z= 40
characters are 16 bits long
answer: characters are 16 bits long+ for a postfix+ Character that constitute
variable
Seclect false statement about Java:
answer: Java is not case sensitive
Which of the follwing statements are invalid
answer: int c= {1,2,3,4,5}int []b= int[4]int e[5]
Java allows multi inheritance
answer: if the vector's capacity is greater than its size + a vector is a data
structure
Dynamic binding determines the type of response at compilation time
answer: polymorphism is implemented through static + the data structures field is
designed
A condition in if clause can be any value
answer: A condition in if clause can be any value + for a prefix operator + the
program continuws with a statement
In an abstract class, method
answer:In an abstract class, method+subclasses or derived classes+an abstract data
type
Java uses four access modifiers
answer: a package is a collection of classes + Java uses four access modifiers
When converting a method from a recursive version into an iterative version
answer: the brevity of program formulation lost+ program clarity can be diminished
Consider the following recursive function, asuming n is even
answer: 11
Recursive definitions serve generating new elements and testing whether an element
belongs to a set
answer: the anchor or ground case allows for the construction of new object
In all cases, nonrecursive implementation is faster recursive implementation
answer: false
The data area containing state information of one method is called an activation
record
answer: an activation record still exists + an activation record contains code of
method
What is the value of h(1)
answer: 14
What is the value of A(3,1)
answer: 13
What are number of additions and number of calls to find Fib(8)
answer: 34 and 67
Recursive definitions on most computers are eventually implemented using a run-time
stack
answer: true
Global variables must be stored in activation record
answer: the recursive version increases program readability+ the return address is
address
Consider below recursive define about tree
answer: true
Which of the following methods are used for Depth-First Traversal
answer: all of the other
Expreesion trees do not use parenthese
answer: Polish notation eliminates all parenthese from formulas+ Using polish
notation, all expressions have to be...+ Expression trees do not use parenthese
In all binary trees, there are 2 nodes at level i
answer: false
Which of the following concepts of tree are true
answer: The height of a nonempty tree is the maximum+ the level of is the length of
the path from+ the level of node
There are six possible ordered depth-first traversals
answer: Morris's algotrthm does not temporarily change tree structure+ a recursive
implementation + depth first traversal can not be
Which of the following statements about heap are false
answer: heap represented by array+ a heap can be defineed as an array+ heaps can be
implemented by array
Which of the following methods are used to traverse a tree without using any stack
or threads
answer: traversal through tree transformation
Which operation is used in DSW algorithm
answer: rotation
A pseudograph is multigraph which allows for loops to occur
answer: a path from v1 to vn + a circuit is a cycle
Which graph representation is best
answer: it depends on the problem
Which of the following statements about finding the shortest path are true
answer: For label-setting methods, in each pass through+ the methods solving the
shortest path problem are
Which of the following statements about graph coloring is true
answer: sequential coloring algorithm + the comlexity of sequential
Which of the following statements about finding shortest path is false
answer: the complexity of WFI's algorithm is V3
The chromatic number of the cycle
answer: the choromatic number of the complete+ in Brelaz's algorithm
Most of the label-setting and label- correcting methods are used to find the
shortest paths from one vertex
answer: true
Which of the following statements about elementary sorting is true
answer: none of the other
Which of the following statements about efficient sorting is true
answer: Insertion sort is applied+ Mergesort can be made more
In insertion sort, the number of movements and comparisons for a randomly ordered
array is closer to the best case
answer: false
Which of the following statements about efficent sorting is true
answer: all of the other
Select correct statements about Radix sort
answer: bitradixsort() can be improved + One of techniques radix sort
In insertion sort algorithm, the number of times variable tmp
answer: all of the other
Which of the following statements about quick sort is true
answer: quick sort is recursive in nature + a strategy for selecting a bound is to
choose
Mergesort don't consume much memory
answer: Mergesort can be made more efficient + Insertion sort is applied to small
portions
To create a hash function, the table has to contain at least the same number of
positions
answer: if hash function transforms different keys into different numbers
Which of the following statements about open addressing are false
answer: using quadratic probing gives much better results than linear probing and
avoids the problem+ in linear probing of the open
Linear hashing is directory technique
answer: the characteristic feature of extendiable+ a reorganization of the file
Linked list can be used in bucket addressing
answer: coalesced hashing combines linear probing with chaning+ linked list can be
used
The mid-square method is applied only to number data
answer: the middle part of the bit representation of the square of a key + in
practice, the mid-square
The shift folding method is applied to string data
answer: in shift folding method+ the boundary folding method
The best value of divisor can be any
answer: The best value of divisor can be any+ the folding method is the preferred
choice
Which of the following statements about perfect hash functions are true
answer: in a minimal perfect hash function+ the function g in FHCD
Hash function is function that can transform a particular key
answer: true
Each codeword corresponds to one or more symbols
answer: false
Run- lenght encoding is very efficient for text file in which only blank character
answer: true
Select correct statement about Ziv-Lempel code
answer: all of the others
Select correct statement about run-length encoding
answer: A serious drawback of run length encoding
The length of the codeword for a given symbol mj shoukd not less than the length
answer: false
Select incorrect statements about huffman coding
answer: huffman tree is only implemented+ adaptive huffman coding uses breath-first
Which of the following statements about Merge sort method are incorrect?
answer: Merge sort can be made more effcient by replacing recursion with iteration
Select correct statements
answer: The characteritic feature of.../ A reoganization of the file is avoided..
Suppose that obj is an variable and that is refers to an Integer [Link] s is a
String variable,then which statement is correct about the assignment "s = (String)
obj;"?
answer: The statement will compile and run with no exception
Which of the following Sorting algorithms use Divide and conquer strategy?
answer: Quick sort
Algorithms are applied to graphs:
answer: All of others
Which traversal method is used in Adaptive Huffman tree?
answer: Breadth Firsttraversal
Suppose temp refers to the third node on the doubly linked list that has more than
5 [Link] statement changes temp so that it refers to the first no?
answer: temp = [Link],previous
Select incorrect statement about skip list:
The search time is O(lgn) in the worst case
Which of the following statements is true:
answer: All of others
" What is number of comparisions in the worst case of mergesort to sort an array of
n elements ?"
answer: O (n#^2)
A chained hash table has an array size of [Link] is the maximum number of
entries that can be placed in the table?
answer: there is no maximum
When a method call is executed, which information does its activation record
contain?
answer: Current depth ofrecursion
Which of the following definitions about in a hash table are incorrect?
answer: Two entries with different data have the exact same key.
Which of the statements about Ziv-Lempel Code are false?
answer: Ziv-Lempel uses buffer of symbols
When a method call is executed, which infomation is not saved in the activation
record?
answer: Location where the method should return when done.
When converting a method from a recursive version into an iterative version,
answer: The program always run slower.
Select correct statement about Ziv-Lempel Code.
answer: None of others
Which of the following statements about the Stack are true?
answer: Clear operation in the linked list implemetation is executed.../Pushing
operation...
Which of the following Sorting algorithms have complexity of O(n) in best case?
answer: All of others
What is the value of the Shift Folding Hash Function if K = 43-65-76-7 and Tsize =
100
answer: 91
The partition function below is used for partitioning the array a in quicksort:
answer: 2,3,5,6,8,10,7,9
Basically, the complexity of inserting a node after a given node in a singly linked
lists is ...
answer: O(1)
Consider the following pseudocode:
answer:HowAreYou
Select the statement that is the most [Link] of the following applications
may use a stack?
answer: Store all variables in a program
The following is the main part of selection sort pseudocode:
answer:2,3,11,12,5,10,7,4,8,6
Specify the correct statement about hashing algorithm (Select the best answer).
answer:If the coalesced method is used ....
What is the value of the Boundary Folding Hash Function K = 43-65-76-7 and Tsize =
100?
answer: 82
Select the statement that is the most correct.
answer: For a recursive method to terminate there must be one or more limit
conditions.
Select the most correct statement about the complexity of insertion sort.
answer: The best case is O(n),and the worst case is O(n^2)
Consider the AVL tree [Link] is the breadth first traversal of the tree after
inserting a node with value 28?
answer: 35,20,45,10,28,40,25,30
Which of the following algorithms in graphs can be implemented by extending Depth
First Search algorithm?
answer: All of others
Suppose temps refers tosome node in a doubly linked [Link] boolean expression
can be used to check whether temp refer to the first node of the list?
answer: [Link]==null
Which of the following problems may use the recursion technique?
answer: Perform symbolic differentiation
Which of the following can be executed in constent time O(n)
answer: when deleting a node of..../when deleting a node of....
Which of the following statements about Run-Length EnCoding are False
answer: Run-Length encoding can be applied to compress faximages
Which of the following strategies fit to Binary Search trees that only have some
elements constantly accessed?
answer: Use the DSW algorithm
Which of the following statements are true:
answer: Using Polish notation, all expressions have to broken down/Preorder,inorder
and..
A queue is implemented using a doubly linked list, which of the following
operations require O(n) time?
answer: None of others
What is the number of comparisions and swaps in the best case for creating a heap
using top down method (William's method)?
answer: the number of comparision is lgn and swaps is zero
A recursive method may be eliminated by using .............
answer: All of others
Which of these operations are likely to have a constant time for worst-case in the
singly linked lists?
answer: get(int index) :Retums the element at the specified position in this list.
What is the complexity of inserting a node in a perfectly balanced tree for worst
case?
answer: none of others
Which of the following problem use stack implicitly or explicitly?
answer: Eight-queen problem
What is the worst-case time for finding an element in a Binary tree?
answer: O(n^2)
In the array implementation of the queue, which operations require constant time?
answer: enqueue
Which of the following statement about Perfect Hash Function are true?
answer: Cichelli's method uses an .../ Cichelli's method is used to....
Select correct statement:
answer: A reoganization of the file is..../The characteritic....
Whcich of the following data structure can be Implemen Huffman Coding
answer: Singly linked list/Priority queue/Doubly linked list
Select incorrect statement about Huffman coding:
answer: Huffman tree is only..../David Huffman's algorithm.../Adaptive Huffman...
Select correct statement about Run-length encoding.
answer: A serious drawback of run-length encoding is that it relies etirely on
the ...

You might also like