Skip to main content

Data Structures and Algorithms (Java-based) Final Exam - 758 Verified Questions

Page 1


Data Structures and Algorithms (Java-based) Final Exam

Course Introduction

This course provides a comprehensive introduction to the fundamental data structures and algorithms used in computer science, with an emphasis on practical implementation using the Java programming language. Topics include arrays, linked lists, stacks, queues, trees, graphs, sorting, searching, recursion, and algorithmic analysis. Students will learn how to select and apply appropriate data structures to solve computational problems efficiently and gain experience in designing, coding, and debugging Java programs to manipulate these structures. The course prepares students to analyze algorithmic complexity and make informed decisions about the trade-offs between different approaches to data organization and manipulation.

Recommended Textbook

Absolute Java 5th Edition by Walter Savitch

Available Study Resources on Quizplus

20 Chapters

758 Verified Questions

758 Flashcards

Source URL: https://quizplus.com/study-set/3975 Page 2

Chapter 1: Getting Started

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

Source URL: https://quizplus.com/quiz/79864

Sample Questions

Q1) A variable of type boolean can be explicitly converted to that of type int.

A)True

B)False

Answer: False

Q2) The modulus operator,%,returns the remainder of integer division.

A)True

B)False

Answer: True

Q3) Explain the difference between an implicit type cast and an explicit type cast.

Answer: A type cast takes a value of one type and produces a value of another type.Java supports two kinds of type casts: explicit and implicit.Java performs an implicit type cast automatically.This can be seen in the declaration of a variable of type double that is assigned an integer value. double castExample = 72; The integer value assigned to the variable castExample is automatically converted to a floating point number.The number assigned to castExample is converted to 72.0. An explicit type cast occurs when the programmer explicitly forces a value of one type into a value of another type.In the example that follows,the value 72.5 is explicitly cast into an integer value. int castExample = (int)72.5;

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

3

Chapter 2: Console Input and Output

Available Study Resources on Quizplus for this Chatper

29 Verified Questions

29 Flashcards

Source URL: https://quizplus.com/quiz/79862

Sample Questions

Q1) Why is echoing user input a good programming practice?

Answer: Echoing input is a technique that is commonly used to allow the user to check their input for accuracy before it is actually sent to the program for processing.This technique reduces the chances of errors in the program.

Q2) What does the following code output?

DecimalFormat dfQuestion = new DecimalFormat("#0.##E0"); System.out.println(dfQuestion.format(12.7896987));

A)12.79E0

B)12.8E0

C)1.28E1

D).13E2

Answer: A

Q3) If there is no loss of efficiency in importing an entire Java package instead of importing only classes you use into your program,why would you not just import the entire package?

Answer: Importing only the classes you need into your program makes your program easier to read as well as aiding in documenting the program.Program readability is very important since humans read computer programs,too.

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

Chapter 3: Flow of Control

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

Source URL: https://quizplus.com/quiz/79861

Sample Questions

Q1) A mixture of programming language and human language is known as:

A)Algorithms

B)Recipes

C)Directions

D)Pseudocode

Answer: D

Q2) What would be the output of the code in #1 if number was originally initialized to 25?

Answer: The condition evaluated to false!

Q3) Discuss the rules Java follows when evaluating expressions.

Answer: First,Java binds operands with operators by fully parenthesizes the expression using precedence and associativity rules. Next,Java evaluates expressions from left to right. Finally,if an operator is waiting for other operands to be evaluated,then that operator is evaluated as soon as its operands have been evaluated.

Q4) Write Java code that uses a while loop to print even numbers from 2 through 10.

Answer: int evenNumber = 2; while(evenNumber <= 10) { System.out.println(evenNumber); evenNumber += 2; }

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

Chapter 4: Defining Classes I

Available Study Resources on Quizplus for this Chatper

44 Verified Questions

44 Flashcards

Source URL: https://quizplus.com/quiz/79860

Sample Questions

Q1) Boolean expressions may be used to control if-else or while statements.

A)True

B)False

Q2) A method that performs some action other than returning a value is called a __________ method.

A)null

B)void

C)public

D)private

Q3) The new operator:

A)allocates memory

B)is used to create an object of a class

C)associates an object with a variable that names it.

D)All of the above.

