COSC 2436 Exam 1 Final Exam review

¡Supera tus tareas y exámenes ahora con Quizwiz!

A class that defines an inner class iterator should implement the

Iterator interface

If an algorithm requires 7 basic operations for an algorithm with a problem size of n, the algorithmic complexity is

O(1)

In a circular array-based implementation of a queue, what is the performance of the dequeue operation?

O(1)

In a circular array-based implementation of a queue, what is the performance of the enqueue operation if you amortize the cost of resizing the array over all additions to the queue?

O(1)

In a circular array-based implementation of a queue, what is the performance when the enqueue operation does not resize the array?

O(1)

In an array-based implementation of the ADT (abstract data type) list, what is the best case performance of the ensureCapacity method?

O(1)

In an array-based implementation of the ADT (abstract data type) list, what is the best case performance of the makeRoom method?

O(1)

In an array-based implementation of the ADT (abstract data type) list, what is the best-case performance of the replace method?

O(1)

In an array-based implementation of the ADT (abstract data type) list, what is the worst case performance of the replace method?

O(1)

The efficiency for recursively calculating xn is

O(log n)

In a circular array-based implementation of a queue, what is the performance when the enqueue operation must resize the array?

O(n)

In an array-based implementation of the ADT (abstract data type) list, what is the worst case performance of the ensureCapacity method?

O(n)

In an array-based implementation of the ADT (abstract data type) list, what is the worst case performance of the makeRoom method?

O(n)

In an array-based implementation of the ADT (abstract data type) list, what is the worst case performance of the remove method?

O(n)

The best-case performance for an array of n items using insertion sort is

O(n)

The efficiency for recursively traversing a chain of linked nodes is

O(n)

In the SeparateIterator class, when the data field wasNextCalled is false it means

a subsequent call to remove requires another call to next

A separate class iterator is a good choice when

an ADT's implementation does not have an iterator and cannot be altered

In the linked implementation of a list, the add method public void add(T newEntry)inserts a new entry

at the end of the list

An expression that has correctly paired delimiters is called a(n)

balanced expression

In the linked implementation of a list, the add method public void add(int newPosition, T newEntry)inserts a new entry

between adjacent nodes of the list

A deque ADT (abstract data type) behaves both a & b none of the above like a stack like a queue

both a & b

In the IteratorForLinkedList class, what happens when the next method is called but iteration has ended?

It throws a NoSuchElementException.

To determine the efficiency of a recursive method you need to solve a(n)

recurrence relation

In a vector implementation of a Stack ADT (abstract data type), you remove an entry from the top of a stack using which vector method?

remove

The _____ deletes the most recent entry returned from the next method from the list.

remove

In the interface ListInterface, the method public void remove(int givenPosition); describes which of the following behaviors?

remove the entry at a given position from the list

