CS 2114 Combo

Ace your homework & exams now with Quizwiz!

You should express the complexity of an algorithm in terms of it

problem size

At the time a method is called during program execution, the activation record is pushed onto the

program stack

When you remove an item from a stack, you remove it from

the top

The selection sort requires _____ comparisons for an array of n items

O(n^2)

What is the scope error in the mystery method? public static void main(String[] args) { int target = 4; target = mystery(target + 1); System.out.println(sum); } public static int mystery(int target) { int sum = 0; for (int i = 0; i < target; target++) { int target = i + 1; sum = sum + target; } return sum; }

there are two local variables named target that overlap

If iteration has ended, the next method

throws a NoSuchElementException

An algorithm has

time requirements and space requirements

the operator == tests to see if

two variables reference the same place in the computer's memory

What is the worst-case time complexity for searching a linked-based bag ADT for a particular entry?

O(n)

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

"cheetah"

For large values of n which statement is true?

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

In the Ch 6 an array-based implementation of a Stack ADT, what value for the topindex of the stack indicates that it is empty?

-1

How many recursive calls will be made if the following method is called with 6 from main? void greeting(int n) { if (n > 0) { System.out.println("Hello!"); greeting(n-1); } }

6

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

????

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

?????

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

?????

Given an array of doubles named values, what does the following code do: double total = 0; for(double element : values) { total = total + element; } double average = 0; if (values.length > 0) { average = total/values.length; }

Calculates the sum and average of the values

Java sorting implementations sort objects that implement the _____ interface.

Comparable

What question should you keep in mind when debugging a recursive method?

Does each base case produce a result that is correct for that case? Are there enough base cases? Is at least one of the cases a base case that has no recursive call?

Given an array of ints named values, what does the following code do: for (int i = 0; i < values.length; i++) { values[i] = i * i; }

Fills the array with squares (0, 1, 4, 9, 16, ...)

Given an array of ints named values, what does this code do? double largest = values[0]; for (int i = 1; i < values.length; i++) { if (values[i] > largest) { largest = values[i]; } }

Find the max value

What is usually an advantage of using a chain to implement the ADT bag?

It avoids moving data when adding or removing bag entries.

The use of a generic data type is preferred over using Object as a general class in a collection because

It ensures that all the members of the collection are objects related by inheritance.

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 when the dequeue operation?

O(1)

In a linked chain implementation of a queue, the performance of the enqueue operation is

O(1)

In a linked-based implementation of the ADT list with a tail reference, what is the performance of adding an entry at the end of the list?

O(1)

In the Ch 6 linked-chain implementation of a Stack ADT, the performance of popping an entry from the stack is

O(1)

What is the time complexity for adding an entry to a fixed-size array-based bag ADT?

O(1)

What is the time complexity for adding an entry to a linked-based bag ADT?

O(1)

The efficiency for recursively traversing a chain of linked nodes is

O(n)

Bridget

REEEE

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

Rudy

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

Rudy

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

Sam

What will be ouput as a result of a call to the calculate method? private int sum = 0; private int product = 0; public static final int AMOUNT = 5; public void output(){ System.out.println("The sum of the numbers from 1 to " + AMOUNT + " is " + sum); System.out.println("The product of the numbers from 1 to " + AMOUNT + " is " + product); } public void calculate(){ int sum = 0; int product = 1; for (int i = 1; i <= AMOUNT; i++){ sum = sum + i; product = product * i; } output(); }

The sum of the numbers from 1 to 5 is 0 The product of the numbers from 1 to 5 is 0

When adding an item to a bag, which of the following statements are true?

You cannot specify the position of the item in the bag.

A class uses composition when it

declares an instance of another class as a data field

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 + /

what does a reference type represent?

a memory address instead of the actual item stored at that address

What does the"new" operator do in the following code from the LinkedBag add method: Node newNode = new Node(newEntry);

a new node is created the JRE allocates memory for a node object a new object is instantiated

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

decremented

In a chain of linked nodes you can

add nodes from the beginning of a chain add nodes from the end of a chain add nodes that are between other nodes

Which behavior(s) change the contents of a bag?

add()

Which of the following is usually an advantage of using an array to implement the ADT bag?

adding an entry to a bag is fast

In the Carrano ListInterface, the method with the signature: public void add(int newPosition, T newEntry); does which of the following

adds a new entry to the specified position in the list increases the list size by 1 moves entries originally at or above the specified position one position higher

implementation

all the data fields and details of the methods definitions

A key benefit of inheritance is

an object can have several types, it is type compatible with any of its superclasses