Q4) Write a method called power the computes x<sup>n</sup> where x and n and positive integers.The method has two integer parameters and returns a value of type long.

Q5) Write a method called isEqual that returns a Boolean value.The method compares two integers for equality.

Page 6

Q6) Discuss a situation in which it is appropriate to use the this parameter.

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

Chapter 5: Defining Classes Ii

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

Source URL: https://quizplus.com/quiz/79859

Sample Questions

Q1) Create a Java class named Book with instance variables title,author,ISBN,and yearPublished.Include javadoc style comments to describe your interface.Such a class would normally have methods,but you are not required to supply any methods.

Q2) A condition that allows a programmer to circumvent the private modifier and change the private instance variable is called:

A)a copy constructor

B)a privacy leak

C)a class invariant

D)an anonymous object

Q3) Does an object created with a copy constructor reference the same memory location that the original object references? Explain.

Q4) Add a constructor and a copy constructor to the Book class created in question #13.

Q5) null can be used:

A)to indicate a variable has no real value

B)in a Boolean expression with ==

C)as a placeholder

D)all of the above

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

7

Chapter 6: Arrays

Available Study Resources on Quizplus for this Chatper

47 Verified Questions

47 Flashcards

Source URL: https://quizplus.com/quiz/79858

Sample Questions

Q1) Write a Java method as well as any facilitator methods needed to perform a sort on an array of whole numbers in descending order.

Q2) A collection class is a class whose objects store a collection of values.

A)True B)False

Q3) A one dimensional array is also called an array of arrays. A)True B)False

Q4) Arrays are objects that are created with new just like class objects. A)True B)False

Q5) Write a Java statement that declares and creates an array of Strings named Breeds.Your array should be large enough to hold the names of 100 dog breeds.

Q6) Write a complete Java console application that prompts the user for a series of quiz scores.The user should type -1 to signify that the input of quiz scores is complete.Your program should then average the scores and display the result back to the user.

Q7) Initialize the array created in number 11 above to -1.0.

Q8) What are three ways you can use the square brackets [ ] with an array name?

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

Chapter 7: Inheritance

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

Source URL: https://quizplus.com/quiz/79857

Sample Questions

Q1) Write Java statements that compares Objects,O1 and O2,using the getClass()method.

Q2) When you define a derived class,you give only the added instance variables and the added methods as well as all the methods from the base class.

A)True

B)False

Q3) A base class is synonymous with a:

A)Child class

B)Parent class

C)Derived class

D)Sub class

Q4) The Object class contains the method:

A)getClass()

B)toString()

C)equals()

D)all of the above

Q5) Overriding is when a derived class redefines a method from the base class.

A)True

B)False

Q6) Explain what a call to super()does in a constructor of a derived class.

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

Chapter 8: Console Input and Output

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

Source URL: https://quizplus.com/quiz/79856

Sample Questions

Q1) Override the clone method inherited in the Tennis Shoes class created in number 11 above.

Q2) The method clone has one parameter and should return a copy of the calling object.

A)True

B)False

Q3) Java uses late binding with private methods,methods marked final,or static methods.

A)True

B)False

Q4) Assigning an object of an ancestor class to a descendent class is called:

A)static binding

B)dynamic binding

C)upcasting

D)downcasting

Q5) Polymorphism refers to the ability to associate many meanings to one method through dynamic binding.

A)True

B)False

Q6) Derive a class named Tennis Shoes from the base class created in number 9 above.

Page 10

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

Chapter 9: Exception Handling

Available Study Resources on Quizplus for this Chatper

45 Verified Questions

45 Flashcards

Source URL: https://quizplus.com/quiz/79855

Sample Questions

Q1) List five common examples of exceptions that occur.

Q2) Exceptions that must follow the Catch or Declare Rule are often called unchecked exceptions.

A)True

B)False

Q3) The execution of a throw statement is referred to as:

A)catching a block

B)trying a block

C)handling an exception

D)throwing an exception

Q4) A program can catch multiple exceptions.

A)True

B)False

Q5) The catch block has ________ parameters.

A)zero

B)one

C)two

D)three

Q6) Revise the program in number 9 above to throw a NegativeNumberException if the user enters a negative number.

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

Chapter 10: File IO

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

