

Algorithms and Data Structures
Mock Exam
Course Introduction
This course provides a comprehensive introduction to foundational algorithms and core data structures, equipping students with the analytical and practical skills necessary for computational problem-solving. Topics include algorithm design techniques, such as divide and conquer, recursion, greedy methods, and dynamic programming, as well as the study and implementation of essential data structures like arrays, linked lists, stacks, queues, trees, and graphs. Emphasis is placed on evaluating algorithmic efficiency, complexity analysis (including Big O notation), and the trade-offs involved in selecting data structures for specific applications. Through projects and exercises, students gain hands-on experience in writing and optimizing code, deepening their understanding of how algorithms and data structures underpin computer science and software development.
Recommended Textbook
Starting Out with Java From Control Structures through Data Structures 2nd Edition by Tony Gaddis
Available Study Resources on Quizplus
22 Chapters
981 Verified Questions
981 Flashcards
Source URL: https://quizplus.com/study-set/3640

Page 2

Chapter 1: Introduction to Computers and Java
Available Study Resources on Quizplus for this Chatper
42 Verified Questions
42 Flashcards
Source URL: https://quizplus.com/quiz/72352
Sample Questions
Q1) Which of the following will run the compiled program ReadIt?
A) java ReadIt.java
B) java ReadIt
C) run ReadIt
D) go ReadIt
Answer: B
Q2) A byte is a collection of:
A) Four bits
B) Six bits
C) Eight bits
D) A dollar
Answer: C
Q3) Because Java byte code is the same on all computers,compiled Java programs
A) Must be re-compiled for each different machine it is run on
B) Cannot run on Linux systems
C) Are non-existent
D) Are highly portable
Answer: D
To view all questions and flashcards with answers, click on the resource link above.
3

Chapter 2: Java Fundamentals
Available Study Resources on Quizplus for this Chatper
53 Verified Questions
53 Flashcards
Source URL: https://quizplus.com/quiz/72353
Sample Questions
Q1) What will be the value of z as a result of executing the following code? int x = 5,y = 28; Float z;
Z = (float)(y / x);
A) 5.60
B) 5.6
C) 3.0
D) 5.0
Answer: D
Q2) To print "Hello,world" on the monitor,use the following Java statement
A) SystemOutPrintln("Hello,world");
B) System.out.println{"Hello,world"}
C) System.out.println("Hello,world");
D) Print "Hello,world";
Answer: C
Q3) A variable's scope is the part of the program that has access to the variable.
A)True
B)False
Answer: True
To view all questions and flashcards with answers, click on the resource link above.
4

Chapter 3: Decision Structures
Available Study Resources on Quizplus for this Chatper
52 Verified Questions
52 Flashcards
Source URL: https://quizplus.com/quiz/72354
Sample Questions
Q1) If str1 and str2 are both Strings,which of the following expressions will correctly determine whether they are equal? (1)(str1 == str2) (2)str1.equals(str2)
(3)(str1.compareTo(str2)== 0)
A) 1,2,and 3 will all work
B) 1 and 2
C) 1 and 3
D) 2 and 3
Answer: D
Q2) What will be the value of ans after the following code has been executed? int ans = 10;
Int x = 65;
Int y = 55; If (x >= y)
Ans = x + y;
A) 10
B) 120
C) 100
D) No value,there is a syntax error
Answer: B
To view all questions and flashcards with answers, click on the resource link above.
Page 5

Chapter 4: Loops and Files
Available Study Resources on Quizplus for this Chatper
48 Verified Questions
48 Flashcards
Source URL: https://quizplus.com/quiz/72355
Sample Questions
Q1) A loop that executes as long as a particular condition exists is called a(n)
A) sentinel loop
B) conditional loop
C) count-controlled loop
D) infinite loop
Q2) When you pass the name of a fi le to the PrintWriter constructor,and the file already exists,it will be erased and a new empty file with the same name will be created.
A)True
B)False
Q3) You can use this method to determine whether a file exists.
A) The Scanner class's exists method
B) The File class's exists method
C) The File class's canOpen method
D) The PrintWriter class's fileExists method
Q4) A file must always be opened before using it and closed when the program is finished using it.
A)True
B)False
To view all questions and flashcards with answers, click on the resource link above.

