Data Structures

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

Suppose that you place 180 items in a hash table with an array size of 200. What is the load factor? 200 0.9 0.8 1.11

0.9

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using linear probing and a division hash function, where will these entries be placed in the table? For example to answer the question for entry 103:

103 at [0] 0 at [1] 205 at [102] 308 at [2] 411 at [3] 2 at [4]

For a sorted list of 1024 elements, a binary search takes at most _______ comparisons. 512 11 6 100

11

Suppose depth first search is executed on the graph below starting at some unknown vertex. Assume that a recursive call to visit a vertex is made only after first checking that the vertex has not been visited earlier. Then the maximum possible recursion depth (including the initial call) is 3 28 19 21

19

Suppose a list is {2, 9, 5, 4, 8, 1}. After the first pass of bubble sort, the list becomes 2, 1, 5, 4, 8, 9 2, 5, 4, 8, 1, 9 2, 9, 5, 4, 8, 1 2, 5, 9, 4, 8, 1 2, 9, 5, 4, 1, 8

2, 5, 4, 8, 1, 9

Suppose that you place 180 items in a hash table with an array size of 200. Using double hashing, what is the average number of table elements that you expect to have examined during a successful search? 2.56 2.0 5.50 1.45

2.56

What is the preorder traversal of the elements in an AVL tree after inserting 3, 4, 45, 21, 92, 12 in this order? 3 4 12 21 92 45 45 21 12 92 3 4 21 4 3 12 45 92 3 4 12 21 45 92 45 4 3 21 12 92

21 4 3 12 45 92

Which of the following complexity is O(nlogn)? 23nlogn + 50 00n + 400n*n 45n + 45n + 503 n*n*n + n

23nlogn + 50

Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the inorder traversal of the elements? 3 4 45 21 12 92 4 21 12 92 45 3 3 4 12 21 45 92 12 21 92 45 4 3 4 45 21 12 92 3

3 4 12 21 45 92

Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the preorder traversal of the elements after deleting 45 from the tree? 3 4 21 12 92 3 4 12 21 92 4 21 12 92 3 4 21 12 92 3 12 21 92 45 4 3

3 4 21 12 92

Suppose you choose the first element as a pivot in the list {5 2 9 3 8 4 0 1 6 7}. Using the partition algorithm in the book, what is the new list after the partition? 4 2 1 3 0 5 8 9 6 7 4 2 3 0 1 5 6 7 9 8 5 2 9 3 8 4 0 1 6 7 2 3 4 0 1 5 9 8 6 7 2 3 4 0 1 5 6 7 8 9

4 2 1 3 0 5 8 9 6 7

Suppose a weighted graph is created with the following code. What is the shortest path from vertex 4 to 0? Integer[] vertices = {0, 1, 2, 3, 4};int[][] edges = {{0, 1, 9}, {0, 2, 5}, {1, 0, 9}, {1, 2, 6}, {1, 3, 4}, {1, 4, 7},{2, 0, 5}, {2, 1, 6}, {2, 3, 3}, {3, 1, 4}, {3, 2, 3}, {3, 4, 1}, {4, 1, 7}, {4, 3, 1}}; WeightedGraph<Integer> graph1 = new WeightedGraph<>(vertices, edges);WeightedGraph<Integer>.ShortestPathTree tree1 = graph1.getShortestPath(graph1.getIndex(0));System.out.println("Shortest path from 4 to 0 is " +tree1.getPath(4)); 4 1 0 4 3 2 0 4 1 3 2 0 4 3 1 0 4 1 2 0

4 3 2 0

If G is an directed graph with 20 vertices, how many boolean values will be needed to represent G using an adjacency matrix? 200 20 40 400

400

Suppose that you place 180 items in a hash table with an array size of 200. Using linear probing, what is the average number of table elements that you expect to have examined during a successful search? 2.0 5.50 2.56 1.45

5.50

Order the following functions by growth rate in ascending order. So # 1 would be the smallest growth rate and #9 would be the largest growth rate. N^1.5 N N^3 2/N N^2 √N (square root of N) N log N 2^N 37

6, 4, 8, 1, 7, 3, 5, 9, 2

Which of the following statements are true about a heap? A binary tree is complete if every level of the tree is full except that the last level may not be full and all the leaves on the last level are placed left-most. A heap is a full binary tree. Each node is greater than or equal to any of its children. A heap is a complete binary tree.

A binary tree is complete if every level of the tree is full except that the last level may not be full and all the leaves on the last level are placed left-most., Each node is greater than or equal to any of its children., A heap is a complete binary tree.

Select the true statements about what a pivot is. You should always choose a pivot that divides the list evenly. A pivot divides a list into two sublists, the elements in the first list are no larger than the pivot and the elements in the second list are larger than the pivot. A pivot divides a list into two sublists of equal size. A pivot can be chosen arbitrarily.