Provide the missing line of pseudocode: isIdentifier(s: string): boolean { if (s is of length 1) // Base case { if (s is a letter) return true else return false } else if (the last character of s is a letter or a digit) //Provide this line of code else return false }

return isIdentifier(s minus its last character)

In an array-based implementation of the ADT (abstract data type) list, the contains method locates the entry by

searching for the entry starting at the beginning of the array working to the end

If myList is a declared ADT (abstract data type) list and the front of the list is on the left, what does the method getEntry(3) return after applying the following pseudo code? add("horse") myList.add("goat") myList.add(1, "fish") myList.replace(3, "sheep") myList.add("cat") myList.remove(1) myList.add(2, "dog")

sheep

A reference to the last node in a linked implementation of a list is commonly called the

tail

When the last action in a recursive method is a recursive call, it is called

tail recursion

In the SeparateIterator class, when the data field wasNextCalled is true it means

that a call to remove is safe

The most significant contributor to an algorithm's time requirement is

the algorithm's basic operation

When search an array for a particular value, which case is most useful?

the average case

When a vector needs to increase its size

the capacity is doubled

The best-case scenario for a insertion sort is

the elements are already in sorted order

The best-case scenario for a selection sort is

there is no best-case scenario

What does the Java Class Library implementation of the interface list do when an index is out of range?

throw an exception

When a counter enumerates simulated time units, it is called a(n)

time-driven simulation

In a circular array-based implementation of a queue implementation where one unused location is used to differentiate between the front and back of the queue, the frontIndex is _____ than the backIndex.

two more

A recursive method that processes a chain of linked nodes

uses the first node in the chain

What object behaves like a high-level array?

vector

Separate class iterators access the list's data fields

via ADT operations

Given the following infix expression, which one of the following is the corresponding postfix expression? w + x * y / z

w x y * z / +

The O(n2) analysis of insertion sort is a(n) _______ analysis

worst-case

In order to modify the front entry of a queue

you need a set method defined

After the following statements execute, what item is at the front of the queue? QueueInterface<String> zooDelivery = new LinkedQueue<>(); zooDelivery .enqueue("lion"); zooDelivery .enqueue("tiger"); zooDelivery .enqueue("cheetah"); String next = zooDelivery .dequeue(); next = zooDelivery .dequeue(); zooDelivery .enqueue("jaguar");

"cheetah"

After the following statements execute, what item is at the back of the queue? QueueInterface<String> zooDelivery = new LinkedQueue<>(); zooDelivery .enqueue("lion"); zooDelivery .enqueue("tiger"); zooDelivery .enqueue("cheetah"); String next = zooDelivery .dequeue(); next = zooDelivery .dequeue(); zooDelivery .enqueue("jaguar");

"jaguar"

For large values of n which statement is true?

(n^2 + n) / 2 behaves like n^2

In the Java Class Library, the default constructor Vector creates an empty vector with an initial capacity of

10

The public ArrayList() constructor in the Java Class Library ArrayList creates an empty list with an initial capacity of

10

Using the evaluate Postfix algorithm, evaluate the following postfix expression. w x + y* z /Assume that w = 3 , x = 4, y = 2, z = 7.

2

Using the evaluate Postfix algorithm, evaluate the following postfix expression. 7 2 + 4 *

36

Given the initial array of 9 elements what is the left partition at the beginning of insertion sort? 42 96 13 19 86 33 7 60 51

42

Using the evaluate Postfix algorithm, evaluate the following postfix expression. a b + c d - *Assume that a = 5, b = 7, c = 6, and d = 2.

48

Given the following array elements, what does the array look like after one iteration of insertion sort, arranging items in ascending order? 14 5 7 19 23 4 12 21

5 14 7 19 23 4 12 21

Given the following array elements, what does the array look like after two iterations of selection sort, arranging items in ascending order? 92 42 73 19 86 33 7 60

7 19 73 42 86 33 92 60

What is the output of the following program when the method is called with 4? void unknown(int n) { .out.print("?"); if (n > 0) unknown(n-1); }

?????

What is the efficiency of the iterative selection sort method for a chain of n linked nodes?

O(n^2)

What is the efficiency of the iterative selection sort method for an array of n items?

O(n^2)

What item is at the front of the list after these statements are executed? DequeInterface<String> waitingLine = new LinkedDeque<>();waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getFront();

Rudy

Given the following infix expression, which one of the following is the corresponding postfix expression?(a + b) * (c - d) / (e + f)

a b + c d - * e f + /

Given the following infix expression, which one of the following is the corresponding postfix expression? a + r ^ 2 - 5

a r 2 ^ + 5 -

In a vector implementation of a Stack ADT (abstract data type), you add an entry to the top of a stack using which vector method?

add

Including a tail reference to a linked implementation of a list makes which functionality more efficient?

adding a node to the end of a list

A common alias for the queue method dequeue is

all of the above

For large values of n which statement is true? 2n^3 + 4n^2 behaves like n^3 2n^3 + 4n^2 + 17n behaves like n^3 all of the above 2n^3 behaves like n^3

all of the above

The dequeue method

all of the above

To properly evaluate the effectiveness of an algorithm, you need to determine

all of the above

Which of the following operations could be identified as the basic operation of an algorithm?

all of the above

Which one of the following would not be a basic operation?

all of the above

If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(4) return after applying the following pseudo code? add("horse") myList.add("goat") myList.add(1, "fish") myList.add("cat") myList.remove(1) myList.add(2, "dog")

cat

To determine if a list is empty you can

check to see if the length of the list is zero

In a(n) ______ the last node references the first node.

circular linked chain

In a vector implementation of a Stack ADT (abstract data type), you clear all of the contents of a stack using which vector method?

clear

In the LList implementation of a list, given a node called currentNode, which statement moves the node's reference to the next node?

currentNode.getNextNode();

After a call to remove, the nextPosition data field should be

decremented

Inner class iterators can access the list's data fields

directly if there is no naming conflict

The rate of growth for the Towers of Hanoi problem as the number of disks increases is

exponential

If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(3) return after applying the following pseudo code? add("horse") myList.add("goat") myList.add(3, "fish") myList.add(1, "dog") myList.add("cat")

fish

In an array-based implementation of the ADT (abstract data type) list, the getEntry method locates the entry by

going directly to the appropriate array element

In the LList implementation of a list, the constructor and the clear method

have the same functionality

If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(3) return after applying the following pseudo code? add("horse") myList.add("goat") myList.add(1, "fish") myList.add("cat") myList.add(2, "dog") myList.remove(4)

horse

Computing the sum of the first n integers using the formula n * (n + 1) / 2 has a growth rate

independent of n

When method X calls method Y, method Y calls method Z, and method Z calls method X, this is called

indirect recursion

Traversing a chain of linked nodes

is easier to do recursively than iteratively

In a vector implementation of a Stack ADT (abstract data type), you check for an empty stack using which vector method?

isEmpty

In the linked implementation of a list, what happens when you try to add a node at an invalid position?

it throws an IndexOutOfBoundsException

In a vector implementation of a Stack ADT (abstract data type), you retrieve the top entry without removing it using which vector method?

lastElement

Which method accesses the last entry of a vector?

lastElement

In an array-based implementation of a queue, a possible solution to dealing with the full condition is to

leave one array location unused

A linked chain whose last node is null is sometimes called a(n)

linear linked chain

When method X calls method Y, and method Y calls method X, this is called

mutual recursion

In an array-based implementation of the ADT (abstract data type) list, the makeRoom method does the most work when

newPosition is 1

In the LList implementation of a list, when a list is empty the firstNode is _____ and the numberOfEntries is _____.

null, 0

In a circular array-based implementation of a queue, the initial size of the array should be

one more than the queue's initial capacity

A common alias for the queue method getFront is

peek

Reverse polish notation is another term for a(n)

postfix expression

Polish notation is another term for a(n)

prefix expression


Conjuntos de estudio relacionados

Chapter 19: Secured Transactions and Bankruptcy

View Set

Ethical Social & Legal Issues - Final Exam Comprehensive [INFO 323]

View Set

Fundamentals Mobility/Safety EAQ

View Set

ECPI 2020 NUR164 CHAPTER 4 HEALTH OF THE INDIVIDUAL, FAMILY AND COMMUNITY

View Set

intro to psych chapters 6,7, & 10

View Set

Diving First Aid for Professional Divers (Chapter Review Questions)

View Set

ATI Dosage Calculations Critical Care Medications

View Set

Ch. 4, 5, 6 Exam -- Theatre Appreciation -- Murphy

View Set