Skip to main content

Data Structures and Algorithms Test Bank - 981 Verified Questions

Page 1


Data Structures and Algorithms

Test Bank

Course Introduction

Data Structures and Algorithms is an essential course that explores fundamental concepts for organizing and manipulating data efficiently. The course covers a range of abstract data types such as arrays, linked lists, stacks, queues, trees, and graphs, alongside key algorithmic techniques like searching, sorting, recursion, and optimization. Students learn how these data structures and algorithms can be applied to solve complex computational problems, analyze their space and time complexities, and make informed choices in software development. Through theoretical concepts and practical programming exercises, the course builds a foundation vital for advanced studies in computer science and professional software engineering.

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) ____________ results in only the object's methods being able to directly access and make the changes to the object's data.

A) Component reusability

B) Classes

C) Data hiding

D) Procedures

Answer: C

Q2) The contents of a variable cannot be changed while the program is running.

A)True

B)False

Answer: False

Q3) A computer program is:

A) A set of instructions that enable the computer to solve a problem or perform a task.

B) Main memory

C) Pseudocode

D) A flow chart

Answer: A

To view all questions and flashcards with answers, click on the resource link above. Page 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) Which Scanner class method reads a String?

A) readString()

B) nextString()

C) getString()

D) nextLine()

Answer: D

Q2) If the compiler encounters a statement that uses a variable before the variable is declared,an error will result.

A)True

B)False

Answer: True

Q3) Which of the following is not a primitive data type?

A) short

B) long

C) float

D) String

Answer: D

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

Page 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) What would be the value of x after the following statements were executed? int x = 10; Switch (x)

{ Case 10: X += 15; Case 12: X -= 5; Break; Default: X *= 3; } A) 5

B) 20

C) 25

D) 30

Answer: B

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

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) What will be the value of x after the following code is executed? int x = 10; Do { X *= 20;

} While (x < 5);

A) 10

B) 200

C) This is an infinite loop.

D) The loop will not be executed,the initial value of x > 5.

Q2) This is an item that separates other items.

A) Controller

B) Partition

C) Doorway

D) Delimiter

Q3) If a loop does not contain within itself a way to terminate,it is called a(n)

A) while loop

B) do-while loop

C) for loop

D) infinite loop

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

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) Local variables

A) are hidden from other methods

B) may have the same name as local variables in other methods

C) lose the values stored in them between calls to the method in which the variable is declared

D) All of the above

Q2) Breaking a program down into small manageable methods

A) makes problems more easily solved

B) allows for code reuse

C) simplifies programs

D) all of the above

Q3) The lifetime of a method's local variable is

A) the duration of the program

B) the duration of the class to which the method belongs

C) the duration of the method that called the local variable's method

D) only while the method is executing

Q4) In the method header the static method modifier means the method is available to code outside the class.

A)True

B)False

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

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) Methods that operate on an object's fields are called

A) instance variables

B) instance methods

C) public methods

D) private methods

Q2) Class objects normally have __________ that perform useful operations on their data,but primitive variables do not.

A) fields

B) instances

C) methods

D) relationships

Q3) A method that gets a value from a class's field but does not change it is known as a mutator method.

A)True

B)False

Q4) An access specifier indicates how the class may be accessed.

A)True

B)False

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

Page 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) In Java,the ability to display splash screens was introduced in Java 6.

A)True

B)False

Q2) The System.exit method will end the application.

A)True

B)False

Q3) These types of components are coupled with their underlying peers.

A) Lightweight

B) Featherweight

C) Middleweight

D) Heavyweight

Q4) When you write an action listener class for a JButton component,it must

A) have a method named buttonClicked

B) implement the ActionLIstener interface

C) have a method named actionPerformed which must take an argument of the ActionEvent type

D) Both b and c

Q5) Check boxes may be grouped in a ButtonGroup like radio buttons are.

A)True

B)False

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

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) Any items typed on the command-line,separated by space,after the name of the class are considered to be one or more arguments that are to be passed into the main method.

A)True

B)False

Q2) What do you normally use with a partially-filled array?

A) A class that does nothing but manage the array

B) An accompanying parallel array

C) An accompanying integer value that holds the number of items stored in the array

D) An accumulator

Q3) For the following code,what would be the value of str[2]? String[] str = {"abc","def","ghi","jkl"};

A) "ghi"

B) "def"

C) A reference to the String "ghi"

D) A reference to the String "def"

Q4) Java does not limit the number of dimensions that an array may have.

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) If a class has a method named finalize,it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.

A)True

B)False

Q2) When the this variable is used to call a constructor,

A) it must be the first statement in the constructor making the call

B) it must be the last statement in the constructor making the call

C) it can be anywhere in the constructor making the call

D) You cannot use the this variable in a constructor call.

Q3) Which of the following is not true about static methods?

A) It is necessary for an instance of the class to be created to execute the method.

B) They are created by placing the key word static after the access specifier in the method header.

C) They are called directly from the class.

D) They are often used to create utility classes that perform operations on data,but have no need to collect and store data.

To view all questions and flashcards with answers, click on the resource link above. Page 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) The StringBuilder constructor used in the following statement will... StringBuilder str = new StringBuilder(25);

A) give the object,str,25 bytes of storage and store spaces in them

B) give the object,str,25 bytes of storage and not store anything in them

C) give the object,str,25 or more bytes of storage and store spaces in them

D) give the object,str,0 bytes of storage

Q2) StringBuilder objects are immutable.

A)True

B)False

Q3) When you are writing a program with String objects that may have unwanted spaces at the beginning or end of the strings,use this method to delete them.

A) replace

B) trim

C) valueOf

D) substring

Q4) The String class's valueOf()method accepts a string representation as an argument and returns its equivalent integer value.

