CSC 205 Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following statements best describes this line of code? numbers[5] = 12; a. a new array called numbers is instantiated with 5 indexes and the 5th index is set to 12. b. The value 12 is put into the numbers array at the location with index 5. c. The compiler throws an error d. 12 is assigned to the first 5 indexes of the numbers array.

The value 12 is put into the numbers array at the location with index 5.

A linked list can hold ______ nodes

any number of

A _______________ search is more efficient than a linear search. a. insertion b. binary c. selection d. bubble

b. binary

Which of the following methods removes an element from a queue? a. enqueue b. dequeue c. first d. pop e. push

b. dequeue

Which of the following is a method in the java.util.List interface? a. addBefore b. addAfter c. add d. resize e. shift

c. add

A tree in which every node can have at most n children is referred to as a __________________ tree. a. binary b. general c. n-ary d. graph e. ternary

c. n-ary

In a binary search, _______________________________ . a. it is assumed that the search pool is small. b. it is assumed that all of the elements are integers. c. it is assumed that all of the elements are Strings. d. it is assumed that the search pool is ordered.

d. it is assumed that the search pool is ordered.

Big-O notation establishes a(n) ____________ on a growth function

upper bound

An algorithm has liner time complexity and can process an input of size n in a certain amount of time. If algorithm runs on a computer that has a processor that is 5 times as fast, how large of an input can be processed in the same amount of time

5n

Which method below is not part of the Iterator interface? a. add b. next c. remove d. hasNext e. all of these are methods in the Iterator interface.

a. add

When writing a class for an array-based implementation of a list, the class that defines an iterator for the list should be a. an inner class b. iterable c. an interface e. public

a. an inner class

The ___________________ algorithm sorts values by repeatedly comparing neighboring elements in the list and swapping their position if they are not in order relative to each other. a. bubble sort b. selection sort c. merge sort d. quick sort e. insertion sort

a. bubble sort

In Java, type compatibility is enforced by _____________. a. compile-time type checking b. convention c. an Enforcer object d. an exception e. Java does not enforce type compatibility

a. compile-time type checking

As with queues and stacks, the first step in removing an element from a list collection is to a. determine that the collection is not empty. b. determine if the element is in the collection. c. determine if the element is in the first or the last position in the collection. d. determine if the collection will be empty once the element is removed. e. none of these is a reasonable first step in removing an element from a collection.

a. determine that the collection is not empty.

Suppose we have an array of String objects identified by the variable names. Which of the following for loops will not correctly process each element in the array. a. for(int i = 0; i < names.length; i++) b. for(String name : names) c. for(int i = 0; i < names.length(); i++) d. none of these will correctly process each element e. all of these will correctly process each element

a. for(int i = 0; i < names.length; i++)

In a array-based implementation of a queue that stores the front of the queue at index 0 in the array, the dequeue operation a. has order O(n) b. has several special cases c. has order O(n^2) d. is impossible to implement e. none of the above

a. has order O(n)

As the number of items in a search pool grows, the number of comparisons required to search _______________ . a. increases b. decreases c. stays the same d. goes to 0 e. none of the above

a. increases

In Java, polymorphic references can be created through the use of __________________ and ________________. a. inheritance, interfaces b. inheritance, abstract classes c. interfaces, abstract classes d. interfaces, iterators e. none of the above

a. inheritance, interfaces

Which of the following is a valid declaration for a two-dimensional array? a. int[][] matrix; b. int[2] matrix; c. int[]** matrix; d. int[] matrix; e. none of these are correct

a. int[][] matrix;

Which of the following is not a way to categorize list collections? a. public b. ordered c. unordered d. indexed e. all of the above are ways to categorize list collections

a. public

The ___________________ is the number of possible values of the digits or characters in a sort key. a. radix b. asymptote c. thread d. order e. none of the above

a. radix

Creating a separate node class that holds a reference to another node and a reference to an object that is being stored in a list is a good design because it a. makes the code more complicated b. hides the implementation details of a collection c. reduces code reuse d. all of the above e. neither a, b nor c

b. hides the implementation details of a collection

The __________________ algorithm sorts a list of values by repetitively inserting a particular value into a subset of the list that has already been sorted. a. quick sort b. insertion sort c. merge sort d. selection sort e. bubble sort