Chapter 5: Methods
Available Study Resources on Quizplus for this Chatper
50 Verified Questions
50 Flashcards
Source URL: https://quizplus.com/quiz/72356
Sample Questions
Q1) Which of the following is not a benefit derived from using methods in programming?
A) problems are more easily solved
B) simplifies programs
C) code reuse
D) all of the above are benefits
Q2) What will be returned from the following method? public static double methodA()
{
Double a = 8.5 + 9.5;
Return a;
A) 18.0
B) 18 (as an integer)
C) 8
D) This is an error
Q3) No statement outside the method in which a parameter variable is declared can access the parameter by its name.
A)True
B)False
To view all questions and flashcards with answers, click on the resource link above.

Chapter 6: A First Look at Classes
Available Study Resources on Quizplus for this Chatper
49 Verified Questions
49 Flashcards
Source URL: https://quizplus.com/quiz/72357
Sample Questions
Q1) Look at the following statement. import java.util.*; This is an example of
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
Q2) Which of the following statements will create a reference,str,to the String,"Hello,World"?
A) String str = "Hello,World";
B) string str = "Hello,World";
C) String str = new "Hello,World";
D) str = "Hello,World";
Q3) Look at the following statement. import java.util.Scanner; This is an example of
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
To view all questions and flashcards with answers, click on the resource link above.
8

Chapter 7: A First Look at Gui Applications
Available Study Resources on Quizplus for this Chatper
49 Verified Questions
49 Flashcards
Source URL: https://quizplus.com/quiz/72358
Sample Questions
Q1) To include Swing and AWT components in your program,use the following import statements
A) import java.swing;import java.awt;
B) import java.swing;import javax.awt;
C) import javax.swing;import java.awt;
D) import javax.swing;import javax.awt;
Q2) The minimize button,maximize button,and close button on a window are sometimes referred to as
A) operations buttons
B) sizing buttons
C) decorations
D) display buttons
Q3) To end an application,pass this as the argument to the JFrame class's setDefaultCloseOperation()method.
A) END_ON_CLOSE
B) JFrame.END_ON_CLOSE
C) JFrame.EXIT_ON_CLOSE
D) JFrame.CLOSE_NOT_HIDE
To view all questions and flashcards with answers, click on the resource link above.

Chapter 8: Arrays and the Arraylist Class
Available Study Resources on Quizplus for this Chatper
52 Verified Questions
52 Flashcards
Source URL: https://quizplus.com/quiz/72359
Sample Questions
Q1) What will be returned from the following method? public static float[] getValue(int x)
A) A float value
B) An array of float values
C) An integer
D) An array of integers
Q2) An ArrayList object automatically expands in size to accommodate the items stored in it.
A)True
B)False
Q3) You can use this ArrayList class method to replace an item at a specific location in an ArrayList.
A) replace
B) add
C) store
D) set
Q4) If a[] and b[] are two integer arrays,the expression a == b compares the array contents.
A)True B)False
To view all questions and flashcards with answers, click on the resource link above. Page 10

