Dsa
Dsa
1. What is the purpose of the public keyword for a method in Java? A. Only methods of
subclasses can call a public method. B. Only methods of the same package can call a public
method. C. Anyone can call public methods. D. Only methods of the same class can call a
public method.
3. What does a do-while loop ensure regarding its loop body? A. The loop body is executed only
if the condition is initially true. B. The loop body is executed zero or more times [Outside
Source]. C. The loop body is repeated for as long as the condition is true each time it is
evaluated, ensuring at least one execution. D. The loop body executes a fixed number of times.
4. What is the primary function of the break statement in Java? A. To skip the remaining steps of
the current loop iteration. B. To immediately exit the entire program [Outside Source]. C. To exit
a loop or switch statement, optionally using a label. D. To return a value from a method.
5. What is the primary function of the continue statement in Java? A. To exit a loop or switch
statement. B. To return a value from a method. C. To skip over the remaining steps of the loop
body in the current iteration and then continue the loop if its condition is satisfied. D. To jump to
a specified label anywhere in the code.
6. If an array in Java is named a, how is its length accessed? A. a.size() [Outside Source]. B.
length(a) [Outside Source]. C. a.length. D. a.capacity().
7. What is an array's "capacity" sometimes referred to as? A. Its element count. B. Its current
size. C. Its length. D. Its available memory [Outside Source].
10. What does CRC stand for in the context of initial coding? A. Code Review Check [Outside
Source]. B. Component-Responsibility-Code. C. Component-Responsibility-Collaborator. D.
Class-Responsibility-Construction [Outside Source].
11. What is the recommended indentation practice for statement blocks in Java coding style
according to the book? A. 8 spaces. B. 2 spaces. C. 4 spaces. D. No specific recommendation,
as long as it's consistent.
12. What is the definition of testing in software development? A. The process of tracking the
execution of a program and discovering errors. B. The process of experimentally checking the
correctness of a program. C. The process of writing the initial code for a program. D. The process
of designing the program's classes.
14. What is a method coverage test aiming to ensure? A. Every code statement in the program is
executed at least once. B. Every method in the program is tested at least once. C. All possible
inputs are tested. D. The program handles unexpected inputs gracefully.
15. Which of the following is NOT assumed as prerequisite knowledge for the reader of the
book? A. Familiarity with variables and expressions. B. Understanding of iteration structures
(for-loops and while-loops). C. Familiarity with object-oriented design. D. Knowledge of
methods (functions or procedures).
16. What does the method hasNextType() of a Scanner object return? A. The next token string in
the input stream. B. Whether the input stream has another line of text. C. True if there is another
token in the input stream and it can be interpreted as the corresponding base type, Type. D. The
next token in the input stream, returned as the base type.
17. Which of the following is a type of loop provided by Java? A. Repeat-until loop. B. While loop.
C. Goto loop. D. Unless loop [Outside Source].
18. Which of the following is a key aspect of Object-Oriented Design Goals? A. Efficiency. B.
Simplicity. C. Adaptability. D. Portability.
19. What are the internal nodes of a file system tree (as per Example 7.1)? A. Regular files. B.
Directories. C. Individual files and directories. D. The root directory only.
20. What is the approximate number of reinforcement, creativity, and project exercises in the
fourth edition? A. 400. B. 670. C. 200. D. 300 [Outside Source].
21. The Java code implementing fundamental data structures in this book is organized in a
single Java package. What is its name? A. java.util. B. com.datastructures [Outside Source]. C.
net.datastructures. D. edu.datastructures [Outside Source].
22. What is the purpose of the abstract modifier for a method? A. It indicates the method can be
called by anyone. B. It prevents the method from being inherited by subclasses [Outside
Source]. C. A method declared as abstract has no code and its signature is followed by a
semicolon. D. It means the method can only be called by objects of classes in the same
package.
23. Which operator is used for equality relation in pseudo-code, as equivalent to "==" in Java? A.
←. B. !=. C. =. D. ==.
24. When developing an object-oriented program, what is one of the main challenges for
beginning Java programmers? A. Deciding which algorithms to use for sorting. B. Debugging
complex code. C. Deciding what classes to define to do the work of their program. D. Optimizing
memory usage.
25. What type of exercises accounts for approximately 20% of the total 670 exercises in the
book? A. Reinforcement exercises. B. Creativity exercises. C. Programming projects. D.
Challenge problems [Outside Source].
2. What are the three main goals of object-oriented design? A. Efficiency, Portability, and
Simplicity. B. Robustness, Adaptability, and Reusability. C. Scalability, Security, and
Maintainability [Outside Source]. D. Encapsulation, Abstraction, and Modularity.
3. What does "robustness" mean in software development? A. The ability of software to run with
minimal change on different platforms. B. The ability of software to evolve over time. C. The
capability of handling unexpected inputs and recovering gracefully from errors. D. The property
of a program producing the right output for all anticipated inputs.
5. How is an Abstract Data Type (ADT) typically expressed in Java? A. By a class with an empty
constructor. B. By a concrete implementation. C. By an interface, which is a list of method
declarations with empty bodies. D. By a hierarchical structure of classes.
7. What is a "superclass" also known as? A. Subclass. B. Extended class. C. Base class. D.
Derived class [Outside Source].
8. What mechanism processes a method invocation o.a() to find the specific method to invoke,
especially when inheritance is involved? A. Static binding. B. Compile-time resolution [Outside
Source]. C. Dynamic dispatch. D. Method overloading.
9. When does method overloading occur in Java? A. When a subclass redefines a method from
its superclass. B. When a method is declared as abstract. C. When a single class has multiple
methods with the same name but different signatures. D. When a method calls itself recursively.
10. What is a "method signature" defined as? A. The method's name and return type. B. The
method's access modifier and name. C. A combination of its name and the type and number of
arguments passed to it. D. The method's body.
11. What is strong typing? A. A requirement that all variables must be declared with a specific
type. B. The compiler or run-time system requiring that parameter types passed to methods
rigidly conform with the type specified in the interface. C. The ability of a method to accept
parameters of different types. D. A principle that hides the internal workings of an object.
12. What specific problem related to software errors was driven home by accidents involving
the Therac-25 machine? A. Adaptability issues. B. Reusability failures. C. Performance
bottlenecks. D. Lack of robustness, leading to severe consequences.
13. Which of the following is an algorithm design pattern discussed in the book? A. Iterator. B.
Adapter. C. Recursion. D. Decorator.
14. Which of the following is a software engineering design pattern discussed in the book? A.
Dynamic programming. B. Prune-and-search. C. Comparator. D. Greedy method.
15. What is the purpose of the throws clause in a method declaration? A. It indicates that the
method is abstract. B. It prevents exceptions from being thrown by the method. C. It specifies
the exceptions the method might throw, letting users know what to expect and preparing the
Java compiler. D. It forces the method to catch all possible exceptions.
16. What is the API (Application Programming Interface) of a class? A. The internal
implementation details of its methods. B. The specification of the messages (methods) its
objects present to other objects. C. The private data fields of its objects. D. The way objects are
organized hierarchically.
17. Which concept is defined as distilling a complicated system down to its most fundamental
parts and describing them in a simple, precise language? A. Encapsulation. B. Modularity. C.
Polymorphism. D. Abstraction.
18. The book mentions that software needs to be able to evolve over time in response to
changing conditions. What is this goal called? A. Portability. B. Robustness. C. Adaptability. D.
Maintainability [Outside Source].
19. What does the class inheritance diagram in Figure 2.4 illustrate? A. Data flow between
classes. B. Relationships between a superclass and a subclass, including inherited fields and
methods. C. The order of method execution. D. Object interactions.
20. Which of the following is NOT a correct statement regarding inheritance? A. It allows general
classes to be specialized. B. It facilitates code reuse. C. A subclass inherits instance variables
and methods from its superclass. D. A subclass must always redefine all methods inherited
from its superclass.
21. What did Roberto Tamassia receive his Ph.D. in Electrical and Computer Engineering from
the University of Illinois at Urbana-Champaign? A. 1986. B. 1988. C. 1990. D. 1992.
22. What is the primary focus of the journal where Roberto Tamassia is editor-in-chief? A.
Theoretical Computer Science. B. Database Systems. C. Graph Algorithms and Applications. D.
Internet Computing.
23. Which section in Chapter 2 discusses Exceptions? A. Section 2.1. B. Section 2.2. C. Section
2.3. D. Section 2.4.
24. What is the meaning of the protected modifier for a method? A. Anyone can call public
methods. B. Only methods of the same class can call a private method. C. Only methods of the
same package or of subclasses can call a protected method. D. Only objects of classes in the
same package can call a friendly method.
25. What did Dr. Goodrich earn several awards for? A. Research in algorithms and data
structures. B. Publications in Internet computing. C. Teaching data structures and algorithms
courses. D. Designing effective hypermedia presentations.
1. What is a drawback of using arrays for storing ordered data? A. They are inefficient for basic
element access. B. They cannot store elements in a certain order. C. Their size must be fixed in
advance, making them not very adaptable. D. They are difficult to implement.
2. In a singly linked list, what is used to identify the end of the list? A. A special tail variable
pointing to null. B. A loop back to the head. C. A null next reference in the last node. D. A size
counter reaching zero.
3. What is the term for moving from one node to another by following a next reference in a linked
list? A. Node hopping. B. Link hopping or pointer hopping. C. Reference traversal [Outside
Source]. D. Sequential access.
4. What is a key advantage of a doubly linked list over a singly linked list? A. It uses less memory
per node. B. It allows for movement in both directions and quick update operations, including
insertion and removal in the middle. C. It simplifies the definition of a Node class. D. It requires
fewer pointers to manage.
5. What are "header" and "trailer" nodes in a doubly linked list often called? A. Placeholder
nodes. B. Dummy or sentinel nodes. C. Entry points. D. Boundary nodes.
6. What does a DNode in the provided Java implementation store? A. Only arbitrary element
types. B. Character strings. C. References to other nodes only. D. Integers.
7. In a DList (doubly linked list) implementation, how can an element be removed at the
beginning or end of the list using a single remove method? A. By calling L.remove(0) or
L.remove(L.size() - 1). B. By directly manipulating the header or trailer sentinels. C. By executing
L.remove(L.getFirst()) or L.remove(L.getLast()). D. By using removeFirst() or removeLast()
methods directly.
8. How does a circularly linked list differ from a singly linked list? A. It has both a head and a tail.
B. Its last node's next pointer points back to the first node, instead of being null. C. It requires
two next pointers per node. D. It cannot be traversed from any node.
9. What is the "cursor" in a circularly linked list? A. The node that marks the end of the list. B. A
special node marked as a starting point for traversal. C. A pointer to the node with the smallest
element. D. An indicator of the current size of the list.
10. What is the insertion-sort algorithm applied to a doubly linked list? A. A method that always
sorts elements in O(1) time. B. An algorithm that requires a separate array for sorting. C. An
algorithm described in pseudo-code and Java implementation (Code Fragment 3.27, 3.28) for
linked lists. D. A sorting method that is only efficient for very small lists.
11. What is recursion in the context of programming? A. A form of iteration using for or while
loops. B. When a function calls itself. C. A technique for optimizing code by avoiding repeated
calls. D. A method that never terminates.
12. What are the two main steps in a recursive approach for problems, as described in the
"Recursive Approach to Ruler Drawing" example? A. Iterating and stopping. B. Solving and
merging. C. Testing for base cases and making a single recursive call that makes progress
towards a base case. D. Dividing and conquering.
13. What is the purpose of multiple recursion in the context of solving combinatorial puzzles? A.
To prove that a solution exists without enumerating all possibilities. B. To simplify the problem to
a constant-sized collection. C. To enumerate all possibilities and test each one in a systematic
way. D. To avoid the need for brute-force methods.
14. In the PuzzleSolve algorithm (Code Fragment 3.37), how is the set U used? A. To store
elements already included in the current sequence. B. To store elements that form the solution
to the puzzle. C. To keep track of the elements not contained in the current sequence. D. To
represent the final permutation generated.
15. What does the recursion trace for PuzzleSolve(3,S,U) with U = {a,b,c} generate? A. Only
combinations of a, b, and c. B. Subsets of a, b, and c. C. All permutations of a, b, and c. D. Only
sequences of length 2.
16. How can the CreditCard class be modified to include modifier methods (setters)? A. By
making instance variables public. B. By removing accessor methods. C. By including special
update methods that restrict modification of instance variables. D. By using only printCard as a
static method.
17. What is the recommended approach for counting elements in an array where unused cells
point to null objects, as discussed in Exercise R-3.1? A. Iterate through the array and count non-
null entries. B. Modify add and remove methods to keep track of the actual size in an instance
variable n. C. Use a separate linked list to track active elements. D. Rely on Java's array.length
property.
18. Which chapter discusses the architectural underpinnings of data structures, specifically
memory management? A. Chapter 1. B. Chapter 4. C. Chapter 14. D. Chapter 7.
19. What type of traversal allows us to print the name and disk space used by directories in a
file-system tree, as described in Example 7.7? A. Preorder traversal. B. Inorder traversal. C.
Postorder traversal. D. Level-order traversal.
20. According to Section 1.5, what is a common programming task that arrays help with? A.
Creating graphical user interfaces. B. Managing threads and sockets. C. Keeping track of a
numbered group of related objects, like top ten scores. D. Performing advanced mathematical
calculations.
21. When inserting a new node z immediately after a given node v in a doubly linked list, what is
w defined as? A. The node immediately preceding v. B. The new node being inserted. C. The
node following v. D. The head of the list.
22. What can be said about the implementation of size() operation for a stack using a singly
linked list to achieve constant time? A. It requires iterating through the list every time. B. It's not
possible to achieve constant time. C. It requires keeping track of the current number of
elements in an instance variable. D. It uses a recursive count [Outside Source].
23. What is the problem described in Project P-3.6? A. Implementing a Caesar cipher. B. Sorting
a linked list. C. Solving summation puzzles by enumerating and testing all possible
configurations. D. Performing encryption/decryption with an arbitrary substitution cipher.
24. In the Towers of Hanoi puzzle (Exercise C-3.11), what is the primary rule for moving disks? A.
Any disk can be placed on top of any other disk. B. More than one disk can be moved at a time.
C. Never place a larger disk on top of a smaller one. D. Disks can only be moved to adjacent
pegs.
25. What is ROT 13 encryption and decryption as discussed in Exercise R-3.3? A. A complex
cipher requiring advanced mathematical functions. B. A method that shifts alphabet characters
by a random amount. C. A Caesar cipher using 13 as the alphabet shift amount. D. An
encryption method specifically for non-English languages.
1. What is the primary goal of the analysis tool developed in this chapter? A. To provide exact
running times for algorithms on specific hardware. B. To perform experimental studies to
compare algorithms. C. To associate a function f(n) with each algorithm that characterizes its
running time as a function of input size n, independent of hardware and software environments.
D. To find the fastest algorithm for any given problem.
2. Which of the following is NOT one of the seven most important functions used in algorithm
analysis in this book? A. Constant. B. Linear. C. Factorial. D. Quadratic.
3. What does the Big-Oh notation (O(g(n))) primarily characterize? A. The best-case running time
of an algorithm. B. The average-case running time of an algorithm. C. An upper bound on the
growth rate of a function. D. The exact running time of an algorithm.
4. When characterizing a function using Big-Oh notation, what should be strived for? A. To state
the most general upper bound possible. B. To use the largest possible constant c. C. To
characterize the function as closely as possible. D. To always use n^5 as the upper bound for
any polynomial.
5. Which statement is always true regarding the relationship between f(n) and g(n) if f(n) is
O(g(n))? A. f(n) and g(n) are equal for large n. B. f(n) is faster than g(n). C. g(n) is a lower bound for
f(n). D. f(n) grows no faster than g(n) asymptotically.
6. What does the constant a represent in the exponential function a^n from Table 4.1? A. The
base of the natural logarithm. B. Any positive integer. C. A constant greater than 1. D. The input
size.
7. What is the formula for the sum of the first n integers, as used by Carl Gauss? A. n(n+1)/2. B.
n^2. C. 2^n - 1. D. n! [Outside Source].
8. What is the I/O complexity (mentioned in Chapter 14 but rooted in analysis tools)? A. The
number of internal memory accesses. B. The number of disk transfers needed to perform an
operation. C. The time taken to read from an input stream. D. The complexity of input/output
operations in Java.
10. What is the running time of prefixAverages1 (Code Fragment 4.1)? A. O(nlogn). B. O(n). C.
O(1). D. O(n^2).
13. Which of the following functions grows the fastest asymptotically among the listed options?
A. nlogn. B. n^2. C. n^3. D. a^n (where a > 1 is a constant).
14. What is the floor function, denoted by floor(x)? A. The smallest integer greater than or equal
to x. B. The integer closest to x. C. The largest integer less than or equal to x. D. x rounded to the
nearest whole number.
15. What is the ceiling function, denoted by ceil(x)? A. The largest integer less than or equal to x.
B. The smallest integer greater than or equal to x. C. The integer closest to x. D. x truncated to an
integer.
16. According to the book, sections that use a function other than the seven most important for
algorithm analysis are marked with what symbol? A. !. B. # [Outside Source]. C. ?. D. * (star).
17. What is one of the limitations of experimental analysis of algorithm running times? A. It is
too simple to perform. B. It is independent of the hardware environment. C. It is difficult to
account for all possible inputs. D. It does not allow for comparison of different algorithms.
18. If the running time of algorithm A is O(f(n)), what can be said about its worst-case running
time? A. It is Ω(f(n)). B. It is Θ(f(n)). C. In the worst case, the running time of algorithm A is O(f(n)).
D. It means the algorithm is always fast.
19. What is the outcome of the expression 3log n + 2 in Big-Oh notation? A. O(n). B. O(1). C. O(n
log n). D. O(log n).
20. What is the expected value of a random variable, as defined in Appendix A? A. The most
frequent outcome of an experiment. B. The sum of x * Pr(X = x) over the range of X. C. The
minimum value of X. D. The maximum value of X.
21. According to Proposition A.19, what is the property of Linearity of Expectation? A. E(X * Y) =
E(X) * E(Y). B. E(X - Y) = E(X) - E(Y). C. E(X + Y) = E(X) + E(Y) and E(cX) = cE(X). D. E(X / Y) = E(X) /
E(Y).
22. What is Hn (the nth Harmonic number) approximately equal to? A. n^2. B. log n. C. ln n +
Θ(1). D. n log n.
23. If d(n) is O(f(n)) and f(n) is O(g(n)), then what is d(n)? A. O(f(n) + g(n)). B. O(f(n)g(n)). C. O(g(n)).
D. Ω(g(n)).
24. What is the result of 2n+2 in Big-Oh notation? A. O(n). B. O(1). C. O(2n+2). D. O(2^n).
25. Which of the following is a correct identity for logarithms and exponents provided in
Appendix A? A. logb(a + c) = logb a + logb c. B. logb(a^c) = c + logb a. C. logb(ac) = logb a + logb
c. D. b^(a+c) = b^a * b^c.
1. What principle governs the insertion and removal of objects in a stack? A. First-in first-out
(FIFO). B. Last-in first-out (LIFO). C. Random access. D. Smallest element first.
2. What is the metaphor used to describe a stack? A. A line of people waiting. B. A conveyor
belt. C. A stack of plates in a spring-loaded cafeteria plate dispenser. D. A collection of books on
a shelf.
3. Which of the following operations removes an element from a stack? A. push(). B. top(). C.
size(). D. pop().
4. What happens if top() is called on an empty stack? A. It returns null. B. It returns 0. C. An error
occurs. D. The stack remains unchanged.
5. In an array-based stack implementation, what symbolic name is used to specify the capacity
of the array? A. SIZE. B. MAX_ELEMENTS. C. CAPACITY. D. ARRAY_SIZE.
6. When implementing a stack using a singly linked list, where is the top of the stack most
efficiently placed? A. At the tail of the list. B. In the middle of the list. C. At the head of the list. D.
It does not matter for efficiency.
7. What is an important problem in processing arithmetic expressions that stacks can help
solve? A. Evaluating complex mathematical functions. B. Converting expressions to postfix
notation. C. Ensuring grouping symbols (like parentheses) match up correctly. D. Optimizing
expression evaluation order.
8. In the algorithm for parentheses matching (Code Fragment 5.10), what happens when an
opening symbol is encountered? A. It is ignored. B. It is popped from the stack. C. It is pushed
onto the stack. D. The algorithm terminates.
9. What is HTML? A. A programming language for web applications. B. The standard format for
hyperlinked documents on the Internet. C. A database query language. D. A data structure for
text processing.
10. What is the common form of a simple opening HTML tag? A. <name/>. B. <name>. C.
</name>. D. {{name}}.
11. In the isHTMLMatched method (Code Fragment 5.12), what is used to store the names of
opening tags? A. A queue. B. An array. C. A stack. D. A linked list directly.
12. What does the java.util.Scanner pattern "<[^>]*>" denote? A. Any string within angle
brackets. B. A string starting with '<', followed by zero or more characters, ending with '>'. C. A
string starting with '<', followed by one or more non-'>' characters, ending with '>'. D. A string that
starts with '<', followed by zero or more characters that are not '>', followed by a '>'.
13. What is a double-ended queue (deque)? A. A queue that allows insertion only at the front. B.
A queue that allows deletion only at the rear. C. A queue-like data structure that supports
insertion and deletion at both the front and the rear. D. A data structure that only allows peeking
at both ends.
14. What is the expected running time for all methods of a deque implemented with a doubly
linked list? A. O(n). B. O(log n). C. O(1). D. O(n log n).
15. What does size() return for a deque? A. A Boolean indicating if the deque is empty. B. The
first element of the deque. C. The last element of the deque. D. The number of elements of the
deque.
16. Suppose an initially empty stack S has performed a total of 25 push operations, 12 top
operations, and 10 pop operations, 3 of which generated StackEmptyExceptions, which were
caught and ignored. What is the current size of S? A. 27. B. 15. C. 25. D. 18.
17. What is the problem described in Project P-5.10 regarding stock transactions? A.
Calculating capital gain using a LIFO protocol. B. Managing stock prices in a priority queue. C.
Calculating total capital gain (or loss) using a FIFO protocol for shares sold. D. Simulating stock
market buy/sell orders with real-time data.
18. Which Java class implements the java.util.Iterator interface and is mentioned as an example
in the text? A. java.util.ArrayList. B. java.util.LinkedList. C. java.util.Scanner. D. java.util.Stack.
19. What is the purpose of the NodeQueue class mentioned in Code Fragment 5.15 and 5.16?
A. To implement a stack. B. To implement a doubly linked list. C. To implement a queue using a
singly linked list. D. To solve the Josephus problem using a stack.
20. What is the Josephus problem (Code Fragment 5.16) solved using in the book? A. A stack. B.
An array. C. A queue. D. A deque.
21. How can the stack ADT be implemented using two queues (Exercise C-5.4)? A. By
alternating push and pop operations between queues. B. By always enqueueing into one queue
and dequeueing from the other. C. This is a conceptual problem that can be solved by shifting
elements between two queues during operations to simulate LIFO. D. It's not possible to
implement a stack using only two queues.
22. What is the "postfix notation" described in Exercise C-5.8? A. A way to write arithmetic
expressions with many parentheses. B. An unambiguous way of writing an arithmetic expression
without parentheses, where operation follows operands. C. A prefix notation where operands
follow the operation. D. A system for evaluating expressions from right to left.
23. What is the expected running time for the push() and pop() methods if a stack ADT is
implemented using two queues (Exercise C-5.4)? A. O(1) for both. B. O(n) for both. C. One
operation might be O(1) and the other O(n) or a more complex analysis depending on
implementation. D. O(log n) for both.
24. Which type of loop condition is tested before the loop body is executed? A. do-while loop. B.
while loop. C. for loop (increment section). D. for loop (initialization section).
1. What is the "index" of an element e in a list S? A. Its position relative to the end of the list. B.
The number of elements of S that follow e. C. The number of elements of S that precede e. D. A
unique identifier for e.
2. What is an extendable array used for in an ArrayList implementation? A. To fix the size of the
array in advance. B. To reduce memory usage. C. To allow the array list to grow in capacity as
needed by push operations. D. To implement a doubly linked list.
3. What algorithmic design pattern is used to show the efficiency of push operations on an
ArrayList implemented with an extendable array? A. Divide-and-conquer. B. Greedy method. C.
Amortization. D. Dynamic programming.
5. What is the amortized running time of each push operation in an ArrayList implemented with
an extendable array (assuming the described amortization scheme)? A. O(n). B. O(log n). C.
O(1). D. O(n log n).
7. What is the purpose of the Position ADT in the context of node lists? A. To expose the internal
next and prev pointers of nodes. B. To allow direct modification of a node's data. C. To
encapsulate the idea of a "node" in a list, presenting an abstract view to the user. D. To enforce
strong typing for elements in the list.
8. How are the nodes of a doubly linked list typically made to implement the Position ADT for a
node list? A. By creating separate Position objects that refer to nodes. B. By making nodes
inherit from an abstract Position class. C. By having each node implement the Position interface
and defining an element() method. D. By embedding the Position object within each node.
9. What is the running time for all methods of a node list ADT implemented with a doubly linked
list? A. O(log n). B. O(n). C. O(1). D. O(n log n).
10. What two methods are supported by the Iterator ADT? A. start() and end(). B. first() and last().
C. hasNext() and next(). D. get() and set().
11. What is the java.lang.Iterable interface designed to support? A. Removing elements from a
collection. B. Returning an iterator of the elements in a collection via an iterator() method. C.
Accessing elements by index. D. Filtering elements based on a condition.
12. In an iterator implementation where the cursor points just before the first element, what
does performing next() involve? A. Moving the cursor to the previous element. B. Skipping an
element and moving the cursor past it. C. Returning the next element (if it exists) and moving the
cursor just past this element's position. D. Recursively calling itself to find the next element.
14. Which interface in java.util is for mapping keys to values? A. Collection. B. Queue. C. Set. D.
Map.
15. Which Java Collections Framework interface extends Collection to sets? A. Map. B. Queue.
C. Set. D. List.
16. How is the java.util.LinkedList class implemented according to its documentation? A. With a
singly linked list. B. With an array. C. With a doubly linked list. D. With a circular array.
17. What is a Sequence ADT defined as? A. A simplified list supporting only basic add/remove
operations. B. A data structure that only provides access by index. C. An ADT that supports all
methods of the deque, array list, and node list ADTs, with dual access by indices and positions.
D. An ordered collection that only allows insertions at the front.
18. The definition of the Sequence ADT as including methods from three different ADTs is an
example of what? A. Single inheritance. B. Multiple inheritance. C. Interface extension. D.
Design pattern usage.
19. What is a major drawback of implementing a general sequence with an array if position
objects hold indices? A. Elements cannot be referenced by index. B. Existing positions in the
sequence have no way of knowing their indices changed after an addFirst operation. C. It uses
too much memory. D. It requires complex pointer management.
20. What is the move-to-front heuristic (Section 6.5.2) used for? A. Sorting a list alphabetically.
B. Maintaining elements in a fixed order. C. Moving an accessed element to the front of a list to
potentially speed up future accesses. D. Removing the least recently used element.
21. What is the ArrayList class in Java a replacement for (as mentioned in the Preface)? A.
java.util.List. B. java.util.Stack. C. java.util.Queue. D. java.util.Vector.
22. What does checkPosition method do in the NodePositionList class (Code Fragment 6.9)? A.
Checks if the position is null. B. Performs safety checks and casts a position back to a DNode.
C. Returns the element at the given position. D. Moves the given position to the start of the list.
23. What happens to the capacity of the underlying array in the ShrinkingArrayList class when
the number of elements goes below N/4 (Exercise C-6.2)? A. It stays the same. B. It shrinks by
half. C. It shrinks to the exact number of elements. D. It doubles.
24. How are elements ordered in the first implementation of a favorite list (FavoriteList class,
Code Fragments 6.19-6.20)? A. By alphabetical order of elements. B. By insertion order. C. By
nonincreasing access counts. D. Randomly.
25. What is a fully associative cache? A. A cache where each memory block has a specific, fixed
slot. B. A cache where a web page can be placed in any available slot. C. A cache that only
stores web pages of a certain type. D. A cache that always keeps the most recently used pages.
Chapter 7: Trees
1. What is one of the most important nonlinear data structures in computing discussed in this
chapter? A. Linked lists. B. Arrays. C. Trees. D. Stacks.
2. In a file system represented as a tree, what do internal nodes represent? A. Regular files. B.
Directories. C. Both files and directories. D. System drives.
3. What is an ordered tree? A. A tree where nodes are sorted alphabetically. B. A tree where the
root is always the smallest element. C. A tree where there is a linear ordering defined for the
children of each node. D. A tree where all nodes have distinct values.
4. What is the depth of a node v in a tree T? A. The number of children of v. B. The length of the
longest path from v to a leaf. C. The number of ancestors of v, excluding v itself. D. The number
of nodes in the subtree rooted at v.
5. What is the depth of the root of a tree? A. 1. B. 0. C. Depends on the tree's height. D.
Undefined.
6. Which traversal type, when applied to a document tree, examines the entire document
sequentially from beginning to end (or the table of contents if external nodes are removed)? A.
Postorder traversal. B. Inorder traversal. C. Level-order traversal. D. Preorder traversal.
7. What is the running time of a preorder traversal of a tree T with n nodes (assuming visiting a
node takes O(1) time)? A. O(log n). B. O(n log n). C. O(n). D. O(n^2).
8. What kind of traversal is suitable for computing the disk space used by a directory in a file
system tree (where disk space is sum of directory size, files in it, and children directories'
space)? A. Preorder traversal. B. Postorder traversal. C. Inorder traversal. D. Level-order
traversal.
9. What are decision trees used to represent? A. Hierarchical file systems. B. Ordered
documents. C. A number of different outcomes from a series of yes-or-no questions. D.
Arithmetic expressions.
10. In a binary search tree, where are elements stored? A. Only at external nodes. B. At internal
nodes. C. At both internal and external nodes. D. At the root only.
11. What is the property that an inorder traversal of the internal nodes of a binary search tree T
visits the elements in? A. Decreasing order. B. Random order. C. Order of insertion. D.
Nondecreasing order.
12. In a binary search tree, if a search value y is less than the key x(v) stored at an internal node
v, where does the search continue? A. In the right subtree of v. B. The search terminates
successfully. C. The search terminates unsuccessfully. D. In the left subtree of v.
13. What is level numbering in a tree T? A. Numbering nodes based on their depth in a preorder
traversal. B. Numbering nodes based on their depth in a postorder traversal. C. Consecutively
numbering the nodes of a tree as they are visited in a traversal that visits all nodes at depth d
before nodes at depth d+1. D. Numbering nodes based on their position in an array.
14. How does an ArrayList representation of a binary tree work for root, parent, left, right
operations? A. It requires complex linked structures. B. It runs in O(n) time for each operation. C.
It can perform these methods using simple arithmetic operations on level numbers in O(1) time.
D. It is generally inefficient for these operations.
15. What is the template method pattern (Section 7.3.7)? A. A pattern for defining a generic
class. B. A pattern for implementing abstract data types. C. A design pattern where an
algorithm's structure is defined in a superclass, but specific steps are implemented in
subclasses. D. A pattern for constructing expression trees.
16. What is the Euler tour traversal used for in Section 7.3.7? A. Traversing binary search trees.
B. A general traversal mechanism that can be specialized to perform various computations for
binary trees. C. Drawing general trees. D. Converting infix expressions to postfix.
17. What is the problem described in Project P-7.7, which involves slicing floorplans and slicing
trees? A. Optimizing network layouts. B. Finding shortest paths in a building. C. Compacting
slicing floorplans by finding the smallest possible height and width for rectangles compatible
with minimum dimensions. D. Simulating fluid dynamics in a building.
18. In a proper binary tree with n nodes, what is the maximum number of external nodes for a
given height h? A. 2^(h+1) - 1. B. 2^h. C. n. D. n+1.
19. What is Proposition 7.10 about? A. The definition of a general tree. B. The running time of
tree traversals. C. Properties relating the height of a binary tree T with its number of nodes. D.
The different types of binary trees.
20. If T is an ordered tree with more than one node, is it possible for a preorder traversal to visit
nodes in the reverse order of a postorder traversal? A. Yes, always. B. Yes, if it is a binary search
tree. C. No, this cannot occur. D. Yes, if external nodes are ignored.
21. What is the running time of parentheticRepresentation(T, T.root()) (Code Fragment 7.10) for a
tree T with n nodes? A. O(log n). B. O(n). C. O(n log n). D. O(n^2).
22. What does a Roman node refer to in Exercise C-7.27? A. A node at depth v. B. A node that is
the sum of its children. C. A node v where the number of descendents in its left subtree differs
from the number in its right subtree by at most 5. D. A node representing an ancient Roman
numeral.
23. What is the path length of a tree T? A. The length of the longest path from the root to a leaf. B.
The number of nodes in the tree. C. The sum of the depths of all the nodes in T. D. The sum of the
heights of all the nodes in T.
24. In the context of graphs, how should the "trees" of Chapter 7 be referred to? A. Free trees. B.
Spanning trees. C. Rooted trees. D. Connected components.
25. What is the purpose of external nodes in a proper binary tree, according to Section 10.1? A.
They store dictionary entries. B. They act as actual data elements. C. They serve only as
"placeholders". D. They are used for balancing the tree.
1. How are elements removed from a priority queue? A. According to the Last-in First-out (LIFO)
principle. B. According to the First-in First-out (FIFO) principle. C. In order of priority (element
with first priority is removed). D. Randomly.
2. What distinguishes a priority queue from position-based data structures like stacks, queues,
and lists? A. It stores elements at specific positions. B. It supports arbitrary element removal. C.
It stores elements according to their priorities and exposes no notion of "position" to the user. D.
It only supports removal from the front.
3. What is a "key" in the context of priority queues? A. A value stored at a specific position in the
queue. B. An object assigned to an element as a specific attribute for identification or weighing.
C. The element itself. D. A reference to another element.
4. What three properties must a comparison rule (≤) define to be a "total order relation" for
keys? A. Reflexive, Symmetric, Transitive. B. Reflexive, Antisymmetric, Transitive. C.
Commutative, Associative, Distributive. D. Identity, Inverse, Closure.
5. What is a key-value pair inserted into a priority queue called? A. A node. B. A tuple. C. An
entry. D. An element.
6. What two special kinds of objects are used in the definition of a priority queue to handle key
associations and comparisons? A. Keys and Values. B. Entry and Comparator. C. Objects and
Classes. D. Pointers and Nodes.
7. What is the purpose of a comparator object in a priority queue? A. To store the elements in
the queue. B. To define the keys for the elements. C. To supply the comparison rules for two
keys, external to the keys themselves. D. To assign priorities to elements automatically.
8. What are the two fundamental methods of a priority queue P? A. add(e) and remove(e). B.
push(e) and pop(). C. insert(k,v) and removeMin(). D. min() and max().
10. What is selection-sort an instance of, in terms of the PriorityQueueSort scheme? A. When P
is implemented with a sorted list. B. When P is implemented with a heap. C. When P is
implemented with an unsorted list. D. When P is implemented with an array list.
11. What is the running time for the insert operation if a priority queue is implemented with an
unsorted list? A. O(n). B. O(1). C. O(log n). D. O(n log n).
12. What is the running time for the removeMin operation if a priority queue is implemented with
an unsorted list? A. O(1). B. O(n). C. O(log n). D. O(n log n).
13. What is the running time for the insert operation if a priority queue is implemented with a
sorted list? A. O(1). B. O(n). C. O(log n). D. O(n log n).
14. What is the Heap Data Structure? A. A general tree structure. B. A specific data structure
used to implement a priority queue. C. A sorting algorithm. D. A type of linked list.
15. What is heap-sort? A. A sorting algorithm that uses an unsorted list. B. A direct sorting
algorithm that does not use a priority queue. C. A sorting algorithm that is a paradigm of the
PriorityQueueSort scheme using a heap. D. An algorithm for constructing a heap from scratch.
16. What is the space requirement for an adaptable priority queue implemented with an
unsorted list, sorted list, or heap? A. O(1). B. O(log n). C. O(n). D. O(n log n).
17. What is the running time of removeMin() for an adaptable priority queue implemented with a
heap? A. O(1). B. O(n). C. O(log n). D. O(n log n).
18. What are location-aware entries used for in adaptable priority queues (and dictionaries)? A.
To determine the order of elements. B. To simplify the display of entries. C. To store a reference
to an entry's position/index in the underlying data structure to speed up operations like removal.
D. To allow entries to be stored in external memory.
19. What is the purpose of using a "reverse" comparator with the priority queue ADT (Exercise R-
8.4)? A. To reverse the order of elements in the queue. B. To retrieve and remove an entry with
the maximum key instead of the minimum. C. To ensure elements are always sorted in
descending order. D. To simplify the implementation of the removeMin method.
20. At which nodes of a heap can an entry with the largest key be stored? A. Only at the root. B.
Only at the leaves. C. Any node. D. Only at nodes with two children.
21. What data structures are suggested for the Unmonopoly game, where the player with the
most money gives half to the player with the least? A. Two arrays (one for highest, one for
lowest). B. A single stack to track money. C. Two priority queues (one to find max, one to find
min). D. A simple linked list.
22. What is the problem described in Project P-8.10 related to operating systems? A. Managing
memory for CPU jobs. B. Scheduling simulated CPU jobs based on priority and length. C.
Optimizing CPU clock speed. D. Balancing load across multiple CPUs.
23. What is the range of priorities assigned to jobs in the CPU scheduling project (P-8.10)? A. 0
to 100. B. 1 to 100. C. -20 (highest priority) to 19 (lowest priority). D. 1 (highest) to 100 (lowest).
24. How long (in terms of time slices) can a job run for once scheduled on the CPU in the P-8.10
simulation? A. Until a higher priority job is added. B. A fixed number of time slices, up to 100. C.
For a number of time slices equal to its length value (1 to 100). D. Indefinitely until manually
interrupted.
25. What is the relationship between the in-degree and out-degree of each vertex in a directed
graph for an Euler tour to exist? A. In-degree must be greater than out-degree. B. Out-degree
must be greater than in-degree. C. In-degree must equal out-degree for each vertex. D. The sum
of in-degrees must equal the sum of out-degrees.
1. What does a map allow us to store elements for? A. Sequential access. B. Priority-based
retrieval. C. Quick location using unique keys. D. Direct modification of values without keys.
2. What are the key-value pairs stored in a map called? A. Tuples. B. Elements. C. Entries. D.
Records.
3. What is a requirement for keys in a map ADT? A. They must be numerical. B. They can be
duplicated for different values. C. Each key must be unique. D. They must be ordered.
4. What is the output of get(k) if a map M does not contain an entry with key k? A. An error. B. The
value of the last accessed entry. C. null. D. An empty entry.
5. What does put(k, v) return if M already has an entry with key k? A. null. B. The new value v. C.
The old value associated with k. D. The key k.
6. How is java.util.Map related to the map ADT described in the book? A. It is a completely
different data structure. B. It is an abstract class for map implementations. C. It is an interface
for the map ADT, with some different method names. D. It is a concrete implementation of the
map ADT.
7. What is a simple way of implementing a map, particularly efficient for very small maps? A.
Using a hash table. B. Using a balanced binary tree. C. Storing its entries in a list (e.g., doubly
linked list). D. Using a skip list.
8. What is the worst-case running time for get(k), put(k,v), and remove(k) in a list-based map
implementation with n entries? A. O(1). B. O(log n). C. O(n). D. O(n log n).
9. What is separate chaining in hash tables? A. Storing all entries directly in the bucket array. B.
Having each bucket store a small map (e.g., a list) holding entries that hash to the same index.
C. Using a secondary hash function to find empty buckets. D. Reassigning keys to new hash
values upon collision.
10. What is the "load factor" of a hash table? A. The capacity of the bucket array. B. The number
of entries n. C. The ratio n/N (number of entries / capacity). D. The number of collisions that
have occurred.
11. For open addressing schemes in hash tables, what should the load factor ideally be
maintained below? A. 0.9. B. 0.5. C. 0.75. D. 1.0.
12. What happens in the HashTableMap (Code Fragments 9.3-9.5) when the load factor exceeds
0.5? A. It stops accepting new insertions. B. It switches to separate chaining. C. It rehashes the
entire contents into a new array that is twice the size. D. It simply allows the load factor to
increase.
13. What is the main difference between a map and a dictionary as defined in Section 9.3? A.
Maps allow duplicate keys, dictionaries do not. B. Dictionaries can contain different entries with
equal keys (duplicate keys), while maps require unique keys. C. Dictionaries are always ordered,
maps are not. D. Maps are for small data sets, dictionaries for large ones.
14. What is a log file or audit trail an implementation of? A. A map with unique keys. B. An
ordered dictionary. C. A dictionary using an unordered list to store entries, suitable for many
insertions and few searches. D. A hash table.
15. What is the worst-case running time for findAll(k) in a list-based dictionary implementation?
A. O(1). B. O(log n). C. O(n). D. O(n log n).
16. What is an ordered search table? A. A hash table where keys are ordered. B. A dictionary
implemented with an unsorted array. C. A dictionary implemented by storing entries in an array
list in nondecreasing order of keys. D. A linked list that keeps elements sorted.
17. What is the primary advantage of using an ordered array list for dictionary implementation
over a hash table in some applications? A. Lower memory usage. B. Faster update operations.
C. Guaranteed good worst-case searching bounds, unlike hash tables' worst-case. D. Simpler
implementation.
18. What is the search method called where a key k is compared to the median candidate, and
the search continues in either the first or second half? A. Linear search. B. Recursive search. C.
Binary search. D. Ternary search.
19. What is the expected running time for find, insert, and remove operations in a dictionary
implemented with a skip list? A. O(1). B. O(n). C. O(log n). D. O(n log n).
20. What is the expected height of a skip list with n entries? A. About n/2. B. About log n. C. n. D.
sqrt(n).
21. What is a "maximum pair" in the context of maxima sets for price-performance trade-offs?
A. A pair with the highest cost and highest performance. B. A pair that dominates all other pairs.
C. A pair (a,b) that is not dominated by any other pairs (i.e., no other pair (c,d) has c < a and b <
d). D. The pair with the lowest cost and highest performance.
22. What is quadratic probing in hash tables? A. A method that links colliding entries in a list. B.
An open addressing strategy that iteratively tries buckets A[(i + j^2) mod N]. C. A method that
rehashes the table when a collision occurs. D. A technique for optimizing hash function
computation.
23. What is secondary clustering associated with? A. Separate chaining. B. Linear probing. C.
Quadratic probing. D. Double hashing.
24. Which java.util class implements the map ADT and uses a default maximum load factor of
0.75? A. java.util.TreeMap. B. java.util.LinkedHashMap. C. java.util.ConcurrentHashMap. D.
java.util.HashMap.
25. What is a key difference between findAll(k) for a dictionary and get(k) for a map? A. findAll(k)
is faster than get(k). B. findAll(k) returns a single entry, get(k) returns a collection. C. findAll(k)
returns an iterable collection of all entries with key k, while find(k) (map equivalent get(k))
returns an arbitrary one if duplicates exist. D. findAll(k) is only available for ordered dictionaries.
1. What is a search tree used for implementing? A. Stacks. B. Queues. C. Lists. D. Dictionaries.
2. In a binary search tree T, where are dictionary entries typically stored? A. At external nodes
only. B. At internal nodes only. C. At both internal and external nodes. D. At the root only.
3. What property must an inorder traversal of a binary search tree T exhibit? A. Visits keys in
decreasing order. B. Visits keys in random order. C. Visits keys in nondecreasing order. D. Visits
keys in insertion order.
4. In the TreeSearch method for a binary search tree, what happens if the search key k is equal
to key(v) at an internal node v? A. The search continues in the left subtree. B. The search
continues in the right subtree. C. The search terminates successfully. D. The search terminates
unsuccessfully.
5. What is the worst-case running time for search and update operations in a standard binary
search tree with n entries? A. O(log n). B. O(h), where h is the height of the tree. C. O(1). D. O(n
log n).
6. What is the expected height of a binary search tree with n keys generated from a random
series of insertions and removals? A. O(n). B. O(log n). C. O(sqrt(n)). D. O(1).
7. What is the primary goal of AVL trees? A. To achieve O(1) time for all dictionary operations. B.
To minimize memory usage. C. To achieve logarithmic time for all fundamental dictionary
operations by maintaining balance. D. To support parallel processing.
8. What is the height-balance property for an AVL tree? A. The height of a node's left subtree
equals its right subtree. B. The height of a node is at most log n. C. For every node v, the heights
of its children differ by at most 1. D. All external nodes have the same depth.
9. What is a trinode restructuring (Code Fragment 10.6)? A. An operation that removes three
nodes from a tree. B. A way to combine three distinct trees. C. An operation used in AVL trees
(and splay trees) to restore balance by changing parent-child relationships among three nodes.
D. A method for inserting three nodes at once.
10. What is splaying an internal node x in a splay tree? A. Deleting x from the tree. B. Moving x to
the root of the tree through a sequence of restructurings. C. Rebalancing the entire tree from
scratch. D. Changing x's key.
11. What is a zig-zig restructuring in a splay tree? A. When x and y are left and right children,
respectively. B. When x and y are a right child and left child, respectively. C. When the node x
and its parent y are both left children or both right children. D. When x is the root's only child.
12. What are multi-way search trees? A. Search trees with only binary internal nodes. B. Trees
with internal nodes that have two or more children. C. Trees used only for non-ordered
dictionaries. D. Trees that allow searching in multiple directions simultaneously.
13. In a d-node of a multi-way search tree, if it has d children, how many key-value entries does
it store? A. d. B. d + 1. C. d - 1. D. 2d.
14. How many external nodes does an n-entry multi-way search tree have? A. n. B. n + 1. C. 2n.
D. n - 1.
15. What is bootstrapping in the context of representing a multi-way search tree? A. A technique
for optimizing memory usage. B. Using a previously constructed (less advanced) dictionary data
structure to represent the ordered set of entries at each internal node. C. A method for
converting a multi-way tree to a binary tree. D. A way to speed up search operations by pre-
sorting keys.
16. What is the primary efficiency goal for a multi-way search tree? A. To minimize the number of
internal nodes. B. To maximize dmax (maximum children). C. To keep the height h as small as
possible, ideally a logarithmic function of n. D. To ensure f(b) and g(b) are always O(1).
17. What is a (2,4) tree also known as? A. Binary search tree. B. Ternary tree. C. 2-4 tree or 2-3-4
tree. D. AVL tree.
18. What are the two simple properties maintained by a (2,4) tree? A. Node property and Link
property. B. Balance property and Depth property. C. Size property (at most four children) and
Depth property (all external nodes same depth). D. Ordering property and Access property.
19. What is the height of a (2,4) tree storing n entries? A. O(n). B. O(log n). C. O(n log n). D.
O(sqrt(n)).
20. What is the effect of a split operation in a (2,4) tree? A. It increases the height of the tree by
at most one. B. It merges two nodes into one. C. It affects a constant number of nodes and can
be implemented in O(1) time. D. All of the above.
21. What is Proposition 10.6 regarding splay trees? A. It describes the worst-case performance
of splay trees. B. It states that the total running time for a sequence of operations is proportional
to n plus a sum involving log(m/f(i)) for each accessed entry. C. It guarantees O(log n) worst-
case time for all operations. D. It defines the maximum height of a splay tree.
22. What does it mean for a search tree to be balanced? A. All nodes have the same number of
children. B. The search time is always O(1). C. The height h is a logarithmic function of n (total
entries). D. It is implemented using an array.
23. What is the relationship between red-black trees and (2,4) trees? A. They are completely
unrelated data structures. B. A red-black tree is a simplified version of a (2,4) tree. C. A red-
black tree can be colored to correspond to a (2,4) tree, sharing a strong structural relationship.
D. (2,4) trees are always faster than red-black trees.
24. How many trinode restructuring operations are needed at most to restore balance after any
insertion in an AVL tree (Exercise C-10.11)? A. Two. B. Three. C. One. D. Log(n).
25. What is the worst-case height of a standard binary search tree storing 100,000 entries
(Exercise R-10.20)? A. O(log n). B. O(sqrt(n)). C. O(n). D. O(n log n).
3. What is the running time of the merge-sort algorithm on an n-element sequence? A. O(n). B.
O(n log n). C. O(n^2). D. O(1).
4. In quick-sort, what is the special element chosen from the sequence S called? A. The
median. B. The key element. C. The pivot. D. The head element.
5. What are the three sequences that elements are put into during the divide step of quick-sort?
A. Small, Equal, Large. B. Left, Middle, Right. C. L (less than pivot), E (equal to pivot), G (greater
than pivot). D. First, Second, Third.
6. What is the worst-case height of a quick-sort tree? A. O(log n). B. O(sqrt(n)). C. n - 1. D. O(n
log n).
7. What is the auxiliary space requirement for a nonrecursive in-place quick-sort designed to
guarantee O(log n) stack size? A. O(n). B. O(n - 1). C. O(log n). D. O(1).
8. What type of tree can represent a comparison-based sorting algorithm? A. Binary search tree.
B. AVL tree. C. Decision tree. D. Splay tree.
9. What is radix-sort used for? A. Sorting general comparable elements in O(n log n) time. B.
Sorting elements with keys that have no specific range. C. Sorting sequences of key-value pairs
where keys are d-tuples of integers in a range [0, N-1]. D. Sorting elements by swapping adjacent
pairs.
10. What is the running time of radix-sort for sorting n key-value pairs with d-tuple keys (each ki
in [0, N-1])? A. O(n + N). B. O(d log n). C. O(d(n + N)). D. O(n log N).
11. Which sorting algorithm is described as a "poor choice in any application" due to its O(n^2)
time behavior even in the best case? A. Merge-sort. B. Quick-sort. C. Heap-sort. D. Selection-
sort.
12. What does A ∩ B represent in set theory? A. The union of sets A and B. B. The difference
between sets A and B. C. The intersection of sets A and B (elements in both A and B). D. The
symmetric difference of sets A and B.
13. What is an application of set intersection mentioned in the context of search engines? A.
Ranking pages by relevance. B. Finding web pages containing a single keyword. C. Computing
the intersection of W(x) ∩ W(y) for a two-word query (x and y). D. Sorting search results by
priority.
14. What is the selection problem? A. Finding the minimum element in an unsorted collection.
B. Finding the maximum element in an unsorted collection. C. Finding the median element in an
unsorted collection. D. Selecting the kth smallest element from an unsorted collection of n
comparable elements.
15. What is the running time for solving the selection problem by sorting the collection first? A.
O(n). B. O(n log n). C. O(log n). D. O(n^2).
16. What algorithmic design pattern is Randomized Quick-Select an example of? A. Divide-and-
conquer. B. Dynamic programming. C. Brute force. D. Prune-and-search (or decrease-and-
conquer).
17. In quickSelect(S,k), if k is less than or equal to the size of L (elements less than pivot), where
does the algorithm recursively call itself? A. quickSelect(E, k). B. quickSelect(G, k - |L| - |E|). C.
quickSelect(L, k). D. It returns the pivot x.
18. Is the merge-sort algorithm stable? A. No, it is never stable. B. Yes, it is stable. C. Only if the
input elements are distinct. D. Only if implemented with arrays.
19. What is an inversion in a sequence S (Exercise C-11.20)? A. A pair of elements x and y such
that x appears after y in S and x < y. B. A pair of elements x and y such that x appears before y in S
but x > y. adding the lowest-weight edge connecting a component to another. D. It only works for
unweighted graphs.
20. What is Proposition 11.9 concerning makeSet, union, and find operations using a sequence-
based implementation of a partition data structure? A. It takes O(n) time. B. It takes O(n log n)
time. C. It takes O(n^2) time. D. It takes O(log n) time.
21. What is α(n) (the inverse of the Ackerman function) described as? A. A fast-growing function.
B. A logarithmically growing function. C. An incredibly slow-growing function, much slower than
log* n. D. A constant-time function.
22. What is stable sorting? A. An algorithm that guarantees O(n log n) worst-case time. B. An
algorithm that is always in-place. C. An algorithm that preserves the relative order of elements
with equal keys. D. An algorithm that sorts elements regardless of their initial order.
23. In the deterministic quick-select algorithm described in Exercise C-11.31, how is the pivot
chosen? A. Randomly from the sequence. B. As the last element of the sequence. C. By
partitioning into groups of 5, sorting each, finding the median of these medians recursively, and
using that as pivot. D. As the first element of the sequence.
24. What is the running time of the deterministic quick-select algorithm (Exercise C-11.31)? A.
O(n log n). B. O(n^2). C. O(n). D. O(log n).
1. What are character strings at the heart of algorithms for processing? A. Numerical data. B.
Binary sequences. C. Text. D. Graphical objects.
2. What is the indexOf(Q) method of the Java String class (for pattern matching)? A. Returns the
last occurrence of Q in S. B. Returns the length of Q if it's a substring. C. If Q is a substring of S,
returns the index of the beginning of the first occurrence of Q in S, else returns -1. D. Checks if Q
is a suffix of S.
3. What does the StringBuffer class provide that the String class does not? A. Immutable string
operations. B. Mutable string operations. C. Faster character access. D. Built-in pattern
matching algorithms.
4. In the classic pattern matching problem, what are we given? A. A pattern string P and a
dictionary of words. B. A text string T of length n and a pattern string P of length m, to find if P is a
substring of T. C. Two text strings T1 and T2 to find their commonalities. D. A text string T and a
set of keywords to find.
5. What is the brute force algorithmic design pattern? A. Optimizing a function by selecting
locally optimal choices. B. Enumerating all possible configurations of inputs and picking the
best. C. Recursively dividing a problem into smaller subproblems. D. Preprocessing the input to
speed up subsequent queries.
6. What is the worst-case running time of the brute-force pattern matching algorithm? A. O(n +
m). B. O(m). C. Ω(nm). D. O(n log m).
7. What is a key assumption of the Boyer-Moore (BM) pattern matching algorithm? A. The
alphabet size can be unbounded. B. The alphabet is of fixed, finite size. C. The pattern is very
short. D. It must be implemented with a trie.
8. What is last(c) in the Boyer-Moore algorithm? A. The last occurrence of character c in the text
T. B. The index of the last occurrence of character c in the pattern P. C. The number of characters
remaining in P. D. A boolean indicating if c is the last character of P.
9. What does the Knuth-Morris-Pratt (KMP) algorithm use to determine where to continue
checking P against T after a mismatch? A. The last function. B. A random number generator. C.
The failure function. D. A brute-force re-scan.
10. What is the main idea behind trie data structures for string searching? A. Preprocessing the
pattern string. B. Preprocessing the text string for a series of queries. C. Searching for patterns in
a random fashion. D. Compressing the text for efficient storage.
11. In a standard trie, how are the have the same length. B. All strings must start with a unique
character. C. This ensures that each string of S is uniquely associated with an external node. D.
This allows for faster insertions.
12. What is the running time of searching for a string of size m in a standard trie with an alphabet
of size d? A. O(m) if d is constant. B. O(log m). C. O(dm). D. O(d).
13. What is word matching (with a trie) different from standard pattern matching? A. It finds any
occurrence of the pattern. B. It matches patterns that span two words. C. The pattern can only
match one of the words of the text exactly. D. It uses dynamic programming.
14. What is a compressed trie also known as? A. Standard trie. B. Radix trie. C. Patricia trie. D.
Suffix trie.
15. What is the main space inefficiency in a standard trie that compressed tries address? A. Too
many external nodes. B. Potentially many internal nodes with only one child. C. Redundant
character labels. D. Inefficient storage of strings.
16. What is the number of nodes of a compressed trie storing s strings? A. O(n), where n is total
length of strings. B. O(s). C. O(s log d). D. O(d).
17. What is the suffix trie for a string X used for? A. Text compression. B. Efficiently performing
pattern matching queries on text X. C. Building an inverted index. D. Finding the longest
common subsequence.
18. What is an inverted index (or inverted file) in a search engine? A. A list of all web pages. B. A
dictionary mapping pages to words. C. A dictionary storing key-value pairs (w, L), where w is a
word and L is a collection of pages containing w. D. A sorted list of all words on the web.
19. What algorithmic design pattern is Huffman Coding an application of? A. Dynamic
Programming. B. Divide-and-Conquer. C. Greedy Method. D. Brute Force.
20. What is the greedy-choice property in the greedy method? A. That the algorithm always
chooses the largest available option. B. That the algorithm makes choices that are globally
optimal from the start. C. That a global optimal condition can be reached by a series of locally
optimal choices. D. That the algorithm may not lead to an optimal solution.
21. What is the **`longest common subsequence (L). B. O(n+m). C. O(2^n * m). D. O(n log m).
22. What algorithmic design pattern is used to solve the LCS problem efficiently? A. Greedy
method. B. Brute force. C. Dynamic Programming. D. Recursion (without dynamic
programming).
23. What are the three properties a problem must possess to be solvable by dynamic
programming? A. Simplicity, Correctness, and Efficiency. B. Simple Subproblems, Subproblem
Optimization, and Subproblem Overlap. C. Divide, Conquer, and Combine. D. Base Cases,
Recursive Calls, and Progress.
1. What is a graph in the context of this chapter? A. A bar chart or function plot. B. A set of
objects, called vertices, together with a collection of pairwise connections, called edges,
between them. C. A hierarchical data structure like a tree. D. A linear sequence of elements.
2. What is a digraph? A. A graph with no directed edges. B. A graph with both directed and
undirected edges. C. A graph whose edges are all directed. D. A graph where all edges are self-
loops.
3. What are parallel edges (or multiple edges)? A. Edges that connect a vertex to itself. B. Edges
that have no common endpoints. C. Two (or more) edges that have the same end vertices (or
origin and destination for directed). D. Edges with different weights.
4. What is a self-loop? A. An edge that connects two distinct vertices. B. An edge whose two
endpoints coincide (connects a vertex to itself). C. An edge with a negative weight. D. An edge
that creates a cycle.
5. What does it mean for a graph to be simple? A. It has only a few vertices and edges. B. It uses
an adjacency list representation [537What is a simple path? A. A path that has its start and end
vertices the same. B. A path that includes all edges in the graph. C. A path where each vertex in
the path is distinct. D. A path where all edges are directed.
7. What is a forest? A. A connected graph without cycles. B. A graph with many cycles. C. A
graph without cycles. D. A graph that contains all vertices of another graph.
8. What is a spanning tree of a graph? A. Any subgraph that is a tree. B. A subgraph that is a tree
and contains only the root vertex. C. A spanning subgraph that is a (free) tree. D. A tree with a
specified root.
10. Which graph data structure explicitly stores a collection of edges and a collection of
vertices, and supports O(1) time for endVertices(e) and opposite(v,e)? A. Adjacency matrix of
edges).** D. It requires too much memory.
11. What is the time complexity of DFS (Depth-First Search) on a graph G with n vertices and m
edges represented with an adjacency list structure? A. O(n^2). B. O(log n). C. O(n + m). D. O(m).
12. What do the discovery edges form in a DFS traversal of a connected component? A. A cycle.
B. A spanning tree. C. A path from start to end. D. A connected component itself.
13. What types of nontree edges can exist in a directed DFS (unlike undirected DFS)? A. Only
back edges and cross edges. B. Only forward edges and cross edges. C. Back edges, forward
edges, and cross edges. D. Only back edges.
Certainly, here are some multiple-choice questions (MCQs) related to Chapter 13 on Graphs,
drawing from the provided sources:
---
**1. Which of the following best defines a "simple graph" according to the sources?**
a) O(n)
b) O(m)
c) **O(n + m)**
d) O(n * m)
**3. Which graph traversal algorithm is analogous to "wandering in a labyrinth with a string and
a can of paint" and divides edges into "discovery edges" and "back edges"?**
c) Prim-Jarník Algorithm
d) Dijkstra's Algorithm
**4. According to the source, if a graph is represented with an adjacency list, what is the worst-
case time complexity of a Depth-First Search (DFS) traversal?**
a) O(n)
b) O(m)
c) **O(n + m)**
d) O(n * m)
**Answer: c) A graph that has a numeric label `w(e)` associated with each edge `e`, called
the weight of edge `e`**.
a) Divide-and-conquer
b) Dynamic programming
c) **Greedy method**
d) Brute force
**7. For Dijkstra's algorithm to correctly compute shortest paths, what is a crucial assumption
about the edge weights in the graph?**
**8. Which of the following problems can be solved using an O(n + m)-time algorithm based on
Breadth-First Search (BFS) for a graph with `n` vertices and `m` edges represented with the
adjacency list structure?**
a) Computing a path with the minimum number of edges between two given vertices.
**10. Kruskal's algorithm builds a Minimum Spanning Tree (MST) by initially treating each vertex
as its own cluster. What is its next step in each iteration?**
c) **It considers each edge in turn, ordered by increasing weight, and adds it if it connects two
different clusters**.
**Answer: c) It considers each edge in turn, ordered by increasing weight, and adds it if it
connects two different clusters**.
---Certainly! Here are multiple-choice questions (MCQs) from Chapter 14 (Memory) and
Appendix A (Useful Mathematical Facts), complete with answers and citations from the
provided sources.
---
**1. According to the sources, computer memory can be fundamentally viewed as:**
**2. Which of the following is NOT one of the two main places where the Java Virtual Machine
(JVM) uses a stack?**
d) For writing and reading elements to and from memory (operand stack).
*Explanation: While memory allocation happens, it's typically in the "memory heap", not
directly on the operand or method stacks for the allocation itself. The memory heap is a
separate region managed for objects.*
**3. In the context of memory allocation from the heap, which algorithm searches the entire
free list to find the hole whose size is closest to the amount of memory requested?**
a) First-fit algorithm
b) Next-fit algorithm
c) Worst-fit algorithm
d) **Best-fit algorithm**
**4. The memory hierarchy in computers consists of levels that vary in terms of their size and
distance from the CPU. Which level is typically the largest and slowest?**
a) Internal registers
b) Cache memory
c) **To minimize the number of disk transfers needed to perform a query or update.**
**Answer: c) To minimize the number of disk transfers needed to perform a query or update.**
**6. In the context of two-level computer memory systems, the concept of bringing a large block
of contiguous locations into primary-level memory when data at a secondary-level location is
accessed is known as:**
a) Virtual memory
b) Caching
c) **Blocking**
d) Fragmentation
**Answer: c) Blocking.**
**7. A B-tree of order `d` is defined as an `(a, b)` tree where `a` and `b` are specifically set
to:**
a) `a = d` and `b = 2d`
b) `a = 2` and `b = 4`
c) `a = 2` and `b = d`
---
a) `a = c^b`
b) `b = a^c`
c) `c = b^a`
d) **`a = bc`**
**Answer: d) `a = bc`.**
**2. Which of the following is the correct identity for `log(ac)` according to the logarithm rules
provided?**
a) `c loga`
b) `log a + log c`
c) `log a / log c`
d) **`log a + log c`** (Assuming base `b` is omitted for brevity, so `logbac = logba + logbc`)
*Explanation: The source provides `logbac = logba + logbc` as the first rule. When applied to
`log(ac)` (implying the same base for all logarithms), this simplifies to `log a + log c`.*
a) `n * (n-1)`
b) `n + (n-1) + ... + 1`
d) `n^n`
**5. What is the sum of the geometric series `a^0 + a^1 + ... + a^n` for any fixed real number `0
< a ≠ 1`?**
a) `a^(n+1)`
b) `(a^n - 1) / (a - 1)`
d) **`(a^(n+1) - 1) / (a - 1)`**
**6. For two random variables `X` and `Y`, and a number `c`, what does the Linearity of
Expectation state regarding `E(X + Y)` and `E(cX)`?**
**7. In the Master Method for characterizing divide-and-conquer recurrence relations of the
form `T(n) = aT(n/b) + f(n)`, if `f(n)` is `O(nlogb a − ε)` for some constant `ε > 0`, then `T(n)`
is:**
a) `Θ(f(n))`
b) `Θ(nlogb a logk+1n)`
c) **`Θ(nlogb a)`**
d) `Θ(n)`
---