b. insertion sort

The pointer to the first element in a linked list a. is optional b. can be modified in any way necessary c. should only be modified by the code that adds nodes to the list and deletes nodes from the list d. can be used to traverse the list e. is inefficient

c. should only be modified by the code that adds nodes to the list and deletes nodes from the list

Which of the following statements is generally true about a linked list implementation of a queue? a. The linked list implementation of a queue maintains references to both ends, the front and the rear, of the linked list. b. Elements are added and removed at the rear of the linked list. c. The first operation retrieves the element that was most recently added to the linked list. d. Elements are added (enqueue) and removed (dequeue) at the front of the linked list. e. All of the above statements are generally true about a linked list implementation of a queue.

The linked list implementation of a queue maintains references to both ends, the front and the rear, of the linked list.

A full binary tree of height n has _________________ leaves. a) 2^n b) 3n c) 2n d) 2(n+1) e) 3(n+1)

a) 2^n

A stack is a ___________________ data structure. a. LIFO b. FIFO c. link based d. array based e. none of the above

a. LIFO

In an ideal implementation of a stack, all operations are ______________________ . a. O(1) b. O(n) c. O(n log n) d. O(n2) e. it depends on the operation

a. O(1)

In an ideal implementations of a queue, all operations are ______________________ . a. O(1) b. O(n) c. O(n log n) d. O(n2) e. it depends on the operation

a. O(1)

Suppose we have algorithms that solve a particular problem that have the following complexities. Which one is most efficient? a. O(1) b. O(log2n) c. O(n2) d. O(n3) e. O(2n)

a. O(1)

The peek operation of a stack, in Big O notation, is a. O(1) b. O(n) c. O(n^2) d. O(n log n) e. none of the above

a. O(1)

The Exception class and the Error class are subclasses of the ___________________ class. a. Throwable b. Catchable c. RuntimeProblem d. CompilerProblem e. none of the above

a. Throwable

In a queue implemented using a circular array, rear refers to a. the first available array element at the end of the queue b.the number of elements remaining to be used at the end of the array c. the number of elements available at the beginning of the array d. the element at the end of the queue e. none of the above

a. the first available array element at the end of the queue

The constructor for a stack implemented using a linked list creates space for how many elements? a. 10 b. 0 c. 1000 d. 100 e. however many the programmer specified when the linked list was instantiated.

b. 0

The List interface is implemented by the ________ class. a. array b. ArrayList c. String d. Object e. Exception

b. ArrayList

The addAfter operation of an unordered list collection is a. O(1) b. O(log n) c. O(n) d. O(n log n) e. a higher order than O(n log n)

b. O(log n)

_____________________ is the process of finding a designated target element within a group of items. a. Sorting b. Searching c. Recursing d. Helping e. none of the above

b. Searching

____________________ is the process of arranging a group of items into a defined order. a. Searching b. Sorting c. Selecting d. Helping e. none of the above

b. Sorting

Which of the following stack operations is not likely to cause an exception to be thrown? a. adding an item to the stack when the stack is full b. adding an item that has the same value as one that is already in the stack c. removing an item when the stack is empty d. all of a), b), and c) e. All of these are likely to cause an exception to be thrown

b. adding an item that has the same value as one that is already in the stack

A(n) ______ is an object that gathers and organizes other objects. a. abstraction b. collection c. exception d. algorithm e. none of the above

b. collection

Which of the following should be performed first in a dequeue operation? a. declare and initialize reference to the node to be removed from the queue b. determine if the queue is empty c. decrement the count of the number of elements in the queue d. adjust the reference to the front of the queue

b. determine if the queue is empty

A stack is the ideal collection to use when _______________________ a. implementing a radix sort b. evaluating a postfix expression c. modeling customers standing in line at the checkout of a grocery store d. finding the largest number in an array e. none of the above

b. evaluating a postfix expression

A self-referential object is an object that a. is its own child class b. has a pointer to another object of the same type c. is its own parent class d. has a pointer to itself e. none of these is correct

b. has a pointer to another object of the same type

Java provides the Queue _____ to create programs that use the queue data structure. a. class b. interface c. parent d. child

b. interface

