Java Data Structures Exam Questions and Solutions, Exams of Nursing

A series of final exam questions related to java data structures, complete with their solutions. It covers fundamental concepts such as adts, linked lists, recursion, and object-oriented programming principles. The questions are designed to test understanding of theoretical concepts and practical application in java. It is useful for students preparing for exams or seeking to reinforce their knowledge of data structures and algorithms. Questions on topics such as encapsulation, inheritance, recursion, and the properties of different data structures like linked lists and arrays. It also covers aspects of software engineering, such as the software life cycle and error types. The questions are presented in a clear and concise manner, making it easy to follow and understand the solutions. This resource is valuable for students looking to test their knowledge and improve their understanding of java data structures.

Typology: Exams

2024/2025

Available from 07/29/2025

lilian-wachira
lilian-wachira 🇺🇸

5

(1)

7.3K documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Java Data Structures FINAL EXAM QUESTIONS WITH
COMPLETE SOLUTIONS | GRADED A
In Java, all arguments are passed to methods by value, except for
objects and arrays. - CORRECT ANSWER-True
Every Java class is a subclass of either another Java class or the
Object class. - CORRECT ANSWER-True
Java allows programmers to perform operations on reference values -
CORRECT ANSWER-False
In Java, multiple class inheritance is possible since a new subclass
can directly inherit the attributes (i.e. data and methods) of more than
one class, including the Object class. - CORRECT ANSWER-False
Files in Java can grow in size as needed, whereas arrays have a fixed
size. - CORRECT ANSWER-True
Which of the following is a precondition for a method that accepts a
number n and computes the nth Fibonacci number? - CORRECT ANSWER-n
is a positive integer
The instance of an object is called a class. - CORRECT ANSWER-False
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Java Data Structures Exam Questions and Solutions and more Exams Nursing in PDF only on Docsity!

Java Data Structures FINAL EXAM QUESTIONS WITH

COMPLETE SOLUTIONS | GRADED A

In Java, all arguments are passed to methods by value, except for objects and arrays. - CORRECT ANSWER- True Every Java class is a subclass of either another Java class or the Object class. - CORRECT ANSWER- True Java allows programmers to perform operations on reference values - CORRECT ANSWER- False In Java, multiple class inheritance is possible since a new subclass can directly inherit the attributes (i.e. data and methods) of more than one class, including the Object class. - CORRECT ANSWER- False Files in Java can grow in size as needed, whereas arrays have a fixed size. - CORRECT ANSWER- True Which of the following is a precondition for a method that accepts a number n and computes the nth Fibonacci number? - CORRECT ANSWER- n is a positive integer The instance of an object is called a class. - CORRECT ANSWER- False

______ can be used to enforce the walls of an ADT. - CORRECT ANSWER- Encapsulation Methods are usually defined as public. - CORRECT ANSWER- True A __________ allocates memory for an object and can initialize the object's data. - CORRECT ANSWER- Constructor Constructor - CORRECT ANSWER- Creates and initializes a new instance of a class Object - CORRECT ANSWER- Program or module that uses the Class Encapsulation - CORRECT ANSWER- Hides the implementation details of the ADT from the programmer who uses it. Subclass - CORRECT ANSWER- Inherits the contents of the superclass Procedural abstraction - CORRECT ANSWER- Separates the purpose and use of a module from its implementation ADT - CORRECT ANSWER- Abstract Data Type Data Structure - CORRECT ANSWER- a construct that is defined within a programming language to store a collection of data

In backtracking, you use recursion to explore all possible solutions until you find the best one - CORRECT ANSWER- True Language grammars are never defined recursively. - CORRECT ANSWER- False What is the value of the postfix expression: 6 7 + 8 2 - * - CORRECT ANSWER- 78 What is the value of the prefix expression: - * 3 8 + 6 5 - CORRECT ANSWER- 13 Which of the following is the postfix form of the prefix expression: * + a b c - CORRECT ANSWER- a b + c * When you solve a problem by solving two or more smaller problems, each of the smaller problems must be ______ the base case than the original problem. - CORRECT ANSWER- either farther from or the same "distance" from A recursive binary search algorithm always reduces the problem size by half at each recursive call. - CORRECT ANSWER- True

