

Computer Science II
Final Test Solutions
Course Introduction
Computer Science II builds upon the foundational concepts introduced in introductory programming courses by exploring more advanced topics such as object-oriented programming, data structures (including arrays, linked lists, stacks, and queues), recursion, and algorithm analysis. Students will deepen their problem-solving and programming skills by designing, implementing, and testing increasingly complex software applications in a modern programming language. The course emphasizes principles of code reusability, maintainability, and modularity, preparing students for upper-level computer science coursework and real-world software development challenges.
Recommended Textbook
Data Abstraction and Problem Solving with Java Walls and Mirrors 3rd Edition by Janet Prichard
Available Study Resources on Quizplus
15 Chapters
870 Verified Questions
870 Flashcards
Source URL: https://quizplus.com/study-set/2590 Page 2

Chapter 1: Review of Java Fundamentals
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51576
Sample Questions
Q1) The following code containing a loop attempts to find how many times the letter 'r' appears in a string.But something is wrong with the loop.How would you fix it?
String s = "railroad"; int count = 0; char letter = s.charAt(index); for (int index = 0;index < s.length();++index) if (letter == 'r') ++count;
Answer: The assignment to letter needs to be moved down into the loop right before we check to see if the letter is an r.
Q2) A built-in class that helps to split strings into pieces,such as words of a sentence,is:
A)Console
B)Scanner
C)StringBuffer
D)StringTokenizer
Answer: D
To view all questions and flashcards with answers, click on the resource link above.

Page 3
Chapter 2: Principles of Programming and Software Engineering
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51577
Sample Questions
Q1) If two programs perform the same task,then the faster program is always better.
A)True
B)False Answer: False
Q2) Which of the following is an example of a syntax error?
A)a program encounters an instruction to divide by zero
B)an array subscript in a program goes out of range
C)the beginning of a while loop is written as "whille" instead of "while"
D)an algorithm that calculates the monthly payment of a loan displays incorrect results
Answer: C
Q3) Abstraction separates the purpose of a module from its implementation.
A)True
B)False Answer: True
Q4) The specifications of a module indicate how that module should be implemented.
A)True
B)False Answer: False

Page 4
To view all questions and flashcards with answers, click on the resource link above.
Chapter 3: Recursion: the Mirrors
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51578
Sample Questions
Q1) When is the base case first > last (where first is the index of the first item in the array and last is the index of the last item in the array)reached in a recursive binary search algorithm?
Answer: This base case is reached when the value being searched for is not in the original array.
Q2) A ______ is a mathematical formula that generates the terms in a sequence from previous terms.
A)local environment
B)pivot item
C)base case
D)recurrence relation
Answer: D
Q3) A method that is declared as static is an object method.
A)True
B)False
Answer: False
Q4) The binary search algorithm can be applied to an unsorted array.
A)True
B)False
Answer: False

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

Chapter 4: Data Abstraction: The Walls
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51579
Sample Questions
Q1) The definition of a subclass includes a(n)______ clause to indicate its superclass.
A)extends
B)super
C)this
D)implements
Q2) The head of a list does not have a successor.
A)True
B)False
Q3) Encapsulation combines an ADT's data with its operations to form a(n)______.
A)exception
B)method
C)object
D)variable
Q4) By default,all members in a class are public.
A)True
B)False
Q5) What is a constructor?
Q6) Give three examples of ADT operations that ask questions about the data in a collection.
To view all questions and flashcards with answers, click on the resource link above. Page 6

Chapter 5: Linked Lists
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51580
Sample Questions
Q1) What is the difference between a linear linked list and a circular linked list?
Q2) If a linked list is empty,the statement head.getNext()will throw a(n)______.
A)IllegalAccessException
B)ArithmeticException
C)IndexOutOfBoundsException
D)NullPointerException
Q3) A dummy head node ______.
A)facilitates adding nodes at the end the linked list
B)is used to store the first item in the linked list
C)is the second node in the linked list
D)is always present,even when the linked list is empty
Q4) Why is a loop necessary to find an arbitrary node in a linked list?
Q5) In Java,the programmer must explicitly deallocate memory.
A)True B)False
Q6) Each node in a linear linked list references both its predecessor and its successor. A)True B)False
Q7) What information is stored in a reference to an object?
Page 7
To view all questions and flashcards with answers, click on the resource link above.