Let Object 'a' be larger than Object 'b'. What will the following method call return? a.compareTo(b); a. it will return 0 b. it will return a number greater than 0 c. it will return a number less than 0 d. it will return true e. it will return false

b. it will return a number greater than 0

Which of the following method declarations correctly defines a method with a variable length parameter list? a. public int average(int[] list) b. public int average(int ... list) c. public int average(...) d. public int average(int a, int b, int c, ...) e. public int average(integers)

b. public int average(int ... list)

Which data structures are used by a radix sort? a. stacks b. queues c. heaps d. both a) and b) are correct e. a), b), and c) are all correct

b. queues

The find method, as used in the array-based implementation of the remove and contains operations, returns a. the element that was found b. the index of the element that was found c. a true or false value indicating whether the element was found d. the element whose reference variable points to the element that was found e. none of the above

b. the index of the element that was found

The push operation of a stack implemented using a linked list is O(1) when a. the top of the stack is at the end of the linked list b. the top of the stack is at the front of the linked list c. the stack is full d. the stack is empty e. none of the above

b. the top of the stack is at the front of the linked list

Which of the following tree traversals traverses the subtrees from left to right and then visits the root? a) Preorder b) Inorder c) Postorder d) Level-order e) none of the above

c) Postorder

A circular array has 20 elements. The index (array subscript) ranges from 0 to 19. What is the subscript of the array element that follows the element with subscript 19? a. 20 b. 1 c. 0 d. 21 e. an exception will be thrown

c. 0

The List ADT (Abstract Data Type) provides how many operations to remove an element from a list? a. 1 b. 2 c. 3 d. 4

c. 3 remove(), removeAt(), & replace()

________ can be used to sort the same set of objects in multiple ways a. selection sort b. random sort c. Comparator objects d. bubble sort e. insertion sort

c. Comparator objects

____________ is the process of catching an exception in the chain of method calls from the method where the exception occurred up to the main method. a. Error handling b. Exception handling c. Exception propagation d. Catch block nesting e. Finally block nesting

c. Exception propagation

A queue is a ____________________ data structure. a. LIFO b. array based c. FIFO d. link based e. none of the above

c. FIFO

__________________ recursion results from the lack of a base case. a. Spiral b. Indirect c. Infinite d. Direct e. none of the above

c. Infinite

The _______________________ puzzle is a favorite of computer scientists because of its elegant recursive solution. a. Tic-Tac-Toe b. Tetris c. Tower of Hanoi d. Sudoku

c. Tower of Hanoi

Recursion occurs when a. a program never ends b. a program terminates abnormally c. a method calls itself d. a program ends normally e. none of the above

c. a method calls itself

All recursive programs ____________________________________ . a. are more difficult to read than iterative programs. b. are easier to read than iterative programs. c. can be implemented iteratively. d. are shorter than iterative programs. e. none of the above are true.

c. can be implemented iteratively.

____________________ recursion occurs when a method calls itself, while _________________ recursion when a method calls another method that then calls the original method. a. downward, upward b. indirect, direct c. direct, indirect d. upward, downward e. none of the above

c. direct, indirect

The Serializable interface allows a. compiler warning messages to be suppressed. b. Object class elements to be added to list collections. c. objects to be read from and written to external files. d. Exceptions to be thrown from methods. e. none of the above

c. objects to be read from and written to external files.

A(n) _____________________ is a list collection has elements whose elements can be referenced using a numeric index. a. array b. indexed list c. ordered list d. unordered list e. linked list

c. ordered list

Which of the following methods inserts an element into a stack data structure? a. enqueue b. dequeue c. push d. pop e. peek

c. push

Java provides two Collections classes that can be used to implement stacks. They are ______ and _____. a. one-dimensional arrays, multidimensional arrays b. Exceptions, Errors c. the Stack class, the LinkedList class d. data structures, list structures e. none of the above

c. the Stack class, the LinkedList class

The remove operation returns a. an int representing the number of elements remaining in the list after the removal. b. a boolean value indicating if the remove was successful or not. c. the element that was removed. d. a pointer to the list e. The remove operation does not return any of these.

c. the element that was removed.

