Object-Oriented Programming Concepts
Object-Oriented Programming Concepts
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.
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.
Linked lists allow easy insertion and deletion of information because such
operations have a local impact on the list.
Answer:True
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.
When a method call is executed, which information is not saved in the activation
record?
Answer: Instances of classes.//Current depth of recursion
In the array version of the Queue, which operations require Otime for their worst-
case behavior?
Answer:None 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.
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
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
......... 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
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.
Most of the label-setting and label-correcting methods are used to find from one
vertex to all other vertices.
Answer:True
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
What is the worst-case time for bubble sort to sort an array of n elements?
Answer:O`(n^2)`
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 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.
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
What is the worst-case time for binary search finding a single item in an array?
Answer:Logarithmic time
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
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
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
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.
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
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}. 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
The program will compile without error and print 2 when running.
Answer:120
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
Answer:5
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
In the array version of the Queue, which operations require O(n) time for their
worst-case behavior?
Answer: None 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
……. 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
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
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
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 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 this method declaration:How many asterisks are printed by the method call
quiz(5)?
a.
8b.
4c.
7d. None of the others
Answer: 7
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.
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()
Which of the following methods take O(n) time for the worst case:
Answer: All of the others.
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
In a single method declaration, what is the maximum number of statements that may
be recursive calls?
Answer: There is no fixed maximum
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.
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.
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.
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.
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
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: 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
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
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 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 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
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
Identify whether below code has error or nota. 3 compile errorsb. No errorc.
Runtime errord. 2 compile errors
Answer:3 compile errors
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
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}
What are number of additions and number of calls to find Fib(8) using recursive
definition;
answer: 33 and 67
Which of the following methods are used to traverse a tree without using any stack
or threads:
answer: Traversal through Tree Transformation
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
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 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 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
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
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 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
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
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
Compound statements, or blocks, are marked by delimiting them with braces, { and }.
Variables used in a class are called class scope variables, data fields, or fields.
Subclasses, or derived classes, inherit the fields and methods from their base
class so that they do not have to repeat the same definitions.
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 queue is a waiting line that grows by adding elements to its end and shrinks by
taking elements from its front.
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).
In priority queues, elements are dequeued according to their priority and their
current #queue position.
Tail recursion is characterized by the use of only one recursive call at the very
end of a method implementation.
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.
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
The sets used to solve the union-find problem are implemented with circular linked
lists
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
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]
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
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
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
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)
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
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
/////////////////////////////////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
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
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
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
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
33. Which of the following data structure can be implemented Huffman Coding
Answer:- Singly linked list - Priority queue - Doubly linked list
38. Class C{
Void process1(char ch)(….)
Void process2(char ch)(….)
Void process3(char ch)(….)
}
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
Answer:- 2 6 3 15 8 10 1 11 12
45.
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
54. In the doubly linked list implementation, enqueuing can be executed in time
O(n)
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
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
72.
What is the value of h(1):
Answer:- 14
73.
What is the value of A(3,1):
Answer:- 15
75. Which of the following methods are used to traverse a tree without using any
stack or threads:
Answer:- Traversal through tree Transformation
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
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
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
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
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
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
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 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
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
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
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
In the doubly linked list implementation, enqueuing can be executed in time O(n)
answer:False
Consider below recursive define about tree: [Link] empty structure is an empty tree.
answer:True
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
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
Which of the following methods are used to traverse a tree without using any stack
or threads:
answer:Traversal through tree Transformation
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 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 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
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
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
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
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
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()
Answer: A node with a specified value (info) can be found by traversing the list.
Which of the following methods take O(n) time for the worst case:
Answer: All of the others.
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
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
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.
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.
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.
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
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}
“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”
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
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
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 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
In Insertion Sort, the number of movements and comparisons for a randomly ordered
array is closer to the best case.
Answer: false
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
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
Answer: 1315131
Answer: 2631581011112
Answer: 2 6 3 15 8 10 1 11 12
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.
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
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.
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.
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];
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.
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: 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
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
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.
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: 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
……………..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
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: O(nlgn)
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
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
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
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: ABBAABBA
Answer: ((n-1)(n+2))/2
Answer: 1, 2, 3, 4, 5, 7, 6
Answer: 7
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: zer@
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)
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: Deleting a node at the beginning of a list involves setting head to point
to [Link].
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.
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
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
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: 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.
Answer: Travels all possible paths from a vertex to see if it can find the
destination before it moves on to the adjacent vertices.
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.
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.
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: False
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.
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
Answer: (a == c) || [Link](b)
Answer: 10
Answer: 11
Answer: 5
Answer: 4
Answer: {15,12,6,11,10,2,3,1,8}
Answer: In the first loop, moveDown is called n/2 times in any case.
Answer: 2
Answer: “this is g of C”
Answer: {3,4,8,10,12,17,5,14,13}
Answer: 2
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.
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.
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
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]
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
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.
……………………… 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
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.
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
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
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
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.
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()
Answer: A node with a specified value (info) can be found by traversing the list.
Which of the following methods take O(n) time for the worst case:
Answer: All of the others.
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
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
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.
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.
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 an optimal system, there should not be any unused short codewords either a
stand-alone encodings or as prefixes for longer codewords.
Answer: True
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}
“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”
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
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
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 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
In Insertion Sort, the number of movements and comparisons for a randomly ordered
array is closer to the best case.
Answer: false
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
Answer: 1315131
Answer: 2631581011112
Answer: 2 6 3 15 8 10 1 11 12
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.
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 ...