Midterm ADS Prac

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Suppose you insert 15, 25, 35, and 45 into a queue. Then you remove three items. Which one is left?

45

True or False, At least one method in array based priority queue traverses through the array.

True

True or False: Deletion in a red-black tree may require some readjustment of the tree's structure.

True

True or False: Not all trees are binary trees.

True

True or False: When one rotation immediately follows another, they are in opposite directions.

True

True or False: When you delete an item from an unordered array, in most cases you shift other items to fill in the gap.

True

A doubly double-ended linked list will contain head and tail pointers.

True

Inserting a node starts with the same steps as _______ a node.

finding

Access to the links in a linked list is usually through the _________ link

first

Creating an array in Java requires using the keyword

new

How many references must you change to insert a link at the end of a singly linked list?

1

In the Java code for a tree, the ______ and the _______ are generally separate classes.

node, tree

Suppose you push 10, 20, 30, and 40 onto the stack. Then you pop three items. Which one is left on the stack?

10

How many references must you change to insert a link in the middle of a singly linked list

2

If a tree is represented by an array, the right child of a node at index n has an index of _______ .

2*n+1

The base 10 logarithm of 1,000 is

3

In a complete binary tree with 20 nodes, and the root considered to be at level 0, how many nodes are there at level 4?

5

The base 2 logarithm of 64 is

6

The maximum number of elements that must be examined to complete a binary search in an array of 200 elements is

8

Suppose a node A has a successor node S. Then S must have a key that is larger than _____ but smaller than or equal to _______.

A, A's left-child descendents

True or False: Deleting a node with one child from a binary search tree involves finding that node's successor.

False

True or False: If there are N items, the bubble sort makes exactly N*N comparisons.

False

True or False: If, in a particular sorting situation, swaps take much longer than comparisons, the selection sort is about twice as fast as the bubble sort.

False

True or False: In an unordered array, it's generally faster to find out an item is not in the array than to find out it is.

False

True or False: The base 2 logarithm of 100 is 2

False

True or False: The bubble sort always ends up comparing every item with every other item

False

True or False: The red-black rules rearrange the nodes in a tree to balance it.

False

True or False: A stack or a queue often serves as the underlying mechanism on which an ADT array is based.

False. It's the other way around.

True or False: Pushing and popping items on a stack and inserting and removing items in a queue all take O(N) time.

False. They take O(1) time.

As other items are inserted and removed, does a particular item in a queue move along the array from lower to higher indices, or higher to lower?

It doesn't move at all.

Which of the following is not a red-black rule? a. Every path from a root to a leaf, or to a null child, must contain the same number of black nodes. b. If a node is black, its children must be red. c. The root is always black. d. All three are valid rules.

If a node is black, its children must be red.

Which of the following is not true about a Huffman tree? a. The most frequently used characters always appear near the top of the tree. b. Normally, decoding a message involves repeatedly following a path from the root to a leaf. c. In coding a character you typically start at a leaf and work upward. d. The tree can be generated by removal and insertion operations on a priority queue.

In coding a character you typically start at a leaf and work upward.

In a binary tree used to represent a mathematical expression, which of the following is not true? a. Both children of an operator node must be operands. b. Following a postorder traversal, no parentheses need to be added. c. Following an inorder traversal, parentheses must be added. d. In pre-order traversal a node is visited before either of its children.

In pre-order traversal a node is visited before either of its children.

What is the invariant in the selection sort?

Items with indices less than or equal to outer are sorted.

The invariant in the insertion sort is that

Items with indices less than outer are partially sorted

When all references to a link are changed to refer to something else, what happens to the link?

Java's garbage collection process destroys it.

What do LIFO and FIFO mean?

Last-In-First-Out; and First-In-First-Out

Efficiency: Linear Search - ? Binary Search - ? Insertion, unordered array - ? Insertion, ordered array - ? Deletion, unordered array - ? Deletion, ordered array - ?

Linear Search - O(n) Binary Search - O(log n) Insertion, unordered array - O(1) Insertion, ordered array - O(n) Deletion, unordered array - O(n) Deletion, ordered array - O(n)

Inserting an item into a typical priority queue takes what big O time?

O(N)

Insertion and deletion in a tree require what big O time?

O(logN)

Inserting an item into a typical array based priority Queue takes what big O time ?

O(n)

What is the efficiency of the following code. for(int i = 0 ; i < n ; i++){arr[i] = 0;}

O(n)

What will be the efficiency if you want to delete the largest item in an unordered singly linked list with a head pointer.

O(n)