A user defines a class to implement an iterator for a user-defined collection. When an iterator object is created, it needs to know a. when it was created b. the datatype of the elements in the collection c. the number of elements in the collection d. why it was created

c. the number of elements in the collection

Traversing a linked list is a. the process of removing every node, one at a time b. the process of deleting the list c. the process of visiting every node for some purpose d. the process of creating a new linked list with twice the capacity e. none of the above

c. the process of visiting every node for some purpose

One reason to define a Queue ADT (abstract data type) interface is a. to tightly couple the data in the queue elements with the implementation of the queue data structure b. to guide the programmer in how to implement the queue operations c. to separate the operations from the ways that the operations can be implemented d. both b) and c) are correct

c. to separate the operations from the ways that the operations can be implemented

Which of the following best describes a balanced tree? a) A balanced tree has all nodes at exactly the same level. b) A balanced tree has no nodes at exactly the same level. c) A balanced tree has half of the nodes at one level and half the nodes at another level. d) A balanced tree has all of the nodes within one level of each other. e) None of the above correctly describe a balanced tree.

d) A balanced tree has all of the nodes within one level of each other.

What exception is thrown if the pop method is called on an empty stack, implemented using the ArrayStack class? a. EmptyStackException b. NoSuchElementException c. ArrayOutOfBoundsException d. EmptyCollectionException e. none of the above

d. EmptyCollectionException

Which of the following statements is true? a. Solutions that are easily expressed recursively should be programmed iteratively. b. Recursion should be used in every program. c. Recursion should be avoided all the time. d. Solutions that are easily expressed recursively should be programmed recursively.

d. Solutions that are easily expressed recursively should be programmed recursively.

Which of the following will result from infinite recursion in Java? a. The program will not compile. b. The program will throw an ArrayOutOfBoundsException. c. The program will hang as though there is an infinite loop. d. The program will run out of memory. e. none of the above.

d. The program will run out of memory.

A Stack interface is defined and has an isEmpty() abstract method. What should this method return? a. an int representing the number of items in the stack b. a double representing the average of the values of the items in the stack c. a String representing the contents of the items in the stack. d. a boolean value representing whether the stack is empty or not.the item that is at the top of the stack

d. a boolean value representing whether the stack is empty or not.the item that is at the top of the stack

An activation record represents a. which students are currently logged in to a campus computer b. a method that terminates due to an exception c. which students are enrolled and actively pursuing a degree d. a method that was called and has not yet completed its execution e. both a) and b)

d. a method that was called and has not yet completed its execution

Which of the following situations could be implemented using a Stack? a. cars waiting to pay and exit a parking garage b. people who have appointments in the reception area of a doctors office c. students passing through the serving line in a cafeteria d. a person who wants to undo several changes that were made to the document that she is editing. e. none of the above

d. a person who wants to undo several changes that were made to the document that she is editing.

In order to compare objects of a class in different ways, a. the class must implement the Comparable interface b. the class must implement the Comparator interface c. the class must inherit from the Comparator class d. a separate class must be created that implements the Comparator interface and provides a body for the compare method e. None of these is correct.

d. a separate class must be created that implements the Comparator interface and provides a body for the compare method

A double-ended queue allows a. adding elements at one end and removing them from both ends b. adding elements at both ends and removing them from one end c. adding elements at one end, removing them from the other end, and viewing (first) elements at either end. d. adding, removing, and viewing elements at either end. e. none of the above

d. adding, removing, and viewing elements at either end.

Which of the following array declarations are invalid? a. int[ ] grades = new int[5]; b. int grades[ ] = new int[5]; c. int[ ] grades = { 91, 83, 42, 100, 77 }; d. all of the above are valid e. none of the above are valid

d. all of the above are valid

A list collection can be implemented using either a. a stack or a queue b. an Exception or an Error c. add or remove operations d. an array or a linked structure e. both c) and d) are correct

d. an array or a linked structure

An iterator is a. an element in a collection. b. an interface c. a loop control variable d. an object that allows access to each element in a collection individually.

d. an object that allows access to each element in a collection individually

Which of the following statements will assign the first command-line argument sent into a Java program to a variable called argument? a. argument = System.getFirstArgument(); b. argument = System.getArgument[1]; c. argument = System.getArgument[0]; d. argument = args[0]; e. argument = args[1];