Chapter 9: A Second Look at Classes and Objects
Available Study Resources on Quizplus for this Chatper
40 Verified Questions
40 Flashcards
Source URL: https://quizplus.com/quiz/72360
Sample Questions
Q1) A static field is created by placing
A) the key word static after the field name
B) the key word static after the access specifier and before the field's data type
C) the key word static after the access specifier and field's data type
D) it in a static field block
Q2) An instance of a class does not have to exist in order for values to be stored in a class's static fields.
A)True
B)False
Q3) A deep copy of an object
A) is an assignment of that object to another object
B) is an operation that copies an aggregate object,and all the objects it references
C) is a bogus term,it has no meaning
D) is always a private method
Q4) A class's static methods do not operate on the fields that belong to any instance of the class.
A)True
B)False
To view all questions and flashcards with answers, click on the resource link above.
11
Chapter 10: Text Processing and More About Wrapper
Classes
Available Study Resources on Quizplus for this Chatper
49 Verified Questions
49 Flashcards
Source URL: https://quizplus.com/quiz/72361
Sample Questions
Q1) Given the following statement,which of the following is not true? str.insert(8,32);
A) str is a StringBuilder type object
B) The insert will start at position 32
C) The starting position for the insert is 8
D) The literal number 32 will be inserted
Q2) What will be the value of matches after the following code is executed? boolean matches;
String[] productCodes = {"456HI345","3456hj"};
Matches = productCodes[0].regionMatches(true,1, ProductCodes[1],2,3);
A) 56H
B) 56h
C) true
D) false
Q3) To convert the string,str = "285" to an int,use the following statement
A) int x = str;
B) int x = Integer.parseInteger(str);
C) int x = Integer.integer(str);
D) int x = Integer.parseInt(str);

Page 12
To view all questions and flashcards with answers, click on the resource link above.

Chapter 11: Inheritance
Available Study Resources on Quizplus for this Chatper
49 Verified Questions
49 Flashcards
Source URL: https://quizplus.com/quiz/72362
Sample Questions
Q1) If you do not provide an access specifier for a class member,the class member is given ___________ by default.
A) private
B) public
C) protected
D) package
Q2) All methods in an abstract class must also be declared abstract.
A)True
B)False
Q3) A protected member of a class may be directly accessed by
A) methods of the same class
B) methods of a subclass
C) methods in the same package
D) All of the above.
Q4) If a method in a subclass has the same signature as a method in the superclass,the subclass method overloads the superclass method.
A)True
B)False
To view all questions and flashcards with answers, click on the resource link above.
Page 13

Chapter 12: Exceptions and Advanced File Io
Available Study Resources on Quizplus for this Chatper
46 Verified Questions
46 Flashcards
Source URL: https://quizplus.com/quiz/72363
Sample Questions
Q1) In a catch statement,what does the following code do? System.out.println(e.getMessage());
A) It prints the stack trace.
B) It prints the error message for an exception.
C) It prints the code that caused the exception.
D) It overrides the toString method
Q2) The IllegalArgumentException class extends the RuntimeException class,and is therefore
A) a checked exception class.
B) an unchecked exception class
C) never used directly
D) None of the above
Q3) If a random access file contains a stream of characters,which of the following would you use to set the pointer on the fifth character?
A) file.seek(4);
B) file.seek(5);
C) file.seek(9);
D) file.seek(8);
To view all questions and flashcards with answers, click on the resource link above.
14

Chapter 13: Advanced Gui Applications
Available Study Resources on Quizplus for this Chatper
46 Verified Questions
46 Flashcards
Source URL: https://quizplus.com/quiz/72364
Sample Questions
Q1) The following statement textList.setSelectionMode( ListSelectModel.SINGLE_INTERVAL_SELECTION);
A) sets the textList component to single selection mode.
B) sets the textList component to ListSelectModel.
C) sets the textList component to single interval selection mode.
D) sets the value of textList to SINGLE_INTERVAL_SELECTION.
Q2) What will display when the following code is executed: JButton button = New JButton ("It is a beautiful day."); Button.setIcon(SunnyFace.gif);
A) A button with the text "It is a beautiful day." to the left of the SunnyFace image.
B) A button with the text "It is a beautiful day." to the right of the SunnyFace image.
C) A button with the text "It is a beautiful day." below the SunnyFace image.
D) A button with the text "It is a beautiful day." above the SunnyFace image.
Q3) The JMenuBar method is a(n)
A) JFrame method
B) JPanel method
C) JMenu method
D) JTextComponent method
To view all questions and flashcards with answers, click on the resource link above.
15
Chapter 14: Applets and More
Available Study Resources on Quizplus for this Chatper
39 Verified Questions
39 Flashcards
Source URL: https://quizplus.com/quiz/72365
Sample Questions
Q1) Given the following code,how many times per second will the TimerListener event be generated? Timer timer = new Timer(1000,new TimerListener());
A) 1
B) 10
C) 100
D) 1000
Q2) Which of the following sound file formats does Java not support?
A) .wav
B) .au
C) .mid
D) Java supports all of the above
Q3) An applet using a Swing GUI is extended from this class.
A) JFrame
B) JLabel
C) JSwing
D) JApplet
Q4) The Applet class requires that you write a constructor to create an object of the class.
A)True
B)False