What is the most popular algorithm? How does it work?

Quicksort, breaks array into sub arrays, calls itself recursively to quick sort each array. chooses a pivot element to partition array, elements less than pivot go left, element greater than pivot rightsingle partition : O(n)overall: O(N*logN)

Which of the following is true? The pop operation on a stack is considerably simpler than the remove operation on a queue. The contents of a queue can wrap around, while those of a stack cannot. The top of a stack corresponds to the front of a queue. In both the stack and the queue, items removed in sequence are taken from increasingly high index cells in the array.

The contents of a queue can wrap around, while those of a stack cannot

Which of the following is true The top of a stack corresponds to the front of a queue The contents of a stack can wrap around, while those of a queue cannot The pop operation on a stack is simpler than dequeue operation of a queue

The top of a stack corresponds to the front of a queue

Which do you think would be a better choice to implement a stack: a singly linked list or an array?

Usually, the list. They both do push() and pop() in O(1) time, but the list uses memory more efficiently.

A priority queue might be used to hold a. passengers to be picked up by a taxi from different parts of the city. b. keystrokes made at a computer keyboard. c. squares on a chessboard in a game program. d. planets in a solar system simulation.

a

Of the lists discussed in this chapter, which one would be best for implementing a queue?

a double-ended list

Assuming a copy takes longer than a comparison, is it faster to delete an item with a certain key from a linked list or from an unsorted array?

a linked list

In the selection sort,

a minimum key is repeatedly discovered

A color flip involves changing the color of ______ and ______ .

a node, its two children

A null child is a. a child that doesn't exist but will be created next. b. a child with no children of its own. c. one of the two potential children of a leaf node where an insertion will be made. d. a non-existent left child of a node with a right child (or vice versa).

a non-existent left child of a node with a right child (or vice versa).

A queue might be used to hold a. the items to be sorted in an insertion sort. b. reports of a variety of imminent attacks on the star ship Enterprise. c. keystrokes made by a computer user writing a letter. d. symbols in an algebraic expression being evaluated.

c

The term priority in a priority queue means that a. the highest priority items are inserted first. b. the programmer must prioritize access to the underlying array. c. the underlying array is sorted by the priority of the items. d. the lowest priority items are deleted first.

c

Shifting a group of items left or right requires repeated

copies

A double-ended list

can be accessed from either end.

When you create a reference to a link in a linked list, it

can refer to any link you want

The bubble sort algorithm alternates between

comparing and swapping

The two basic operations in simple sorting are _________ items and _________ them (or sometimes _________ them)

comparing and swapping (or copying)

A Huffman tree is typically used to _______ text.

compress

Computer sorting algorithms are more limited than humans in that

computers can compare only two things at a time

O(1) means a process operates in _________ time.

constant

Suppose you have a curr pointer pointing to the second last node of a regular linked list. Which of the following lines will delete the last node.

curr.next = null

Assuming current points to the next-to-last link in a singly linked list, what statement will delete the last link from the list?

current.next=null;

A special case often occurs for insertion and deletion routines when a list is

empty

A binary tree is a search tree if a. every non-leaf node has children whose key values are less than (or equal to) the parent. b. every left child has a key less than the parent and every right child has a key greater than (or equal to) the parent. c. in the path from the root to every leaf node, the key of each node is greater than (or equal to) the key of its parent. d. a node can have a maximum of two children.

every left child has a key less than the parent and every right child has a key greater than (or equal to) the parent.

True or False, Insertion sort divides an array in half at each iteration

false

A subtree of a binary tree always has a. a root that is a child of the main tree's root. b. a root unconnected to the main tree's root. c. fewer nodes than the main tree. d. a sibling with the same number of nodes.

fewer nodes than the main tree

What is the use of an iterator?

give user control of transversal, create multiple current pointers

In the insertion sort, "partially sorted" means that

group items are sorted among themselves, but items outside the group may need to be inserted in it

Which of the following is not true? A reference to a class object

has a size dependant on its class.

What is double ended linked list.

has both head and tail reference

Access to a singly linked list is usually through which node.

head

Finding a node in a binary search tree involves going from node to node, asking

how big the node's key is in relation to the search key

Big O notation tells

how the speed of an algorithm relates to the number of items

A balanced binary search tree is desirable because it avoids slow performance when data is inserted ________ .

in order (or inverse order)

An unbalanced tree is one

in which the root or some other node has many more left children than right children, or vice versa.

In an unordered array, allowing duplicates

increases search times in some situations