A recursive solution can have more than one base case. - CORRECT ANSWER- True Typically, a directly recursive method requires a while or for loop. - CORRECT ANSWER- True A recursive method always calls itself. - CORRECT ANSWER- False What is the effect of the following recursive Java method, assuming that N is a positive integer? public static int Mystery (int N) { if (N > 0) return 1 + Mystery(N / 10); else return 0; } - CORRECT ANSWER- It computes the number of decimal digits in N In the box trace for a recursive method, a new box (i.e. activation record) is created each time: - CORRECT ANSWER- the method is called Consider the following Java program. What is output by the program? public static void main( void )

else return 1; } - CORRECT ANSWER- 81 During the specification phase of the life cycle of software, the programmer should indicate what enhancements to the program are likely in the future. - CORRECT ANSWER- True Logical errors of a program are removed during the coding phase of the software life cycle. - CORRECT ANSWER- False According to the basic tenets of software engineering, more than 50% of the cost and time for software is perpetuated within the maintenance phase of the software life cycle. - CORRECT ANSWER- True Which of the following is NOT a part of the maintenance phase of the software life cycle? - CORRECT ANSWER- proving the correctness of algorithms The syntax errors of a program are removed during the ______ phase of the program's life cycle. - CORRECT ANSWER- Coding

Which of the following is an example of a syntax error? - CORRECT ANSWER- the beginning of a while loop is written as "whille" instead of "while". Check all of the following that are true of an array-based implementation of a linked list: - CORRECT ANSWER- Generally has a fixed size Check all of the following that are true of an array-based implementation of a linked list: - CORRECT ANSWER- Has a density factor of 1 A reference-based implementation of a linked list has a density factor of 1. - CORRECT ANSWER- False The last node in a linked list has a next reference set to ________. - CORRECT ANSWER- Null A reference variable contains the location of an object in memory. - CORRECT ANSWER- True When one reference variable is assigned to another reference variable, both references then refer to the same object. - CORRECT ANSWER- True Given the code snippet below, which reference variable would be marked for garbage collection:

Garbage - CORRECT ANSWER- an object whose access paths have all been destroyed It is possible for a dangling reference to exist in Java. - CORRECT ANSWER- False A linked list does not always have a head. - CORRECT ANSWER- False A linked list with a null head is full. - CORRECT ANSWER- False In a reference-based linked list, the data field next in the last node is set to null. - CORRECT ANSWER- True What best describes the purpose of this code snippet: for (Node curr = head; curr != null; curr = curr.getNext()) { // code goes in here } - CORRECT ANSWER- Traversing a linked list. When deleting a node from an ordered linked list, all cases involve at least a partial traversal of the list in order to find the location of the node to be deleted. - CORRECT ANSWER- True

A reference-based implementation of the ADT list does not shift items during insertion or deletion. - CORRECT ANSWER- True A reference based implementation of the ADT list does impose a fixed maximum list length. - CORRECT ANSWER- False Select all of the following which are TRUE of array-based implementations of ADT lists when compared to a reference-based implementation. - CORRECT ANSWER- Requires less memory Select all of the following which are TRUE of array-based implementations of ADT lists when compared to a reference-based implementation. - CORRECT ANSWER- Fixed size Select all of the following which are TRUE of array-based implementations of ADT lists when compared to a reference-based implementation. - CORRECT ANSWER- Potential for over allocation of space The storage density factor of a reference-based implementation of an ADT list is less than 1. - CORRECT ANSWER- True In an array-based implementation of an ADT list, the access time varies. - CORRECT ANSWER- False In a reference-based implementation of an ADT list: - CORRECT ANSWER- an item explicitly references the next item.