Data Structures and Algorithms Final Test Solutions - 981 Verified Questions

Page 1


Data Structures and Algorithms

Final Test Solutions

Course Introduction

This course introduces the fundamental concepts of data structures and algorithms, which are essential for efficient problem-solving in computer science. Students will learn about various data organization techniques such as arrays, linked lists, stacks, queues, trees, and graphs, as well as algorithmic strategies including recursion, searching, sorting, and dynamic programming. Emphasis is placed on analyzing algorithm performance and selecting appropriate data structures to solve computational problems. By the end of the course, students will have developed the skills necessary to design, implement, and evaluate algorithms for a wide range of applications.

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

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) Application software refers to programs that make the computer useful to the user.

A)True

B)False

Answer: True

Q2) Key words are:

A) The data names in your program

B) Words that have a special meaning in the programming language

C) Symbols or words that perform operations on one or more operands

D) Words or names defined by the programmer

Answer: B

Q3) Which of the following will compile a program called ReadIt?

A) java ReadIt.java

B) java ReadIt.javac

C) javac ReadIt.java

D) javac ReadIt.javac

Answer: C

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) The ___________ is normally considered the standard output and standard input devices,and usually refer to the monitor and keyboard.

A) CRT

B) CPU

C) secondary storage devices

D) console

Answer: D

Q2) What will be displayed after the following statements have been executed? final double x;

X = 54.3; System.out.println("x = " + x );

A) x = 54.3

B) x

C) x = 108.6

D) Nothing,this is an error.

Answer: D

Q3) In Java the variable named one is the same as the variable named One.

A)True

B)False

Answer: False

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) Enclosing a group of statements inside a set of braces creates a

A) block of statements

B) boolean expression

C) loop

D) Nothing,it is just for readability

Answer: A

Q2) In an if/else statement,if the boolean expression is false,

A) the first statement or block is executed

B) the statement or block following the else is executed

C) all statements or blocks are executed

D) no statements or blocks are executed

Answer: B

Q3) Which of the following expressions will determine whether x is less than or equal to y?

A) x > y

B) x =< y

C) x < = y

D) x >= y

Answer: C

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 file must always be opened before using it and closed when the program is finished using it.

A)True

B)False

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

Q3) What will be the value of x after the following code is executed? int x = 10; While (x < 100);

{ X += 10; }

A) 90

B) 100

C) 110

D) This is an infinite loop

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

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) Methods are commonly used to

A) speed up the compilation of a program

B) break a problem down into small manageable pieces

C) emphasize certain parts of the logic

D) document the program

Q2) When an argument is passed to a method,

A) its value is copied into the method's parameter variable

B) its value may be changed within the called method

C) values may not be passed to methods

D) the method must not assign another value to the parameter that receives the argument

Q3) No statement outside the method in which a parameter variable is declared can access the parameter by its name.

A)True

B)False

Q4) All @param tags in a method's documentation comment must

A) end with a */

B) appear after the general description of the method

C) appear before the method header

D) span several lines

Page 7

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) Instance methods do not have the key word static in their headers.

A)True

B)False

Q2) A constructor is a method that

A) returns an object of the class. B) never receives any arguments.

C) with the name ClassName.constructor. D) performs initialization or setup operations.

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

Q4) Instance methods should be declared static.

A)True

B)False

Q5) The java.lang package is automatically imported into all Java programs. 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) This layout manager arranges components in five regions.

A) GridLayout

B) BorderLayout

C) FlowLayout

D) RegionLayout

Q2) In a Swing application,you create a frame object from the

A) Jlabel class

B) JFrame class

C) Jpanel class

D) AbstractButton class

Q3) To use the Color class,which is used to set the foreground and background of various objects,use the following import statement

A) import java.swing;

B) import java.awt;

C) import java.awt.*;

D) import java.awt.event.*;

Q4) The FlowLayout manager does not allow the programmer to align components.

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) Which of the following is a correct method header for receiving a two-dimensional array as an argument?

A) public static void passArray(int[2])

B) public static void passArray(int [][])

C) public static void passArray(int[1][2])

