data structures final exam

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the efficiency of a linked chain queue

0(1)

what is the efficiency of the deque

0(1)

Given the following array, show the comparisons to an array entry that are performed to search for the number 23 if you use the binary search algorithm? 2 3 5 7 11 13 17 19 23 29 31 37

23 == 13, 23 < 13, 23 == 23

How many nodes are in a full binary tree of height 8?

2^8- 1 or 256 - 1 = 255

how many nodes does a full tree contain

2^n - 1 nodes

Give the level order traversal of the following binary tree. A B C D E F G H

A, B, C, D, E, F, G, H

Give the level order traversal of the following binary tree. (look at pdf)

A, B, C, D, E, F, G, H

Give the breadth-first traversal of the following graph beginning at vertex A. (refer to post-it)

A, B, E, D, C

How can you reference a node in a queue using a linked chain

Either the head reference (front) or tail reference (back)

what is the behavior of a queue

First in first out (FIFO)

Explain the two steps that typical hash functions perform.

First, they convert the search key into a hash code (an integer), then they compress the hash code into the range of indices for the hash table.

If myList is a declared ADT list and the front of the list is on the left, show the contents of the list after applying the following pseudo code? myList.add("Tom") myList.add("1, Hank") myList.add(2, "Ryan") myList.add("Sally") myList.add(3, "Helen")

Hank, Ryan, Helen, Tom, Sally

What is the behavior of a sequential search of either a list, an array, or chain

It looks at the first entry, then the second, and so on until it finds the specific entry or reaches the end and discovers there's no such entry

If myList is a declared ADT list and the front of the list is on the left, show the contents of the list after applying the following pseudo code? myList.add("Tom") myList.add("Hank") myList.add(3, "Ryan") myList.add(1, "Sally") myList.add("Helen")

Sally, Tom, Hank, Ryan, Helen

What is the fastest way to access a node in a queue using a linked chain

The first/front node

In the linked implementation of a list, why shouldn't the constructor call the method clear even though they do the same exact assignment statements?

The functionality should not be coupled because subsequent modifications to the clear method would also affect the constructor which might not be appropriate.

In a circular linked chain, every node references what

The next node

Assume you are using a hash function that takes strings and sums the Unicode values of each letter to create a hash code. Give an example of two strings that produce the same hash code.

The text gives the example DUB and BUD but there are infinitely many. An exam is RAM and ARM. The intent is to give the same string that is in a different order.

In the ADT DirectedGraph, what is the purpose of the data fields visited, previousVertex and cost?

These are needed to implement the shortest path algorithm and breadth and depth traversals.

In the ADT DirectedGraph, what is the purpose of the data fields visited, previousVertex and cost?

These are needed to implement the shortest path algorithm and breadth and depth traversals.

Explain why a public method should be declared to be final if it is called by a constructor.

This prevents another subclass from overriding it and potentially changing the effect of the constructor.

True or False when a chain has only a head reference: 1. adding nodes to chain's beginning is special case 2. removing first node is a special case 3. adding/removing a node that is last in chain requires chain traversal 4. adding a node anywhere within chain requires change of at most two references 5. removing a node anywhere within chain requires change of at most two references

True

How do we shield the client from the details of handling the first and last indexes of the array to search in a recursive search on an unsorted array?

Use the header that does not reveal the search method public static <T> boolean inArray(T[] inArray, t anEntry) and implement the algorithm as a private method search that inArray invokes

Show the contents of the stack as an inorder traversal is performed on the following binary tree. (refer to pdf)

a, a is empty and removed b, b c, c is empty and removed b is removed d e e is removed d is removed

In the ADT graph, the method clear has efficiency a. O(1) b. O(log n) c. O(n2) d. O(n)

a. O(1)

The technique for determining an array index using only a search key and not searching is called a. hashing b. direct indexing c. search key indexing d. stealth searching

a. hashing

A new entry is added to an array-based implementation of the ADT list a. immediately after the last occupied position b. immediately before the first occupied position c. in the last array position d. in the location returned by the new operator

