CS2114 Final Exam

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

If an algorithm requires 7 basic operations for an algorithm with a problem size of n, the algorithmic complexity 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 linked-based bag ADT?

O(1)

What is the worst-case performance of the add method in a full binary search tree with linked nodes?

O(log n)

A complete traversal of an n-node binary tree is a(n) _____ operation if visiting a node is O(1) for the recursive implementation.

O(n)

For an array implementation of a list, the efficiency of remove(index) is:

O(n)

The efficiency for recursively traversing a chain of linked nodes is

O(n)

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

O(n)

a key benefit of inheritance is

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

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

You can add a new entry in a list

at the beginning, at the end, and in between items

recursive methods need a

base case

Advantage(s) of an inner iterator class over a separate iterator class:

It has direct access to the ADT's data so it can execute more efficiently

If you plan for a future subclass to be allowed to manipulate a class's data fields, provide _____ methods to enable the subclass to do this safely and efficiently.

protected

An iterative version of a level order traversal for a binary tree uses a(n)

queue

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

What does a primitive type represent

simple indecomposable values

An iterative version of a preorder traversal for a binary tree uses a(n)

stack

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

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

The inorder predecessor of a node N is

the largest entry in N's left subtree

For an array implementation of a stack, the efficient choice for the top is

the last element in the array.

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 methods 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

The inorder successor of a node N is the smallest entry in N's right subtree

the smallest entry in N's right subtree

The largest entry in a node N's right subtree is

the subtree's rightmost node

an algorithm has

time requirements and space requirements

why do we use inheritance

to have a general class with common properties and behaviors by multiple specialized classes

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? (bags)

when the addition of a new item was not successful

When you declare a method to be protected and final, who can access it?

a subclass

implementation

all the data fields and details of method defintions

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

problem size

you should express the complexity of an algorithm in terms of its

problem size

for large values of n, what is true?

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

Encapsulation

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

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

Does the 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?

To implement a Deque(double ended queue) with a firstNode and a lastNode reference, which of the following underlying representations would result in a more efficient implementation?

Double linked chain

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.

Of the two sorting algorithms we studied in lecture, which would do less work, in terms of comparisons and swaps, if executed upon an already sorted array?

Insertion Sort

Why do we use inheritance?

To have a general class with common properties and behaviors shared by multiple more specialized classes.

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

what does a reference type represent

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

what happens when you use the new operator in the LinkedBag constructor

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

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

what behavior changes the contents of a bag

add()

Which of the following List member methods should not be implemented for a SortedList?

add(int newPosition, T newEntry)

Which of the following is 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 what

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

this()

calls the constructor of the current class

super()

calls the constructor of the parent class

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();

A class uses composition when it

declares an instance of another class as a data field

A subclass is also called a

derived class

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

What issue should you weigh when considering an implementation for an ADT?

execution time, memory use, extensibility

To prevent a subclass from overriding protected methods, we declare them to be

final

abstraction

focus on what not how

which method returns a count of the current number of items in a bag

getCurrentSize()

a fixed size size array

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

composition

has-a

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

head

In a binary search tree, the getInorderIterator inherited from the class BinaryTree sorts data

in ascending order

placing the Node class inside the LinkedBag class makes it an

inner class

inheritance

is-a relationship

What is an advantage of using a chain for a Bag ADT?

it avoids moving data when adding or removing bag entries

The use of a generic data type to be determined later by the client of the class

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

The data in a BST's node's _____ subtree are less than the data in a node's _____ subtree.

left, right

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

newPosition is 1

In the interface SearchTreeInterface, what does the method getEntry return if the object being sought doesn't exist?

null

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

null, 0

a superclass is also called a

parent class

Which of the following visibility modifiers should be used for a field in a class C if the programmer does not want the the subclass to have direct access to the field?

private


Kaugnay na mga set ng pag-aaral

2214 RealizeIT Module 4 Questions

View Set

Assessment Related to Acid-Base Balance

View Set

U.S. History American Economic Expansion

View Set