D) public static void passArray(int[],int[])

Q2) Given that String[] str has been initialized,to get a copy of str[0] with all characters converted to upper case,use the following statement:

A) str.uppercase();

B) str[0].upperCase();

C) str.toUpperCase();

D) str[0].toUpperCase();

Q3) If numbers is a two-dimensional array,which of the following would give the length of row r?

A) numbers.length

B) numbers.length[r]

C) numbers[r].length[r]

D) numbers[r].length

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

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 declaration for an enumerated type begins with this key word.

A) enumerated

B) enum_type

C) enum

D) ENUM

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

A) a compiler error will result,if it is not the first statement of the constructor.

B) a compiler error will result,if it is the first statement of the constructor.

C) nothing will happen.

D) The this variable cannot be used as a constructor call.

Q3) Look at the following declaration. enum Tree { OAK,MAPLE,PINE }

What is the fully-qualified name of the PINE enum constant?

A) PINE

B) enum.PINE

C) Tree.PINE

D) enum.PINE.

E) PINE.Tree

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) What will be printed after the following code is executed? String str = "abc456";

Int m = 0; While ( m < 6 )

{ If (Character.isLetter(str.charAt(m))) System.out.print( Character.toUpperCase(str.charAt(m))); M++; }

A) abc456

B) ABC456

C) ABC

D) 456

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

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) In the following code,what will the call to super do? public class ClassB extends ClassA

{ Public ClassB()

{ Super(40); System.out.println("This is the last statement "+ "in the constructor."); } }

A) This cannot be determined form the code.

B) It will call the method super and pass the value 40 to it as an argument.

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

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

Q2) Every class has a toString method and an equals method inherited from the Object class.

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) To serialize an object and write it to the file,use this method of the ObjectOutputStream class.

A) SerializeObject

B) WriteObject

C) Serialize

D) SerializeAndWrite

Q2) A class must implement the Serializable interface in order for objects of the class to be serialized.

A)True

B)False

Q3) If,within one try statement you want to have catch clauses that catch exceptions of the following types,in which order should they appear in your program? (1)Throwable (2)Exception

(3)RuntimeException

(4)NumberFormatException

A) 4,3,2,1

B) 2,3,1,4

C) 4,1,3,2

D) 3,1,2,4

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) A menu system may consist of each of the following except A) menu item

B) separator bar

C) menu bar

D) It may have all the above.

Q2) What will display when the following code is executed? imagePanel = new JPanel(); ImageLabel = new JLabel(); ImagePanel.Add(imageLabel);

ImageIcon sunnyFaceImage = New ImageIcon("SunnyFace.gif"); ImageLabel.setIcon(sunnyFaceImage); Pack();

A) The JFrame that encloses the window will resize itself to accommodate the SunnyFace image.

B) imagePanel will resize itself to accommodate the SunnyFace image.

C) The SunnyFace image will resize itself to fit on imageLabel.

D) The SunnyFace image will resize itself to fit on imagePanel.

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) When you extend an interface,you must implement all the methods defined in the interface.If you are interested in only one or two mouse events,you can extend the _______ class which implements the MouseListener interface,but does not require you to write all the functions in the interface.

A) MouseAdapter

B) MouseExtender

C) MouseMotionAdapter

D) MouseMotionExtender

Q2) The browser creates an instance of the applet class automatically.

A)True

B)False

Q3) Which tag will produce largest text?

A) < h4 >Hello< /h4 >

B) < h3 >Hello< /h3 >

C) < h2 >Hello< /h2 >

D) < h1 >Hello< /h1 >

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) The actions that the JVM must perform any time a method is called is called

A) stack frame.

B) overhead.

C) housekeeping.

D) method calls.

Q2) To solve a program recursively,you need to identify at least one case in which the problem can be solved without recursion - this is known as

A) the recursive case.

B) the terminal case.

C) the base case.

D) the final case.

Q3) Any problem that can be solved recursively can also be solved iteratively.

A)True

B)False

Q4) 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) A contiguous segment of an array is specified using two subscripts,lower and upper.Which expression gives the position of the element in the middle of the array segment?