A)True

B)False

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) Protected members are

A) not quite private

B) not quite public

C) Both A and B

D) Neither A or B

Q2) Look at the following code and determine what the call to super will do. public class ClassB extends ClassA { Public ClassB()

{ Super(10); } }

A) This cannot be determined form the code shown.

B) It will call the constructor of ClassA that receives an integer as an argument.

C) It will call the method named super and pass the value 10 to it as an argument.

D) The method super will have to be defined before we can say what will happen.

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) The catch clause

A) follows the try clause.

B) starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable.

C) contains code to gracefully handle the exception type listed in the parameter list.

D) All of the above.

Q2) The throw statement informs the compiler that a method throws one or more exception.

A)True

B)False

Q3) All of the exceptions that you will handle are instances of classes that extend this class.

A) RunTimeException

B) IOException

C) Error

D) Exception

Q4) The throws clause causes an exception to be thrown.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above. Page 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) If the combo box addressBox contains a list of strings,why is the returned value of getSelectedItem method in the following code cast to String? String selectedAddress; SelectedAddress = (String)addressBox.getSelectedItem();

A) This is not necessary.

B) Because the syntax of the method requires it.

C) It makes the program more readable

D) Because the return type of the method is an Object.

Q2) When you write a change listener class method for a slider,it must implement the ChangeListener interface which is in the javax.swing.event package.

A)True

B)False

Q3) Which of the following assigns ALT+C as a mnemonic key for the JButton object,clearButton?

A) clearButton.addMnemonic(KeyEvent.VK_C);

B) clearButton.setMnemonic(KeyEvent.C);

C) clearButton.setMnemonic(KeyEvent.VK_C);

D) clearButton.assignMnemonic(KeyEvent.VK_C);

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

Page 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) Applets are important because the can be used to

A) extend the capabilities of a web page.

B) process large data files.

C) run other programs on the user's system.

D) keep the doctor away.

Q3) Hypertext can contain

A) a Java application program

B) exception methods

C) executable code

D) a link to another Web page

Q4) Some browsers do not directly support the Swing classes of applets.

A)True

B)False

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

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) If Method A calls Method B which in turn calls Method A,it is called indirect recursion.

A)True

B)False

Q2) Like a loop,a recursive method must have

A) a counter.

B) some way to control the number of times it repeats itself.

C) a return statement.

D) a predetermined number of times it will execute before terminating.

Q3) Indirect recursion occurs when a method calls another method that in turn calls the first method.

A)True

B)False

Q4) 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

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) A basic step is

A) an operation that can be executed within a constant amount of time

B) an operation that is used only in the simplest algorithms

C) one that is implemented in a library package

D) None of the above

Q2) If an array is known to be sorted,it can be searched very quickly by using A) sequential search

B) binary search

C) selection search

D) None of the above

Q3) The addition of two integers

A) is always a basic step

B) is a basic step in algorithms that use addition to define more complex operations such as multiplication

C) is a basic step if there is a fixed bound on the size of the integers

D) All of the above

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

18

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) The declaration

Class Point< T extends Number >

{ }

Is an example of

A) a generic class extending the class Number

B) a generic class extending a non-generic class

C) a generic class extending another generic class

D) a non-generic class extending a generic class

Q2) A class is generic

A) if it is a subclass of the Object class

B) if it is a superclass of the Object class

C) if it has type parameters

D) if it has method parameters

Q3) The notation < E extends Comparable< E > >

A) will be rejected by the Compiler as an error

B) declares a generic type that implements the Comparable interface

C) is used when there is a recursive definition of the generic type E

D) None of the above

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

Page 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) An object that can compare two other objects and determine whether one is greater than,less than,or equal to the other is a

A) Comparator

B) Comparable

C) Sorter

D) Sequencer

Q2) A HashMap

A) is a subclass of Map that implements the HashCode interface

B) is a subclass of HashSet that implements the Map interface

C) uses hash codes to store keys

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

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

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) Assume an array-based list implemented by a class that uses the fields String [ ] list; int nElements; to represent the array of elements,and the number of elements currently stored.Show the code for a constructor that creates a list with a default capacity of 100.

Q2) 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

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 X with index 1 or greater from a linked list, A) set a reference pred to the predecessor of the node you want to remove,and set the successor of pred to the successor of X

B) decrease the index of the node to be removed by 1,and then set its reference to null C) first store the value of the element in X in a safe place,then set its reference to null D) None of the above

Q2) A doubly linked list makes it easy to

A) move from any node to its successor,and from any node to its predecessor

B) skip two nodes at a time when moving forward through the list

C) skip two nodes at a time when moving backward through the list

D) to create a second copy of the linked list

Q3) The objects that form the units of memory allocation in a linked lists are called

A) memory modules

B) elements

C) nodes

D) links

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) A stream of cars going through a toll booth is an example of a

A) priority queue

B) hash set

C) stack

D) 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. Page 23

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) A ternary tree is like a binary tree,except each node may have up to three successors.Write a TNode class that can be used to represent a ternary tree.Define a notion of preorder and postorder traversal for ternary trees,and write methods void postorder(TNode tree)and void preorder(TNode tree)that implements your notion of those traversals.

Q2) When a new item is added to an AVL tree

A) the tree may become unbalanced in only one way

B) the tree may become unbalanced two different ways,but the two imbalances are mirror images of each other

C) the tree may become unbalanced in four different ways,but because of mirror images,there are really only two fundamentally different imbalances

D) the height of one of the subtrees of the root may become three times the height of the other subtree

Q3) The predecessor of a node in a binary tree is called its A) progenitor

B) ancestor

C) parent

D) precursor

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

Turn static files into dynamic content formats.

Create a flipbook