d. argument = args[0];

The Comparable interface contains which of the following methods? a. isGreaterThan b. isLessThan c. equals d. compareTo e. all of the above

d. compareTo

Which of the following is not an operation on a stack? a. push b. pop c. peek d. dequeue e. all of the above are operations on a stack

d. dequeue

In Java, a(n) ___________________ is a collection of constants and abstract methods. a. polymorphic reference b. abstract class c. implementation d. interface e. iterator

d. interface

Which of the following algorithms has a worst case complexity of O(n log2n)? a. insertion sort b. selection sort c. bubble sort d. merge sort e. none of the above

d. merge sort

A(n) ____________________ is another way to refer to an object reference variable. a. primitive variable b. instantiated object c. referer d. pointer e. stack collection

d. pointer

A(n) ________________ is an ordered sequence of bytes. a. exception b. error c. input-output flow d. stream e. none of the above

d. stream

Which of the statements is true about the following code snippet? int[] array = new int[25]; array[25] = 2; a. The integer value 2 will be assigned to the last index in the array. b. The integer value 25 will be assigned to the second index in the array. c. The integer value 25 will be assigned to the third value in the array. d. This code will result in a compile-time error. e. This code will result in a run-time error.

e. This code will result in a run-time error. Compile-time errors generally correspond to syntax or semantics. Runtime errors refer to errors encountered during the execution of code at runtime.

Which of the following is not a queue operation? a. isEmpty b. enqueue c. first d. dequeue e. all of the above are queue operations

e. all of the above are queue operations

Which of the following is not a sorting algorithm? a. Quick sort b. Merge sort c. Bubble sort d. Selection sort e. all of the above are sorting algorithms

e. all of the above are sorting algorithms

Java uses ________ to allow us to define a class and not specify the type of the objects that the class employs until the class is instantiated. a. exceptions b. widgets c. inheritance d. interfaces e. generic types

e. generic types

Which operation below is not part of the List interface? a. add an element to the list b. remove an element from the list c. replace an element in the list with another element d. get the size of the list e. grow the size of the list

e. grow the size of the list

A __________________ search looks through the search pool one element at a time. a. binary b. insertion c. selection d. clever e. linear

e. linear

A(n) _____________________ is a data structure that uses object reference variables to create links between objects. a. array-based data structure for a stack b. exception structure c. interface d. stack e. link structure

e. link structure

What is the limit of the number of variable parameters that can be passed to a method that has a variable-length parameter list? a. 5 b. 10 c. 16 d. less than 100 e. none of the above

e. none of the above

The queue operation that returns the element after the element at the front of the queue (that is, the second element in the queue) without removing the element at the front of the queue, is ________. a. dequeueNext b. dequeue c. bypass d. dequeueAndPeek e. none of these is correct

e. none of these is correct

A(n) _____________________ is a list collection has elements that are ordered by a characteristic of the elements. a. unordered list b. linked list c. indexed list d. array e. ordered list

e. ordered list

The first operation of a queue is similar to the ______ operation of a stack a. push b. pop c. isEmpty d. size e. peek

e. peek

What does this array contain? String[ ] studentNames = new String[25]; a. names b. students c. studentNames d. Strings e. references to Strings

e. references to Strings

The process of inheritance should establish a(n) ___________________ relationship. a. is-a b. has-a c. static d. not-a e. none of the above

is-a


Set pelajaran terkait

Chapter 2: types of life insurance policies

View Set

AB: Ch. 10 Gastrotestinal tract and Abdominal wall

View Set

PSYCH 1101- Chapter 11 Test Personality

View Set

Principles of Marketing Chapter 7

View Set

Rocks and the Rock Cycle Final Exam

View Set

Chapter 15 - Interest Rates and Monetary Policy

View Set

7a. Basic Learning Concepts and Classical Conditioning; Operant Conditioning

View Set

Topic 6A Identify Features of Linux

View Set

APUSH: Final Exam Research Review

View Set

Chapter 14 (Classes of mutation, explain all of them, know how tautomerization alters base pairing, know repair systems.)

View Set

Chapter 5 Thinking Critically to Analyze Data and Make Informed Nursing Judgments

View Set