a. immediately after the last occupied position

In a _____ traversal of a binary tree, you begin at the root and visit nodes one level at a time. a. level order b. inorder c. flat order d. straight order

a. level order

A node in a binary tree is an object that references a data object and a. two child nodes in the tree b. a linked list containing the child nodes c. a vector containing the list of child nodes d. none of the above

a. two child nodes in the tree

what is a list

an object with ordered entries

where can you add entries to a list

at the end or a specific index location

In a doubly linked chain implementation of a queue, what is the performance when the dequeue operation? a. O(log n) b. O(1) c. O(n) d. O(n2)

b. O(1)

An array provides _______ access to its elements. a. random b. direct c. sequential d. none of the above

b. direct

A(n) _____ is a collection of distinct vertices and distinct edges. a. binary search tree b. graph c. red-black tree d. AVL tree

b. graph

The most common implementation of a tree uses a(n) a. array b. linked structure c. bag d. priority queue

b. linked structure

In an array-based implementation of a queue, if waitingList is the name of the array, and the index to the last entry in the queue is called backIndex, write a single assignment statement to update backIndex to add an entry to the queue.

backIndex = (backIndex + 1) % waitingList.length;

If colorList is an array-based ADT list and the front of the list is on the left, show the contents of the list after applying the following code? colorList.add("red") colorList.add("purple") colorList.add("green") colorList.add(3, "yellow") my colorList List.add(1, "black") colorList.add(4, "blue")

black, red, purple, blue, yellow, green

If colorList is an array-based ADT list and the front of the list is on the left, show the contents of the list after applying the following code? colorList.add("red") colorList.add(1, "purple") colorList.add(1, "green") colorList.add(1, "yellow") my colorList List.add(1, "black") colorList.add("blue")

black, yellow, green, purple, red, blue

If we use a chain of linked nodes with only a head reference to implement a queue which statement is true? a. You must traverse the entire chain to access the last node. b. Accessing the last node is very inefficient. c. Both a & b d. None of the above

c. Both a & b

The worst-case time efficiency of a sequential search on an unsorted chain of linked nodes is a. O(log n) b. O(1) c. O(n) d. O(n2)

c. O(n)

A common implementation of a graph that uses a two dimensional array to represent the graph's edges is called a(n) a. graph array b. adjacency array c. adjacency matrix d. adjacency list

c. adjacency matrix

In a linked-based implementation of the ADT list with only a head reference, which method has a time efficiency of O(1)? a. toArray b. contains c. clear d. all of the above

c. clear

When you classify data into groups and subgroups, you are using a(n) _____ order. a. linear b. circular c. hierarchical d. group

c. hierarchical

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? myList.add("horse") myList.add("goat") myList.add(1, "fish") myList.replace(3, "sheep") myList.add("cat") myList.remove(1) myList.add(2, "dog") a. dog b. horse c. sheep d. cat

c. sheep

using another location in a hash table to resolve a collision is called

closed hashing

what are the two ways to resolve a hash map collision

closed hashing and open hashing

Collisions resolved with linear probing cause groups of consecutive locations in hash table to be occupied called

clusters

what occurs when more than one search key in a gets mapped to the same location in the hash table

collision

probing sequence uses ____________ locations

consecutive

how to expand an array list

copy the contents to a larger array

A linked implementation of a list a. uses memory only ass need for new entries b. returns unneeded memory to the system when an entry is removed c. avoids moving data when adding or removing entries d. all of the above

d. all of the above

Which operation is not performed on the ADT graph? a. add a vertex b. remove a vertex c. retrieve a vertex d. all of the above

d. all of the above

You can add a new entry in a list a. at the beginning b. at the end c. in between items d. all of the above

d. all of the above

When each location of a hash table can represent more than one value, that location is called a(n) a. open slot b. overloaded index c. linked slot d. bucket

d. bucket

If you have a list object to search that is an instance of ADT list, you search it by using the list operation a. search b. inList c. has d. contains

d. contains

an array implementation of a list provides _________ access to any of its elements using a method such as __________