a variable declared as an interface type can reference

any object of a class that implements that interface

Where does a queue add new items?

at the back

You can add a new entry in a list

at the beginning at the end in between items

Where will you find the item added earliest to a queue?

at the front

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

balanced expression

Recursive methods need a(n)

base case

A superclass is also called a(n)

base class

A subclass is also called a(n)

derived class

encapsulation

design principle that encloses data and methods within a class, thereby hiding the class' implementation details

this();

calls the constructor of the current class that takes no arguments

super();

calls the constructor of the parent class that takes no arguments

Which method removes all entries of a bag?

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 = currentNode.getNextNode();

When adding an entry to an array-based implementation of the ADT list at a specified location before the end of the list

entries must be shifted to vacate a position for the new item

To efficiently remove a node at the end of a linked chain implementation of a queue requires a

extra reference in the node pointing to the previous node

What type of behavior defines a queue?

first-in first-out

abstraction

focus on what and not how

Which method returns a count of the current number of items in a bag?

getCurrentSize()

A fixed size array

has a limited capacity can waste memory prevents expansion when the bag becomes full

composition

has-a-relationship

Which method does the interface Iterator specify?

hasNext next remove

A reference to the first node in a linked list is called the _____ reference.

head

Shane

hep

How many recursive calls will be made if the following method is called with 6 from main? void greeting(int n) { if (n > 0) { System.out.println("Hello!"); greeting(n+1); } }

infinite

How many recursive calls will be made if the following method is called with 6 from main? void greeting(int n) { System.out.println("Hello!"); greeting(n-1); }

infinite

Placing the Node class inside the LinkedBag class makes it a(n)

inner class

inheritance

is-a-relationship

Which of the following are good reasons to write tests that use your bag ADT before the implementation is done?

it helps confirm the design it helps check the suitability of the specification it helps check your understanding of the specification

In an array-based implementation of the ADT list, the makeRoom method does the most work when

newPosition is 1

In the Carrano 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 inital capacity

In the Carrano ListInterface, the method with the signature: public T remove(int givenPosition); does which of the following:

removes the entry at a given position from the list

The fixed array implementation of the method remove that has no parameter in the bag

removes the last entry in the array

Which behavior is not represented in a bag?

reorder the bag

The most efficient approach to dealing with a gap left in an array after removing an entry from a bag is to

replace the entry being removed with the last entry in the array and replace the last entry with null

In your reading, the pop and peek methods throw a(n) ________ exception when the stack is empty.

runtime

Selecting the smallest element of an array and swapping it with the smallest entry is an operation in which sorting method?

selection sort

What does a primitive type represent?

simple indecomposable values

When too many recursive calls are made creating more activation records than the allocated program memory can handle, what kind of error occurs?

stack overflow

An incomplete definition of a method is called a _____.

stub

What is the scope error in the main method? public static void main(String[] args) { int target = 4; sum = mystery(target + 1); System.out.println(sum); } public static int mystery(int target) { int sum = 0; for (int i = 0; i < target; i++) { int target = i + 1; sum = sum + target; } return sum; }

sum is not declared

Because SortedList is derived from LList, you write _____.add(newPosition, newEntry) to invoke the add operation of the ADT list

super

The node that is easiest to access in a linked-chain is

the head node

In the Ch 6 array-based implementation of a Stack ADT, the entry peek returns may be found at

the last occupied location in the array

when one method has the same name but a different set of parameters than a second method

the method are overloaded

Problem size is defined as

the number of items an algorithms processes

In the Ch 6 linked-chain implementation of a Stack ADT, when a node is popped from the stack

the original first node will no longer be referenced the original first node will be deallocated the new first node will reference what was the second node in the chain

In the linked chain implementation of a queue, the chain's first node contains

the queue's front entry

What are the consequences of returning a reference to the bag array in the toArray method?

the return variable is an alias for the private instance array variable the client will have direct access to the private instance array variable the client could change the contents of the private instance array variable without using the public access methods

If the SortedList class inherited the remove by position method from the LList class

we would not have to implement it again

client interface

what client code needs to know to use a class

Why would the add method return false?

when the addition of a new item was not successful


Related study sets

(Exam 1) Validity and Reliability

View Set

Ch. 18 Kidney Clinical and Diagnostic Procedures

View Set

fundamentals of nursing Course Point Quiz- CH. 19

View Set

PSYC 100- LearningCurve 14a- Introduction to Personality and Psychodynamic Theories, Humanistic and Trait Theories

View Set

PATIENT MANAGEMENT: " Very Important File "

View Set