A) lower + upper / 2

B) lower /2 + upper

C) (upper - lower./2

D) lower + (upper - lower./ 2

Q2) An array of 4 elements is being sorted in ascending order using the insertion sort algorithm.How many comparisons will insertion sort perform if the array was originally sorted in descending order?

A) 2 comparisons

B) 4 comparisons

C) 6 comparisons

D) None of the above

Q3) The binary search algorithm

A) cannot be used to search an array that is not sorted

B) does twice as much work as sequential search on the average case

C) must be written using recursion

D) is slower than sequential search when the item being searched for is not in the array

To view all questions and flashcards with answers, click on the resource link above. Page 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 automatic conversion of a wrapper type to the corresponding primitive type when the wrapper type is assigned to a variable of the primitive type is called

A) autoboxing

B) unboxing

C) type casting

D) autoconversion

Q2) The process used by the Java compiler to remove generic notation and substitute actual type arguments for formal type parameters is called

A) erasure

B) removal

C) substitution

D) masking

Q3) Which of the following statements is true?

A) The CompareTo method is implemented by the String class

B) The CompareTo method is implemented by all the subclasses of the Number class

C) The Comparable interface is defined in the Java class libraries

D) All 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) The concrete classes of the JCF that implement the Set interface

A) all extend the AbstractMap class

B) should be assigned the value null when they are empty collections

C) are optimized for fast searching of elements in a collection

D) None of the above

Q3) An index

A) is a list of keys that allows fast look up of values in a map

B) is an object that indicates which one of a group of collections contains a given value

C) is the position of an element within a list

D) is used with generic collections to quickly find stored values

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) The E get(int index)method of the List interface should throw an exception if A) the index passed to it is negative

B) the index passed to it nonnegative

C) the index passed to it is negative or greater or equal to the size of the list

D) the index passed to is negative or greater than the size of the list

Q2) The int indexOf(Object o)method of the List interface

A) searches a list for the occurrence of an object and returns its index

B) adds an object to a list and returns the index of the newly added object

C) uses binary search to locate the given object,and then returns its index

D) None of the above

Q3) The position of an item within a list is called its

A) index

B) rank

C) level

D) number

Q4) What is the difference between the Iterator and Iterable interfaces? How would you use these two interfaces if you had to write a collection class?

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

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 allocate storage for its elements,an array-based list such as ArrayList uses

A) linked allocation

B) contiguous allocation

C) capacity allocation

D) fixed size allocation

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

A) memory modules

B) elements

C) nodes

D) links

Q3) A recursive computation of the size of a list can work as follows:

A) set a local counter to zero;loop through the list,incrementing the counter by one at each element of the list;return the counter

B) recursively compute the size of the tail,add one,and return the result

C) if the list is not empty,recursively compute the size of its tail,add one,and return the result

D) if the list is empty,return zero;otherwise,recursively compute the size of the tail,add one,and return the result

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

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) Compilers of modern programming languages support method calls and returns with an internal

A) priority queue

B) hash set

C) stack

D) queue

Q2) A queue is a container that allows elements to be stored and removed

A) in a last-in-first-out fashion

B) in a first-in-first-out fashion

C) in a first-in-last-out fashion

D) quickly and efficiently

Q3) The stack pop operation

A) removes all items currently on the stack

B) extracts one element from the stack and returns it

C) removes from the stack the number of elements specified by its integer parameter

D) does not exist: There is no such stack operation

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

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) An empty binary tree has height

A) -1

B) 0

C) 1

D) None of the above: the height of an empty binary tree is not defined.

Q2) The depth of a binary tree

A) is the length of the longest path from the root to a leaf

B) is the length of the shortest path from the root to a leaf

C) is the total number of leaves in the tree

D) is the depth of one of the subtrees plus one

Q3) Binary trees have been used

A) in compilers and interpreters to represent expressions

B) in computer hardware to model branching patterns of electronic signals

C) in the Java Collections Framework to internally implement the Vector class

D) None of the above

Q4) A binary tree with no root

A) must have only one node

B) must have exactly two nodes

C) must be empty

D) None of the above

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
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.