Source URL: https://quizplus.com/quiz/79874

Sample Questions

Q1) The class ObjectOutputStream contains all of the following methods except:

A)writeInt()

B)writeChar()

C)writeDouble()

D)println()

Q2) Files whose contents must be handled as sequences of binary digits are called:

A)text files

B)ASCII files

C)binary files

D)output files

Q3) The method __________ from the File class forces a physical write to the file of any data that is buffered.

A)close()

B)flush()

C)writeUTF()

D)writeObject()

Q4) Using BufferedReader to read integers from a file requires the String input to be parsed to an integer type.

A)True

B)False

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

Chapter 12: Uml and Patterns

Available Study Resources on Quizplus for this Chatper

22 Verified Questions

22 Flashcards

Source URL: https://quizplus.com/quiz/79872

Sample Questions

Q1) The second section of a UML class diagram specifies the:

A)class members

B)class name

C)class methods

D)class modifiers

Q2) The third section of a UML class diagram specifies the:

A)class members

B)class name

C)class methods

D)class modifiers

Q3) The first section of a UML class diagram specifies the:

A)class members

B)class name

C)class methods

D)class modifiers

Q4) Draw a UML class diagram for a class that represents a sphere.

Q5) Define pseudocode.

Q6) A container is a class whose objects hold multiple pieces of data.

A)True

B)False

Page 13

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

Chapter 13: Interfaces and Inner Classes

Available Study Resources on Quizplus for this Chatper

32 Verified Questions

32 Flashcards

Source URL: https://quizplus.com/quiz/79871

Sample Questions

Q1) A class that uses an interface must use the keyword:

A)Extends

B)Inherits

C)Super

D)Implements

Q2) A Java interface is an example of:

A)encapsulation

B)abstraction

C)polymorphism

D)all of the above

Q3) If an inner class contains non static members,then the class name must be modified by the keyword:

A)Final

B)Static

C)Void

D)Protected

Q4) The compiler and the run-time system enforces semantics on the Comparable interface.

A)True

B)False

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

Chapter 14: Generics and the Arraylist Class

Available Study Resources on Quizplus for this Chatper

31 Verified Questions

31 Flashcards

Source URL: https://quizplus.com/quiz/79870

Sample Questions

Q1) When using ArrayLists the method _______ can be used to save memory:

A)trimToSize()

B)trimDown()

C)trimOff()

D)None of the above

Q2) Write Java statements to display the size of the resulting ArrayList from question 5 above.

Q3) You can not use the set method to put an element at just any index.

A)True

B)False

Q4) A class definition can have more than one type parameter.

A)True

B)False

Q5) The keyword ___________ can be used to place a bound on a type parameter.

A)Implements

B)Inherits

C)Encapsulates

D)Extends

Q6) What is the base type of the ArrayList defined in question number 2?

Q7) Write a Java statement to create an ArrayList to hold 25 integers.

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

Chapter 15: Linked Data Structures

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

Source URL: https://quizplus.com/quiz/79869

Sample Questions

Q1) What is the result of a preorder traversal of the binary search tree created in question 12 above?

Q2) What is the binary search tree storage rule?

Q3) A copy constructor and a clone method should normally make a deep copy whenever possible.

A)True

B)False

Q4) To use the Java Iterator Interface you must import the ____________ package.

A)java.tools

B)java.linkedlist

C)java.iterator

D)java.util

Q5) Redraw the diagram created in number 4 above after deleting the head node.

Q6) When using a linked list,you do not need to know when the end of the list has been reached.

A)True

B)False

Q7) A stack cannot be represented as a linked list.

A)True

B)False

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

Chapter 16: Collections and Iterators

Available Study Resources on Quizplus for this Chatper

44 Verified Questions

44 Flashcards

Source URL: https://quizplus.com/quiz/79868

Sample Questions

Q1) For-each loops can not be used with Collection classes.

A)True

B)False

Q2) The V parameter in a HashMap&lt;K,V&gt; may be any object,but the K parameter must be a String.

A)True

B)False

Q3) The List interface is for collections that allow repetition of elements and do not impose an order on their elements.

A)True

B)False

Q4) The method contains(Object o)of the ArrayList class returns a value of type:

A)int

B)char

C)byte

D)boolean