A pivot divides a list into two sublists, the elements in the first list are no larger than the pivot and the elements in the second list are larger than the pivot. A pivot can be chosen arbitrarily.

Suppose you have a directed graph representing all the flights that an airline flies. What algorithm might be used to find the best sequence of connections from one city to another? A cycle-finding algorithm. Breadth first search. A shortest-path algorithm. Depth first search.

A shortest-path algorithm.

Select all of the correct responses. The WeightedGraph is a subtype of _________. AbstractGraph UnweightedGraph Graph WeightedEdge

AbstractGraph, Graph

The Minimum Spanning Tree (MST) class is a subtype of _____________. AVLTree Binary Search Tree (BST) Tree AbstractGraph.Tree

AbstractGraph.Tree

The ShortestPathTree class is subtype of a _______________. AVLTree Tree AbstractGraph.Tree Binary Serach Tree

AbstractGraph.Tree

Select all of the true statements about Java's root class Object: you should override the hashCode method whenever the equals method is overridden to ensure that two equal objects return the same hash code it has the hashCode method, which returns an integer hash code during the execution of a program, invoking the hashCode method multiple times returns the same integer, provided that the object's data are not changed two unequal objects may have the same hash code, but you should implement the hashCode method to avoid too many such cases by default, the hashCode method returns the memory address for the object

All of these

Select all of the true statements about the the implementation of a Binary Search Tree ( BST ). BST contains a property named root. If tree is empty, root is null. Node has a property named left that links to the left subtree and a property named right that links to the right subtree and a property named right Node is defined as an inner class inside BST. Node is defined as a static inner class inside BST because it does not reference any instance data fields in BST.

All of these

Why is algorithm analysis often for the worst case? Best-case is not representative. Worst-case is not representative, but worst-case analysis is very useful. You can show that the algorithm will never be slower than the worst-case. Average-case analysis is ideal, but difficult to perform, because it is hard to determine the relative probabilities and distributions of various input instances for many problems. All of these are true

All of these are true

Which graph representation allows the most efficient determination of the existence of a particular edge in a graph? Edge lists. An adjacency matrix.

An adjacency matrix.

The ________ approach searches for a candidate solution incrementally, abandoning that option as soon as it determines that the candidate cannot possibly be a valid solution, and then looks for a new candidate. Brute-force Dynamic programming Divide-and-conquer Backtracking

Backtracking

What graph traversal algorithm uses a queue to keep track of vertices which need to be processed? Breadth-first search. Depth-first search.

Breadth-first search.

______________ approach divides the problem into subproblems, solves the subproblems, then combines the solutions of the subproblems to obtain the solution for the entire problem. Unlike the ________ approach, the subproblems in the divide-and-conquer approach don't overlap. A subproblem is like the original problem with a smaller size, so you can apply recursion to solve the problem. Divide-and-conquer/dynamic programming Dynamic programming/divide-and-conquer Brute-force/divide-and-conquer Backtracking/dynamic programming

Divide-and-conquer/dynamic programming

A Depth First Search of a directed graph always produces the same number of tree edges, i.e., independent of the order in which vertices are considered. True False

False

Which of the following statements is true? Graph vertices may be linked in any manner. A graph must have at least one vertex. A graph can only be drawn on paper. A graph must have at least one edge.

Graph vertices may be linked in any manner.

A simple graph has no loops. What other property must a simple graph have? It must be undirected. It must have no multiple edges. It must have at least one vertex. It must be directed.

It must have no multiple edges.

_______ measures how full the hash table is. Load factor Threshold Hashing Probing

Load factor

Give a precise expression for the minimum number of nodes in an AVL tree of height h, as N(0) = N(1) = N(h) =

N(0) = 1 N(1) = 2 N(h) = N(h-1) + N(h-2) + 1

Assume n vertices are in the graph and m edges terminate at the desired node. What is the expected number of operations needed to loop through all the edges terminating at a particular vertex given an adjacency matrix representation of the graph? O(m) O(m)^2 O(n)^2 O(n)

O(n)

The time complexity for searching an element in a binary search tree is _______. O(logn) O(n) O(n^2) O(nlogn)

O(n)

The time to merge two sorted lists of size n is _________. O(n*n) O(nlogn) O(logn) O(n) O(1)

O(n)

The worst-time complexity for bubble sort is _____________. O(n*n) O(logn) O(1) O(n) O(nlogn)

O(n*n)

The time complexity for the selection sort algorithm in the text is ________. O(n^2) O(2^n) O(logn) O(nlogn)

O(n^2)