Page 16
To view all questions and flashcards with answers, click on the resource link above.

Chapter 15: Recursion
Available Study Resources on Quizplus for this Chatper
34 Verified Questions
34 Flashcards
Source URL: https://quizplus.com/quiz/72366
Sample Questions
Q1) Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What is the recursive case for the algorithm?
A) x < 8
B) 2 * x
C) x != 8
D) x >= 8
Q2) A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem.
A)True
B)False
Q3) The number of times that a method calls itself is known as the
A) height of recursion
B) depth of recursion
C) width of recursion
D) length of recursion
To view all questions and flashcards with answers, click on the resource link above. Page 17

Chapter 16: Sorting, Searching, and Algorithm Analysis
Available Study Resources on Quizplus for this Chatper
46 Verified Questions
46 Flashcards
Source URL: https://quizplus.com/quiz/72367
Sample Questions
Q1) The Quicksort algorithm works by
A) repeatedly comparing adjacent items and swapping them so smaller values come before larger values
B) repeatedly locating the smallest value in the unsorted portion of the array and moving it toward the lower end of the array
C) repeatedly taking the first value in the unsorted portion of the array and placing it at its proper place in the part of the array that is already sorted
D) partitioning the unsorted portion of the array into two sublists and a pivot and recursively sorting the two sublists
Q2) The worst case complexity function is a good measure to use when
A) the load on the system is heaviest
B) we want a guarantee on the performance of an algorithm
C) the best case complexity would lead to incorrect results
D) we want to create an efficient algorithm
To view all questions and flashcards with answers, click on the resource link above.
Chapter 17: Generics
Available Study Resources on Quizplus for this Chatper
50 Verified Questions
50 Flashcards
Source URL: https://quizplus.com/quiz/72368
Sample Questions
Q1) Consider a method of the form
Void printPoint(Point< Number > p){
//Code not shown
}
Where Point< T > is a generic type.When the method is called,the only objects that may be passed for the parameter p are
A) Point< Number > objects only
B) Point< T > objects,where T is the Number class,or is any subclass of Number
C) Point< T > objects,where T is the Number class,or is any superclass of Number
D) All of the above
Q2) Which of the following statements is true?
A) Interfaces may not be generic in Java
B) The keyword implements cannot be used do describe a type parameter that implements an interface
C) a generic class may not have more than one type parameter in its declaration
D) None of the above statements are true.
To view all questions and flashcards with answers, click on the resource link above.

19
Chapter 18: Collections
Available Study Resources on Quizplus for this Chatper
50 Verified Questions
50 Flashcards
Source URL: https://quizplus.com/quiz/72369
Sample Questions
Q1) The default implementation of hashCode in Java returns
A) a value determined from the class type of the object
B) a value derived from the memory address of the object
C) a value determined from the values of the fields in the object
D) None of the above
Q2) Which of the following is true?
A) The ListIterator interface is a subinterface of the Iterator interface
B) The ListIterator interface is a superinterface of the Iterator interface
C) The ListIterator interface extends the List interface
D) None of the above
Q3) Which of the following is true?
A) Both the Set and List interfaces extend the Collection interface
B) Both the Set and Map interfaces extend the Collection interface
C) Both the List and Map interfaces extend the Collection interface
D) None of the above
Q4) A collection whose elements are pairs of keys and values is called
A) an enumerator
B) a map
C) a hash list
D) a paired collection