Q5) How can one retrieve all the values of a HashMap object?

Q6) &lt;T&gt; is a wildcard used to specify a wide range of parameters.

A)True

B)False

Page 17

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

Chapter 17: Swing I

Available Study Resources on Quizplus for this Chatper

37 Verified Questions

37 Flashcards

Source URL: https://quizplus.com/quiz/79867

Sample Questions

Q1) Composition indicates a/an _______________ relationship.

A)Is-a

B)Has-a

C)both A & B

D)none of the above

Q2) What is an action listener? What is an action event?

Q3) GUIs are windowing interfaces that handle user input and output.

A)True

B)False

Q4) The JFrame method setVisible()takes one argument of type:

A)byte

B)boolean

C)int

D)short

Q5) One of the main functions of JPanel objects is to subdivide a JFrame (or other container)into different areas.

A)True

B)False

Q6) Write Java statements to add menu items named "Circle","Square",and "Rectangle" to the menu created in number 7 above.

Page 18

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

Chapter 18: Swing II

Available Study Resources on Quizplus for this Chatper

31 Verified Questions

31 Flashcards

Source URL: https://quizplus.com/quiz/79866

Sample Questions

Q1) An imaginary _____________ is used for drawing all shapes on the screen.

A)bounding box

B)view port

C)container

D)none of the above

Q2) When using scroll bars,the text is viewed through a ______________ that shows only part of the text at a time.

A)view port

B)text area

C)all of the above

D)none of the above

Q3) The paint method of the Graphics class can only be used with Applets.

A)True

B)False

Q4) Write a Java statement that draws a filled oval at position (150,100)with a height of 100 and a width of 50.

Q5) Write Java statements to add the icon created in number 1 above to a label that says "Love".

Q6) Set policies for the scroll bar created in number 3 above.

Q7) Write a Java statement to create an image icon for the image heart.gif.

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

Chapter 19: Java Never Ends

Available Study Resources on Quizplus for this Chatper

18 Verified Questions

18 Flashcards

Source URL: https://quizplus.com/quiz/79865

Sample Questions

Q1) The Java language does not support multithreading.

A)True

B)False

Q2) ____________ means that an object has an identity that extends beyond one session.

A)Event handling

B)Introspection

C)Persistence

D)None of the above

Q3) An InterruptedException is a checked exception.

A)True

B)False

Q4) What is a JavaBean?

Q5) An alternative to deriving a thread from the Thread class is to inherit the Runnable interface.

A)True

B)False

Q6) What other programming technique can be combined with sockets so a server can handle requests from multiple clients?

Q7) What are Enterprise JavaBeans?

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

Chapter 11: Recursion

Available Study Resources on Quizplus for this Chatper

43 Verified Questions

43 Flashcards

Source URL: https://quizplus.com/quiz/79873

Sample Questions

Q1) When defining recursive valued methods you should:

A)Ensure there is no infinite recursion.

B)Ensure each stopping case returns the correct value for that case.

C)Ensure that the final value returned by the method is the correct value.

D)All of the above

Q2) Regarding recursion,if a base case is never reached the result is:

A)infinite recursion

B)iteration

C)termination

D)all of the above

Q3) What is the value returned when the integer 5 is the argument to the factorial method?

A)15

B)50

C)100

D)120

Q4) Binary search is a divide and conquer algorithm.

A)True

B)False

Q5) Explain the concept of divide and conquer.

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

Chapter 20: Applets

Available Study Resources on Quizplus for this Chatper

25 Verified Questions

25 Flashcards

Source URL: https://quizplus.com/quiz/79863

Sample Questions

Q1) Images can be embedded within HTML pages.

A)True

B)False

Q2) The HTML tag used to insert a horizontal line on a page is:

A)< h1 >

B)< href >

C)< hr >

D)< br >

Q3) An applet is embedded within an HTML document by adding a reference to a valid class file within the &lt;applet&gt;&lt;/applet&gt; tag.

A)True

B)False

Q4) Applets do not support JMenus.

A)True

B)False

Q5) URL stands for:

A)Unified Resource Locator

B)Uniform Reader Locator

C)Uniform Resource Locator

D)Uniform Resource Language

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

Turn static files into dynamic content formats.

Create a flipbook