_____________ means to find an open location in the hash table in the event of collision. Normal hashing Open addressing Perfect hashing Separate chaining

Open addressing

The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is Q M N P O R N Q M P O R Q M N P R O M N O P Q R

Q M N P R O

What kind of initialization needs to be done for a chained hash table? None. The key at each array location must be initialized. The head pointer of each chain must be set to NULL. Both B and C must be carried out.

The head pointer of each chain must be set to NULL.

What kind of initialization needs to be done for an open-address hash table? The key at each array location must be initialized. The head pointer of each chain must be set to NULL. None.

The key at each array location must be initialized.

A map is also called a dictionary, a hash table, or an associative array. True False

True

A typical hash function first converts a search key to an integer value called a hash code, then compresses the hash code into an index to the hash table. True False

True

All of these questions are from the Liang textbook, 10th ed, Chapters 27 and some refer back to Chapter 21. The answer to this question is true. True False

True

Every object has the hashCode() method. True False

True

If two strings are equal, the two strings have the same hashCodes. True False

True

Java's root class Object has the hashCode method, which returns an integer hash code. True False

True

Many real-world problems can be solved using graph algorithms. True False

True

Regarding a BST, a new element is always inserted into a leaf node. True False

True

Representing a graph is to store its vertices and edges in a program. The data structure for storing a graph is arrays or lists. True False

True

The WeightedGraph class extends AbstractGraph. True False

True

The breadth-first search of a graph visits the vertices level by level. The first level consists of the starting vertex. Each next level consists of the vertices adjacent to the vertices in the preceding level. True False

True

The depth-first search of a graph starts from a vertex in the graph and visits all vertices in the graph as far as possible before backtracking. True False

True

The shortest path between two vertices is a path with the minimum total weights. True False

True

The time complexity of the Depth First Search algorithm is O(|E| + |V|). True False

True

Two equal objects will return the same hash code if the hashCode method is overridden whenever the equals method is overridden True False

True

Two objects have the same hashCodes if they are equal. True False

True

You can represent a graph using an adjacency matrix or adjacency lists. True False

True

What is the best definition of a collision in a hash table? Two entries are identical except for their keys. Two entries with different data have the exact same key. Two entries with different keys have the same exact hash value. Two entries with the exact same key have different hash values.

Two entries with different keys have the same exact hash value.

In an open-address hash table there is a difference between those spots which have never been used and those spots which have previously been used but no longer contain an item. Which function has a better implementation because of this difference? insert is_present remove size Two or more of the above functions

Two or more of the above functions

Suppose a graph is created in the following code. Using the depth first search algorithm in the text, what is the output for the path from 4 to 0? Integer[] vertices = {0, 1, 2, 3, 4}; int[][] edges = { {0, 1}, {0, 2}, {1, 0}, {1, 2}, {1, 3}, {1, 4},{2, 0}, {2, 1}, {2, 3}, {3, 1}, {3, 2}, {3, 4}, {4, 1}, {4, 3} }; Graph<Integer> graph1 = new UnweightedGraph<>(vertices, edges); AbstractGraph<Integer>.Tree dfs = graph1.dfs(0); System.out.println(dfs.getPath(4)); [4, 1, 2, 0] [4, 3, 2, 0] [4, 3, 1, 0] [4, 3, 2, 1, 0]

[4, 3, 2, 1, 0]

The getMinimumSpanningTree() method returns _____________. a queue a Minimum Spanning Tree (MST) a LinkedList an ArrayList

a Minimum Spanning Tree (MST)

If a graph is very sparse (i.e., very few edges), using a(n) ________________ is better, edge list object matrix adjacency matrix adjacency lists

adjacency lists

Regarding AVL trees, the _________ of a node is the height of its right subtree minus the height of its left subtree. degree balance factor length depth

balance factor

In a ________, the element j to be removed is always at the root. AVL tree binary tree binary search tree binary heap

binary heap

A __________ (with no duplicate elements) has the property that for every node in the tree the value of any node in its left subtree is less than the value of the node and the value of any node in its right subtree is greater than the value of the node. binary search tree linked list binary tree list

binary search tree

The ______________ search of a graph first visits a vertex, then all its adjacent vertices, then all the vertices adjacent to those vertices, and so on. minimum maximum breadth-first depth-first

breadth-first

The _________ is to visit the nodes level by level. First visit the root, then all children of the root from left to right, then grandchildren of the root from left to right, and so on. breadth-first traversal preorder traversal postorder traversal inorder traversal

breadth-first traversal

O(1) is ________. log-linear time linear time constant time logarithmic time

constant time

The _______ of a node is the length of the path from the root to the node. degree length depth height

depth

The ____________ search of a graph first visits a vertex, then it recursively visits all the vertices adjacent to that vertex. minimum maximum breadth-first depth-first