Page 20
To view all questions and flashcards with answers, click on the resource link above.

Chapter 19: Array-Based Lists
Available Study Resources on Quizplus for this Chatper
20 Verified Questions
20 Flashcards
Source URL: https://quizplus.com/quiz/72370
Sample Questions
Q1) Why does the Java Collections Framework define a List as an interface rather than a class?
A) To be consistent with earlier versions of Java
B) To allow different types of concrete classes,with different performance characteristics to implement the interface
C) To allow the use of generic types
D) All of the above
Q2) The difference between an array and an ArrayList is
A) an ArrayList uses a LinkedList to hold its elements,an array does not.
B) an array keeps track of its length while an ArrayList does not track comparable information
C) arrays have a fixed size and cannot grow to accommodate more elements
D) All of the above
Q3) The position of an item within a list is called its A) index
B) rank
C) level
D) number
To view all questions and flashcards with answers, click on the resource link above.
21
Chapter 20: Linked Lists
Available Study Resources on Quizplus for this Chatper
36 Verified Questions
36 Flashcards
Source URL: https://quizplus.com/quiz/72371
Sample Questions
Q1) To remove a node with a positive index k from a linked list, A) decrement k by 1,and set the reference to the node to be removed to null B) start a reference r at the head of the list,walk r forward k steps,and then set r to null
C) assign the successor reference in the node with index k to the successor reference in the node with index k-1
D) decrement k by 1,and then use recursion
Q2) A list method E remove(int index)designed to remove and return the element at the given index should throw IndexOutOfBoundsException when
A) the index is 0
B) the index is negative,and greater than the size of the list
C) the index is negative,or is greater than the size of the list
D) the index is negative,or is greater than,or equal to,the size of the list
Q3) A circularly linked list makes it easy to
A) move from any node to its predecessor
B) move from any node to its successor
C) jump from the last node to the first D) jump from node to node
To view all questions and flashcards with answers, click on the resource link above.

Page 22

Chapter 21: Stacks and Queues
Available Study Resources on Quizplus for this Chatper
36 Verified Questions
36 Flashcards
Source URL: https://quizplus.com/quiz/72372
Sample Questions
Q1) In a list implementation of a queue,the end of the list from which elements are removed is called
A) the front of the queue
B) the rear of the queue
C) the top of the queue
D) the bottom of the queue
Q2) In a list implementation of a queue,the end of the list at which elements are added is called
A) the front of the queue
B) the rear of the queue
C) the head of the queue
D) the bottom of the queue
Q3) The stack peek operation
A) checks a stack to see if there are any elements in it
B) removes and returns an item from the stack
C) returns the item at the top of the stack,but does not remove it
D) adds a single item to the stack
To view all questions and flashcards with answers, click on the resource link above.
Chapter 22: Binary Trees, Avl Trees, and Priority Queues
Available Study Resources on Quizplus for this Chatper
45 Verified Questions
45 Flashcards
Source URL: https://quizplus.com/quiz/72373
Sample Questions
Q1) Consider the operation of deleting the root of a binary search tree.If the root has two children,then
A) the root node should be removed,then the least node in the right subtree should be deleted and used to replace the root
B) the rood node should be removed,and the deepest rightmost leaf should be used to replace the root
C) the rood node should be removed,the deepest rightmost leaf should be used to replace the root,and then a sift down should be performed to take the root replacement to its proper place
D) the operation should be recursively performed on the two subtrees of the root.
Q2) A binary tree is a collection of nodes in which
A) each node has at most one predecessor and at most one successor
B) each node has at most one predecessor and exactly two successors
C) each node has at most one predecessor and at most two successors
D) each node has at least one predecessor and at most two successors
To view all questions and flashcards with answers, click on the resource link above.

24