direct, getEntry

what is the behavior of a deque

double sided queue where entries can be added or removed from either side

adding/removing an entry to an array list requires what, which causes what

entries to shift one position in the array causing degrading in time efficiency

True or False when a chain has a head and tail reference: 1. adding a node to an empty chain is a special case 2. adding a node to the chains end is a not a special case, and requires chain traversal 3. removing last node from a chain is a special case

false, 2. adding a node to the chains end is a special case, and does not requires chain traversal

True or false a binary search of an array does not require the array to be sorted

false, the array must be sorted before search

what is the behavior of a binary search of a sorted array

finds middle entry, figures out if specific entry is larger or smaller half then finds middle entry of that half and repeats until entry is found

In an array-based implementation of a queue, if waitingList is the name of the array, and the index to the last entry in the queue is called frontIndex, write a single assignment statement to update frontIndex to remove an entry to the queue.

frontIndex = (frontIndex - 1) % waitingList.length;

A _________ _________ transforms an entry's search key into the index of the array element that will contain the element

hash function

__________ is a dictionary implementation that stores entries into an array called the ____________ ______________

hashing, hash table

All classes that have a method hashCode that returns an

integer hash code

how is a sequential search typically performed

iteratively

A _______ is a node with no children

leaf

a perfect hash function does what

maps each search key into distinct location in the hash table

a good hash function should

minimize collisions and be fast to compute

If a directed graph has 9 vertices, how many edges can it have?

n x (n-1) = 9 x 8 = 72

a perfect hash function makes ________ efficiency implementations of the dictionary implementations possible

o(1)

what is the worst case of a binary search

o(log n)

the efficiency of a binary search of a tree can be as fast as _________ or as slow as __________

o(log n), o(n)

what is the average efficiency of a sequential search

o(n)

changing the structure of a hash table so that each array location can hold more than one value to resolve a collision is called

open hashing

probing that spaces the locations at the increasing increment of K + J^2 ( the squares of integers) is called

quadratic probing

how is a binary search typically performed

recursively

Write pseudocode for the binary tree method isLeaf() that returns true if the node is a leaf and false if not.

return (leftChild == null) && (rightChild == null)

Show the contents of the stack as an in order traversal is performed on the following binary tree. A B C D E

stack top is on the right A empty (A is removed) b b c b (c is removed) empty (b is removed) d d e d (e is removed) empty (d is removed)

what is inorder traversal of a tree

start at bottom left of tree visit left node then root then right node

whats the behavior of breadth first traversal of a graph

starting at original vertex, then moves to its left and right neighbors then its neighbor's neighbors

what is the behavior of level order traversal of a tree

starts at the root and visits nodes from left to right one level at a time

where are entries added in the queue

the back of the queue

which entry of a queue is at the front

the earliest added entry

Adding to which end of a linked chain list is faster when the chain has both head and tail references?

the end of the chain

what is a balanced tree

the subtrees of each node have exactly the same height

what is a root in a tree

the top node in the tree

A _________ is a set of nodes connected by edges that indicate the relationship among the nodes

tree

True or False maintaining a reference to a chain's first and last node eliminates the need for a chain traversal when adding a node at the end of the chain

true

what is the behavior of double hashing

uses a fixed increment depending on the search key and a second function provides the increment

what is postorder traversal of a tree

visit left node then right node then root

what is preorder traversal of a tree

visit the root first then the subtrees starting at left nodes then right nodes


संबंधित स्टडी सेट्स

Hess&Hunt and Inman: Domain III-Topic B

View Set

Week 4 Check Your Understanding Assignment

View Set

Radiation questions from classmates

View Set

Vocabulario de los dias del arcoiris

View Set

Chapter 68: Management of Patients With Neurologic Trauma

View Set

Chapter 2 Financial Statements, Taxes, and Cash Flow

View Set

Week 1: Ch. 9: Chronic Illness and Disability

View Set

Ch 40 PrepU: Nursing Care of a Family ... Respiratory Disorder

View Set