DS Test 3

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

Most hash functions involve the use of what operator?

% (x % N = (O, N))

For the following binary tree, what is the depth of node 4?

(depth = height) 4

A hash function

(gives you the hash code) maps key values to array indices

In a recursive algorithm, the base case represents ...

(represents where the problem is going to be terminated) solving the problem directly

A depth first search of the following graph starting at node 0 would return what? Assume that nodes are examined in numerical order when there are multiple edge

0 2 1 5 6 4 3

What would a breadth first search of the following graph return, if the search began at node 0? Assume that nodes are examined in numerical order when there are multiple edges.

0123456

For the following binary tree, what nodes would be visited in the search for node 5?

10, 8, 2, 1, 6, 4, 3 *X* 10 8 2 6. 4 ?

In a perfect binary tree with 128 leaf nodes, how many internal nodes are there?

127

For the following graph, what would a depth first search starting at node 2 return? Assume adjacent nodes are accessed in numerical order, starting with the lowest value.

2 4 5 3

In the code below, what value is stored in the variable named result? HashMap<String, Integer> hm = new HashMap<String, Integer>();hm.put("Lemon", 489);hm.put("Dragonfruit", 513);hm.put("Dragonfruit", 334);Integer result = hm.get("Dragonfruit");

334

For the following binary tree, what is the height of node 4?

4 *X* 1?

The number of nodes in a perfect binary tree of height 5 is ...

63

What are the leaf nodes of a perfect balanced binary search tree that has the following in-order traversal: 7 8 9 10 11 12 13

7 9 11 13

What will a post-order traversal of the following tree generate?

7, 22, 34, 80, 39, 29, 18

Given the following inputs: 4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199 and the hash function x mod 10 (x % 10), which of the following statements are true?

9679, 1989, 4199 hash to the same index. 1471, 6171 hash to the same index.

The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open addressing with hash function h(k) = k mod 10. What is the resulting hash table?

A & B don't have all values. D has multiple values (separate chaining?). Ans is C. 0 | 1 | 2 | 12 3 | 13 4 | 2 5 | 3 6 | 23 7 | 5 8 | 18 9 | 15

An adjacency matrix is implemented as:

A 2D array

What does the following method return? public static String fred (String s) { if (s.length() == 0) return s; char c = s.charAt(0); return fred(s.subsring(1)) + c; }

A string with the letters reversed

What type of graph would you need to represent cities and the distances between them?

An undirected, weighted graph.

Which statement is true about ArrayLists?

ArrayLists automatically expand in size as needed (from the perspective of users who use ArrayLists)

Characterize the following graph: a. Connected (can go from one node to any other node) b. Acyclic (no cycles) c. Directed (directions on edges) d. Complete (every node is connected to some other node)

Connected

If the height of a binary search tree is h, what is the largest number of nodes in that tree?

If binary tree has height h, maximum number of nodes will be when all levels are completely full. Total number of nodes will be 2^(h+1) - 1

Traversing a BST by which method would cause the values to appear in an ascending sorted sequence?

In-order

Using separate chaining, insert the following five items into a hash table of capacity 5, in the order given. What is the result? Key: Hash Code: A ----- 0 B ----- 1 C ----- 2 D ----- 0 E ------ 2

Index: Value: 0 ----- D->A 1 ----- B 2 ----- E->C 3 ----- null 4 ----- null

Of what use is a hash table's load factor?

Indicates the percentage full at which you increase the size of the hash table

A well designed hash table and function will give what complexity for retrieval of items?

O(1)

If a binary search tree is balanced, what is the complexity of a search?

O(log n)

Running merge sort on an array of size n which is already sorted is

O(n log n)

If a binary search tree is unbalanced, what is the complexity of an add?

O(n)

In recursive methods, if a temporary variable is used to store intermediate results, how many copies of that variable will exist from the first call to the last one when the recursion finishes?

One for each recursive call

Which sorting algorithm uses a pivot to divide the items to be sorted into two groups?

QuickSort

Which statements are true of the graph represented by the following adjacency matrix: 0 1 2 3 0 0 1 0 1 1 1 0 0 0 2 0 0 1 0 3 0 1 1 0

The graph is directed. There is an edge from 3 to 1. There is a self-loop on node 2.

What is a hash tables load factor ?

The number of keys stored in the hash table divided by the capacity of the table.

What kind of data structure would be the best for implementing a file system like the one on your hard drive?

Tree

A hash function may generate the same index for different inputs.

True

The data structure best to find and remove an item efficiently is a ...

balanced binary search tree

Select all the descriptors that are applicable to the following tree:

binary search tree + complete *X* binary search tree?

In a singly-linked list that keeps track of the first element as the head and the last element as the tail, which is true about the state of the list, after we add a node to an empty singly-linked list?

c. The new node is the head of the list, the tail node is null. *X* The new node is the head and tail of the list.?

Select all the descriptors that are applicable to the following tree:

full balanced *.67* full, complete, balanced?

Which data structure is most useful for looking up people by their social security number?

hash table

What equation represents the number of internal nodes (i) in a complete binary tree that has height h?

i = 2^(h) - 1 *X* Undetermined without seeing the tree?

In a tree with N nodes, how many edges will there will be?

n-1

Which line of code completes the solution to the factorial problem, i.e. n*(n-1)*(n-2) ... *1 given: public int fac (int n) { int result; if (n == 1) result = 1; else // what goes here? return result; }

result = n * fact(n-1)

A perfect hash function requires:

that every key value maps to a unique index

What would be the pre-order traversal of this tree:

traverse from the root to the left subtree then to the right subtree 17 48 36 21 75 51 92?

A node can be both a root and a leaf.

true


Kaugnay na mga set ng pag-aaral

Mathematics Methods and Instruction for Students with Mild/Moderate Exceptionalities - D237

View Set

Fundamentals of Success - Legal and Ethical Issues

View Set

Intermediate Accounting - Chapter 1 SB

View Set

Chapter 7: Difficulty Conceiving a Child: Infertility

View Set