depth-first

In a _____________ graph, each edge has a direction, which indicates that you can move from one vertex to the other through the edge. theoretical universal undirected directed

directed

On an average, linear search searches one fourth of the list half of the list just one element in the list the whole list

half of the list

The _______ of a nonempty tree is the length of the path from the root node to its furthest leaf + 1. height degree length depth

height

You can reference a vertex, of a graph, by its name or its _____________ . boolean path index number of edges

index

The ________ is to visit the left subtree of the current node first, then the current node itself, and finally the right subtree of the current node. preorder traversal inorder traversal breadth-first traversal postorder traversal

inorder traversal

What is the return type value for the hashCode() method? long byte short int

int

When a collision occurs during the insertion of an entry to a hash table, ______ finds the next available location sequentially. linear probing quadratic probing double hashing normal hashing

linear probing

A __________ is an edge that links a vertex to itself. parallel edge loop weighted edge directed edge

loop

Suppose you place m items in a hash table with an array size of s. What is the correct formula for the load factor? s + m s - m m - s m * s m / s

m / s

Select the phrase that best completes the sentence. A hashing function _____________. deletes an element in the hash table stores an element in the hash table updates an element in the hash table maps a key to an index in the hash table

maps a key to an index in the hash table

How many linked lists are used to represent a graph with n nodes and m edges, when using an edge list representation? m m*n n m + n

n

What is the number of edges in a tree of n vertices? n*n n(n-1)/2 n - 1 n

n - 1

What is the number of edges in a complete graph of n vertices? n - 1 n*n n(n-1)/2 n

n(n-1)/2

Graph traversal is the process of visiting each vertex in the graph exactly _________ time(s). one zero two unlimited number of

one

If each key is mapped to a different index in the hash table, it is called _______. perfect hashing elemental hashing groovy hashing normal hashing

perfect hashing

The most efficient algorithm for sorting integer keys is __________. quick sort heap sort radix sort merge sort

radix sort

In the MyHashMap class in the text, the __________ method first copies all entries in a set, doubles the capacity, creates a new hash table, and resets the size to 0

rehash()

The __________ places all entries with the same hash index into the same location, rather than finding new locations. double hashing scheme quadratic probing scheme open addressing scheme separate chaining scheme

separate chaining scheme

What is the number of iterations in the following loop: int count = 5;while (count < n) {count = count + 3;} the ceiling of (n - 5) / 3 n - 5 n - 3 (n - 5) / 3

the ceiling of (n - 5) / 3

To remove the root of a heap, you need to start a process by first placing _______ to the place of the root and move it down to maintain the heap property. one of the root's children the smaller child of the root the last node in the heap the larger child of the root

the last node in the heap

Analyzing algorithm efficiency is used ________. to estimate algorithms execution time to measure algorithms actual execution time to estimate bandwidth needed to estimate algorithms growth function

to estimate algorithms growth function

A connected graph is a(n) _____________ if it does not have cycles. tree object weighted graph spanning tree

tree

Using linear probing, you want to place 1000 elements in a hash table, and you'd like an average search to examine just two table elements. How big does the table's array need to be? we need a load factor of 2/3, which requires a table capacity of 1500 we need a load factor of less than 0.8, which requires a table capacity of about 1250 we need a load factor of 2, which requires a table capacity of 500 we need a load factor of 0.4, which requires a table capacity of 2000

we need a load factor of 2/3, which requires a table capacity of 1500

Using double hashing, you want to place 1000 elements in a hash table, and you'd like an average search to examine just two table elements. How big does the table's array need to be? we need a load factor of less than 0.8, which requires a table capacity of about 1250 we need a load factor of 2/3, which requires a table capacity of 1500 we need a load factor of 0.4, which requires a table capacity of 2000 we need a load factor of 2, which requires a table capacity of 500

we need a load factor of less than 0.8, which requires a table capacity of about 1250

A collision occurs _____________. when two elements are swapped when two elements have the same key value. when two or more keys are mapped to the same hash value. when two elements are mapped to different hash tables

when two or more keys are mapped to the same hash value.

Suppose a heap is stored in an array list as follows: {100, 55, 92, 23, 33, 81}. After inserting 103, what is the content of the array list? {103, 55, 100, 23, 33, 81, 92} {100, 55, 92, 23, 33, 81, 103} {103, 55, 92, 23, 33, 81, 100} {100, 55, 103, 23, 33, 92, 81} {103, 55, 92, 23, 33, 81, 92}

{103, 55, 100, 23, 33, 81, 92}


Kaugnay na mga set ng pag-aaral

Art Appreciation Chapter 2 - Developing Visual Literacy

View Set