Chapter 6: Problem Solving With Abstract Data Types
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51581
Sample Questions
Q1) A language is a set of strings of ______.
A)numbers
B)letters
C)alphabets
D)symbols
Q2) What is a postfix expression?
Q3) An empty string ______.
A)has a length of 0
B)has a length of 1
C)is not a valid string
D)has a negative value for its length
Q4) In the recursive solution to the Eight Queens problem,the problem size decreases by ______ at each recursive step.
A)one square
B)two squares
C)one column
D)two columns
Q5) What is an infix expression?
Q6) What is a prefix expression?
Q7) What is an empty string?
To view all questions and flashcards with answers, click on the resource link above. Page 8

Chapter 7: Stacks
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51582
Sample Questions
Q1) If a stack is used by an algorithm to check for balanced braces,which of the following is true once the end of the string is reached?
A)the stack is empty
B)the stack has one "{"
C)the stack has one "}"
D)the stack has one "{" and one "}"
Q2) Which of the following operations of the ADT stack does not throw a StackException?
A)push
B)pop
C)popAll
D)peek
Q3) If the array: 6,2,7,13,5,4
Is added to a stack,in the order given,which number will be the first number to be removed from the stack?
A)6
B)2
C)5
D)4
To view all questions and flashcards with answers, click on the resource link above.
9

Chapter 8: Queues
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51583
Sample Questions
Q1) What is an event-driven simulation?
Q2) In an implementation of a queue uses the ADT list,which of the following can be used to implement the operation enqueue(newItem)?
A)list.add(list.size(),newItem)
B)list.add(list.size()+1,newItem)
C)list.add(newItem.size(),newItem)
D)list.add(newItem.size()+1,newItem)
Q3) An event list for an event-driven simulation of a bank contains ______.
A)all arrival events
B)all arrival events that will occur but have not occurred yet
C)all departure events
D)all departure events that will occur but have not occurred yet
E)all arrival and departure events that will occur but have not occurred yet
Q4) Define the problem of rightward drift in an array-based implementation of a queue.
Q5) Operations on a queue can be carried out at ______.
A)its front only
B)its back only
C)both its front and back
D)any position in the queue
To view all questions and flashcards with answers, click on the resource link above. Page 10
Chapter 9: Advanced Java Topics
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51584
Sample Questions
Q1) What is meant by object type compatibility?
Q2) A(n)______ is a class that is used to provide access to another class that contains many objects.
A)interface
B)abstract class
C)package
D)iterator
Q3) In a class within a package,the keyword ______ must appear in front of the class keyword to make the class available to clients of the package.
A)open
B)public
C)protected
D)package
Q4) How can a package be created in Java?
Q5) Is it legal for a subclass of an abstract class not to implement all of the methods it inherits? Briefly explain.
Q6) Clients of a class can directly access the protected members of that class.
A)True
B)False

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

Chapter 10: Algorithm Efficiency and Sorting
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51585
Sample Questions
Q1) In the best case,a sequential search is ______.
A)O(n)
B)O(1)
C)O(log2 )
D)O(n²)
Q2) Suppose we wish to sort an array of 3-digit integers using radix sort.We will make three passes over the elements of the array.What occurs during the first pass?
Q3) The value of which of the following growth-rate functions grows the slowest?
A)O(n)
B)O(n²)
C)O(1)
D)O(log2 )
Q4) The analysis of an algorithm must take into consideration the computer that will be used to run a program that implements the algorithm.
A)True
B)False
Q5) What is determined by average-case analysis?
Q6) What does the area analysis of algorithms focus on?
Q7) Compare the efficiencies of the quicksort and the mergesort in the worst case.
Page 12
To view all questions and flashcards with answers, click on the resource link above.