Which of the following is not true? Iterators would be useful if you wanted to a. do an insertion sort on a linked list. b. insert a new link at the beginning of a list. c. swap two links at arbitrary locations. d. delete all links with a certain key value.

insert a new link at the beginning of a list.

Suppose you have an application that maintains a list of customers who have already used a coupon code to buy a movie ticket. What is the most common operation for this list ? What kind of list will you use ?

insert, unordered

When class A is using class B for something, the methods and fields class A can access in class B are called class B's __________

interface

Stability might refer to

keeping cities sorted by increasing population within each state, in a sort by state

Complete the following code to find a node in a BST.Node curr = root;while(curr.data != value) {if( [ Select ] )curr = curr.left;else curr = curr.right; if ( [ Select ] ) return null;}return curr;

key < curr.datacurr == null

A "crossover" node or subtree starts as a ________ and becomes a _______ , or vice versa.

left child, right child

Post-order tree traversal

left, right, visit

In-order tree traversal

left, visit, right

In the insertion sort, after an item is inserted in the partially sorted group, it will

never be shifted to the left

What is the efficiency of bubble sort algorithm.

o(n^2)

Either variables of primitive types or _________ can be placed in an array

objects

An outside grandchild is a. on the opposite side of its parent that its parent is of its sibling. b. on the same side of its parent that its parent is of its parent. c. one which is the left descendant of a right descendant (or vice versa). d. on the opposite side of its parent that its sibling is of their grandparents

on the same side of its parent that its parent is of its parent

How many times would you need to traverse a singly linked list to delete the item with the largest key?

once, if the links include a previous reference

Ordered arrays in compared to unordered arrays are:

quicker at searching

Ordered arrays, compared with unordered arrays, are

quicker at searching

A logarithm is the inverse of

raising to a power

Which of the following is not involved in a rotation? a. rearranging nodes to restore the characteristics of a binary search tree b. changing the color of nodes c. ensuring the red-black rules are followed d. attempting to balance the tree

rearranging nodes to restore the characteristics of a binary search tree

Newly inserted nodes are always colored _______

red

The two possible actions used to balance a tree are _______ and _______ .

rotations, changing the colors of nodes

Inserting an item into an unordered array

takes the same time no matter how many items there are

In the insertion sort, the "marked player" described in the text corresponds to which variable in the insertSort.java program?

temp

Assume an array is numbered with index 0 on the left. A queue representing a line of movie-goers, with the first to arrive numbered 1, has the ticket window on the right. Then: a. there is no numerical correspondence between the index numbers and the movie-goer numbers. b. the array index numbers and the movie-goer numbers increase in opposite left-right directions. c. the array index numbers correspond numerically to the locations in the line of movie-goers. d. the movie-goers and the items in the array move in the same direction.

the array index numbers and the movie-goer numbers increase in opposite left-right directions.

One difference between a priority queue and an ordered array is that a. the lowest-priority item cannot be extracted easily from the array as it can from the priority queue. b. the array must be ordered while the priority queue need not be. c. the highest priority item can be extracted easily from the priority queue but not from the array. d. All of the above.

the array must be ordered while the priority queue need not be.

If class A is going to use class B for something, then

the more work that class B can do, the better

In the insertFirst() method in the linkList.java program (Listing 5.1), the statement newLink.next=first; means that

the next field of the new link will refer to the old first link.

What does the following code in the insertFirst() method of a linked list mean ? newNode.next = head;

the next field of the new node will refer to the old head node

Two rotations are necessary when a. the node is an inside grandchild and the parent is red. b. the node is an inside grandchild and the parent is black. c. the node is an outside grandchild and the parent is red. d. the node is an outside grandchild and the parent is black.

the node is an inside grandchild and the parent is red.

In a balanced tree,

the paths from the root to all the leaf nodes are about the same length.

A copy is ________ times as fast as a swap.

three

True or False, Binary Search can only be performed on ordered arrays.

true

True or False, Linear Search can be performed on both ordered and unordered arrays.

true

Pre-order tree traversal

visit, left, right

Which of the following is not true? Rotations may need to be made a. before a node is inserted. b. after a node is inserted. c. during a search for the insertion point. d. when searching for a node with a given key.

when searching for a node with a given key.


Ensembles d'études connexes

AP Psych Unit 6 content quiz questions

View Set

NSG OB Nursing Management during the Postpartum Period Week 3

View Set

Pediatrics AAP Board Review Questions

View Set

NCLEX The client with pancreatitis

View Set

Intro to Criminal Justice Test #2

View Set

MBIO 4310 - Final Exam Review Questions

View Set