Chapter 11: Trees
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51586
Sample Questions
Q1) In ______,the left and right subtrees of any node have heights that differ by at most 1.
A)all trees
B)all binary tress
C)n-ary trees
D)balanced binary trees
Q2) In a binary tree,what is the maximum number of siblings a node may have? What is the minimum?
Q3) Each node in a binary tree has ______.
A)exactly one child
B)at most one child
C)exactly two children
D)at most two children
Q4) What are the three methods that a class that implements the Iterator interface must provide?
Q5) What are the three properties of each node n in a binary search tree?
Q6) Briefly describe an algorithm for finding the largest key value in a binary search tree.
Q7) What is a search key?
Q8) What are the characteristics of a binary tree?
To view all questions and flashcards with answers, click on the resource link above. Page 13

Chapter 12: Tables and Priority Queues
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51587
Sample Questions
Q1) The ______ operation of the ADT table throws a TableException.
A)tableInsert
B)tableDelete
C)tableRetrieve
D)tableTraverse
Q2) A(n)______ implementation of a table is nonlinear.
A)list
B)linked list
C)binary search tree
D)array
Q3) What is a semiheap?
Q4) What is the effect of the assumption that all items in a table have distinct search keys,on the insertion operation of a table?
Q5) The sorted reference-based implementation of the tableInsert operation is ______.
A)O(1)
B)O(n)
C)O(n²)
D)O(log n)
Q6) What are the two main differences between a heap and a binary search tree?
Page 14
To view all questions and flashcards with answers, click on the resource link above.

Chapter 13: Advanced Implementations of Tables
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51588
Sample Questions
Q1) In designing a hash table,why do we want the size of the table to be significantly larger than the maximum number of entries that we will insert into it?
Q2) What is meant by clustering? How does clustering affect the overall efficiency of hashing?
Q3) A(n)______ is a balanced binary search tree.
A)2-3 tree
B)2-3-4 tree
C)red-black
D)AVL
Q4) A 2-3-4 tree is always balanced.
A)True
B)False
Q5) Searching a 2-3 tree is ______.
A)O(n)
B)O(log2 )
C)O(log2 * n)
D)O(n²)
Q6) In a 2-3 tree,how is the search key of a 2-node related to the search keys in the left subtree and the right subtree of the 2-node?
Page 15
To view all questions and flashcards with answers, click on the resource link above.

Chapter 14: Graphs
Available Study Resources on Quizplus for this Chatper
60 Verified Questions
60 Flashcards
Source URL: https://quizplus.com/quiz/51589
Sample Questions
Q1) Define a path between two vertices.
Q2) The sum of the weights of the edges of a path can be called all of the following EXCEPT ______.
A)length
B)weight
C)height
D)cost
Q3) Suppose we have a weighted graph with n vertices,and at least n edges.Explain is wrong with the following approach for finding the minimum spanning tree: while(the number of edges in the graph >= n) find the edge with the highest weight and delete it from the graph
Q4) A ______ can have duplicate edges between vertices.
A)spanning tree
B)connected graph
C)complete graph
D)multigraph
Q5) In a digraph,there can be only one edge between a pair of vertices. A)True
B)False
To view all questions and flashcards with answers, click on the resource link above. Page 16

Chapter 15: External Methods
Available Study Resources on Quizplus for this Chatper
30 Verified Questions
30 Flashcards
Source URL: https://quizplus.com/quiz/51590
Sample Questions
Q1) Which statement is true about B-trees?
A)Traversals of a table can be done in sorted order more efficiently than a hash table.
B)All nodes are children of the root.
C)The root node contains either the largest or smallest key value.
D)If there are n nodes in the B-tree,then the height of the tree is log2 n.
Q2) If a B-tree of order 5 contains the key values 20,40,50,60,80,90 and 100,and the root contains only the key value 60,then deleting the key 20 will require us to merge the two child nodes.
A)True
B)False
Q3) When deleting a key value from a B-tree,what happens if this results in its node becoming empty?
A)A new root node must be created.
B)A new child node must be created.
C)The empty node must merge with another node.
D)The empty node must split into two nodes.
Q4) What is the advantage of using a B-tree instead of a 2-3 tree for indexing external data?
Q5) Name two advantages to storing a data structure in external storage.
To view all questions and flashcards with answers, click on the resource link above. Page 17