Data Structures Final Study Guide

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

D - E - B - F - G - C - A

Apply a post order traversal to this binary tree: D - B - E - A - F - C - G A - B - D - E - C - F - G G - F - E - D - C - B - A A - B - C - D - E - F - G D - E - B - F - G - C - A

3

Apply an In-Order Traversal to this array based tree. What position is the root in the output? If it's the first output, indicate 1, for example, if the output was 1 - 2 - 3 - 4 - 5, and 1 is the root, put 1 as the answer. If 4 is the root, then 4th position, so 4 is the anser.

27

Build a 2-3 Tree using the following values. After the tree is built, what value(s) is/are in the root? 27 49 19 24 39 71 88 20

19, 42, 55, 88

Build a Binary Search Tree with the following values. Which values are on the 3rd level? Reminder, the root is the 1st level. 48, 37, 69, 55, 19, 31, 42, 88, 53

21, 24

Build a Max Heap with the following values. What two values are on the second level? (Reminder, the root is at the first level.) 17, 12, 24, 28, 23, 21, 5

23

Build a max heap for the following values. 7, 19, 12, 5, 15, 23, 2, 14 What is the value in the root?

49

Build an AVL tree from the following values, which value is the first to become the Alpha node? 35, 49, 22, 27, 64, 60

1400

Determine the memory address for the following element using row-major order. Given, the base address of the array is 1400. The array is 12 rows, 9 columns. Element size is 4. What is the memory address of Array[0,0]?

1432

Determine the memory address for the following element using row-major order. Given, the base address of the array is 1400. The array is 12 rows, 9 columns. Element size is 4. What is the memory address of Array[0,8]?

1796 (1400+11*4*9)

Determine the memory address for the following element using row-major order. Given, the base address of the array is 1400. The array is 12 rows, 9 columns. Element size is 4. What is the memory address of Array[11,0]?

1604 (1400+5*4*9+6*4) Calculating where an element is: Base Address + Index * element size. Calculating the memory address of an element with row-major. Base Address + Index * element size + rows allocated size. Ex: Base Address: 1000 Element Size: 4 Int array[4,5] = ... Array[1, 2] = 1000 + (2 * 4) + (1 * 5 * 4) = 1000 + 8 + 20 = 1028

Determine the memory address for the following element using row-major order. Given, the base address of the array is 1400. The array is 12 rows, 9 columns. Element size is 4. What is the memory address of Array[5,6]?

After the first addition operator, the top of the stack is 13 the bottom of the stack is 13 After the subtraction operation, the top of the stack is 1 After the multiplication, the top of the stack is 6 After the whole expression is evaluated, the final answer is 5

Evaluate the following Reverse Polish expression to determine the state of the stack at specific points in time. 7 6 + 5 4 - 3 2 * + 1 + - After the first addition operator, the top of the stack is ? the bottom of the stack is ? After the subtraction operation, the top of the stack is ? After the multiplication, the top of the stack is ? After the whole expression is evaluated, the final answer is ?

White

For the Tri-Color Garbage Collection algorithm. Which set holds only garbage at the end of the algorithm?

B: A->C C: B->A->D (Not in alphabetical order) E:

For the following graph, indicate which list(s) in the adjacency list is/are incorrect. A: B->C B: A->C C: B->A->D D: B->C->E E: None of the above.

A, B, D, F, G, H

For the following graph, select which rows are correct.

B, C, D, F

For the following objects in memory, run the Tri-Color Garbage Collector and determine which objects are garbage. Root objects are A, G. What is garbage?

AH, CH, BC, GH

For the following weighted simple graph, find the minimum spanning tree using Kruskal's algorithm. In the building of the tree, which edges cause a cycle to be formed, and are subsequently removed?

Binary Tree Binary Search Tree AVL Tree

For the given array based tree, what category(ies) of trees could the data represent? Binary Tree Binary Search Tree AVL Tree Max Heap Min Heap None of these

O(n^2)

Given the following Function notation, what is the Big-Oh? 3n^2 + 5n + 10

2

Given the following array, after how many values in the array are tested against with a binary search looking for 57?

Eulerian circuit & Hamiltonian circuit

Given the following graph, identify which Euler and/or Hamiltonian characteristics it posses. Eulerian path (trail) Eulerian circuit Hamiltonian path (trail) Hamiltonian circuit Eulerian path (trail) & Hamiltonian path (trail) Eulerian circuit & Hamiltonian path (trail) Eulerian path (trail) & Hamiltonian circuit Eulerian circuit & Hamiltonian circuit None of the above

Hamiltonian circuit

Given the following graph, identify which Euler and/or Hamiltonian characteristics it posses. Eulerian path (trail) Eulerian circuit Hamiltonian path (trail) Hamiltonian circuit Eulerian path (trail) & Hamiltonian path (trail) Eulerian circuit & Hamiltonian path (trail) Eulerian path (trail) & Hamiltonian circuit Eulerian circuit & Hamiltonian circuit None of the above

5

Given the following operations applied to a queue, what value is at the front of the queue? Enqueue 10 Enqueue 5 Dequeue Enqueue 17 Enqueue 6

6

Given the following operations applied to a stack, what value is at the top of the stack? Add 5 Add 10 Remove 10 Add 17 Add 6

B->right, C->left

Given this doubly linked list, and the definition of a node below. What pointers will be changed to add 40? Use A, B, C, D, E as the name of the node. Example answer A-left

5

Identify which cell adding key 40 with a normalized hash result of 4 is placed into the following hash table using linear probing for collision resolution.

3

Identify which cell adding key 70 with a normalized hash result of 6 is placed into the following hash table using linear probing for collision resolution.

Test if the list is empty. Update the temporary node's next pointer. Create a temporary pointer. Shift the temporary pointer into position. Create a node with the new value.

Identify which of these steps you need to code for to add a new value to a sorted singly linked list. Have the new value returned by the add function. Test if the list is empty. Update the temporary node's next pointer. Create a temporary pointer. Shift the temporary pointer into position. Create a node with the new value. Delete the new node. Delete the temporary node.

Values must be rehashed and reinserted into the new array.

If a hash table's array is resized to reduce collisions, what must be done to the existing values already in the table? Values must be rehashed and reinserted into the new array. The Hash Function must be changed. All items must be copied over to the same indices in the new array. The Hash Function must be changed. All n items must be copied over to fill the first n elements of the new array. The existing items need be discarded.

int track=0; for(int i=0;i<size;i++) { if(numbers[i]==key) { track++; } if(track==2) { return i; } } return -1; }

Implement the body of this function header. The function will return the index of the second occurrence of key. int FindSecond(int numbers[], int size, int key) {

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

Perform a delete operation on the following min heap, what does the corresponding tree look like?

False

Spatial locality of reference is related to a recently used resource is likely to be used again in the near future.

True

Spatial locality of reference is related to the use of resources near other resources at a particular time.

B, D, G, H (not in that order)

Starting at vertex A, use Prim's algorithm to find the Minimum Spanning Tree. What are the 4 nodes added to the tree after node A?

True

Temporal locality of reference is related to a recently used resource is likely to be used again in the near future.

False

Temporal locality of reference is related to how many times a resource is used.

59, 41

Using Merge Sort, for the following in-progress sort, which two numbers will be in a different spot after the next state change?

45, 24, 51, 14

Using Quicksort, if the Pivot is [ 28 ], which values are found to be in the wrong partition after the first pass across the array?

Object C is not reclaimed yet.

Using Reference Counting Garbage Collection. Identify which line, if any, will cause the reclamation of the object C. Reference x = new Object(C); Reference y = x; Reference z = new Object(B); y = x; z = x;

42, 11

Using a Selection Sort on the following array, which two numbers will be in a different spot after the next state change?

No determinable maximum

Using a chained hash table with an array size of 17. What is the maximum number of entries that can be added to the table. 9 16 17 34 No determinable maximum

3

Using an Insertion sort, identify which line made an incorrect state change. Underlined items for a row indicate changes made.

19, 34, 41 Feedback The value at index 0 is using the simplest approach for pivot selection. The value at index 4 is using the middle value, which keeps us away from worst case scenarios on already sorted data. The median value, which can occur at either index 0, 4, or 8, works to further improve how even the splits are.

Using each of the three methods for selecting the Pivot in the Quick Sort algorithm, which pivots would be used?

void List::addToHead(int data) { Link *temp = new Link(); temp->info = data; temp->prev = null; temp->next = head; if(head!=null) head->prev=temp; head = temp; if(tail==null) tail=head; }

Using the following code, implement AddToHead(int data) class Link { public: int info; Link* prev; Link* next; }; class List { Link* head; Link* tail; ...

void Dequeue() { if (isEmpty()) { cout << "Queue is empty!" << endl; //end if there's nothing to remove return; } //store Front in temp node* temp = Front; //get the next node from node in Front //and make it the new Front Front = Front->next; Count--; //if the front reaches the back //set the back to 0 if (Front==0) { Back=0; } delete(temp); }

Using the following node definition, implement the Dequeue function. class Node { public: int data; Node* next; }; class Queue {private:Node* first; Node* last; ...

The second vertex in the output is A The fourth vertex in the output is G The last vertex to be output is I

Using this Graph, apply a Breadth First Search starting at Vertex D to fill in the statement. Vertexes are labeled with capital letters and so must your answers. Note that D is the first vertex in the output. The second vertex in the output is ? The fourth vertex in the output is ? The last vertex to be output is ?

The second vertex in the output is A The fourth vertex in the output is C The last vertex to be output is I

Using this Graph, apply a Depth First Search starting at Vertex D to fill in the statement. Vertexes are labeled with capital letters and so must your answers. Note that D is the first vertex in the output. The second vertex in the output is ? The fourth vertex in the output is ? The last vertex to be output is ?

Bi-Partite

What classification(s) [shape(s))], does the following graph fit into? Cycle Wheel Star Complete Bi-Partite Complete Bi-Partite None of the above.

Cycle

What classification(s) [shape(s))], does the following graph fit into? Cycle Wheel Star Complete Bi-Partite Complete Bi-Partite None of the above.

Cycle Complete

What classification(s) [shape(s))], does the following graph fit into? Cycle Wheel Star Complete Bi-Partite Complete Bi-Partite None of the above.

None of the above.

What classification(s) [shape(s))], does the following graph fit into? Cycle Wheel Star Complete Bi-Partite Complete Bi-Partite None of the above.

Star Bi-Partite Complete Bi-Partite

What classification(s) [shape(s))], does the following graph fit into? Cycle Wheel Star Complete Bi-Partite Complete Bi-Partite None of the above.

Star Complete Complete Bi-Partite

What classification(s) [shape(s))], does the following graph fit into? Cycle Wheel Star Complete Bi-Partite Complete Bi-Partite None of the above.

Wheel

What classification(s) [shape(s))], does the following graph fit into? Cycle Wheel Star Complete Bi-Partite Complete Bi-Partite None of the above.

Wheel Complete

What classification(s) [shape(s))], does the following graph fit into? Cycle Wheel Star Complete Bi-Partite Complete Bi-Partite None of the above.

All of the above

What factors affect the probability of a collision? Table Size Hash Function Load Factor All of the above None of the above

Two different keys being normalized into the hash table at the same index.

What is a collision in a hash table? A hash table that does not have any primary clustering. All keys added to the table without any collisions. Two different keys hashing to a value outside of the range of the table. A hash table that is completely full. Two different keys being normalized into the hash table at the same index. A hash function that returns a hash value that does not need to be normalized into the table. A hash function that yields a uniform distribution in its hash results before normalization.

All keys added to the table without any collisions.

What is a perfect hash in a hash table? A hash table that is completely full. Two different keys being normalized into the hash table at the same index. All keys added to the table without any collisions. A hash table that does not have any primary clustering. A hash function that yields a uniform distribution in its hash results before normalization. A hash function that returns a hash value that does not need to be normalized into the table. Two different keys hashing to a value outside of the range of the table.

O(1)

What is the Big-Oh notation of adding a value to an array based queue?

O(1)

What is the Big-Oh notation of removing a value from a linked based stack?

O(1)

What is the big - Oh for a minimal perfect hash lookup?

O(n^2)

What is the big-oh for the Bubble sort?

O(n^2)

What is the big-oh for the Insertion sort?

O(n lg n)

What is the big-oh for the Merge sort?

O(n^2)

What is the big-oh for the Quick sort?

O(n^2)

What is the big-oh for the Selection sort?

O(lg n)

What is the big-oh notation for the following operation? Add a new value to a 2-3 tree.

O(n)

What is the big-oh notation for the following operation? Add a new value to a binary search tree.

O(lg n)

What is the big-oh notation for the following operation? Add a new value to a min heap.

O(n)

What is the big-oh notation for the following operation? Generating a postfix expression from an expression tree.

O(lg n)

What is the big-oh notation for the following operation? Searching a 2-3 tree.

O(n)

What is the big-oh notation for the following operation? Searching a max heap?

O(lg n)

What is the big-oh notation for the following operation? Searching an AVL tree?

None of the above.

What is the degree of every vertex in a Cycle graph? | V | - 2 | V | - 1 | V | | V | + 1 | V | + 2 None of the above.

None of the above.

What is the degree of every vertex in a Star graph? | V | - 2 | V | - 1 | V | | V | + 1 | V | + 2 None of the above.

|V|-1

What is the degree of every vertex in a complete graph?

|V|-1

What is the degree of the vertex at the center of a Star graph?

n

What is the functional notation for line 3? int count = 0; for ( int i = 0; i < n; i++) count++; for (int k = 1; k < n; k++) count++; cout << count << endl;

2n

What is the functional notation for line 4? int count = 0; for ( int i = 0; i < n; i++) count++; for (int k = 1; k < n; k++) count++; cout << count << endl;

The ratio of the number of elements in the table to the size of the table.

What is the load factor of a hash table? The number of entries loaded into the hash table. Using prime numbers for the size of the hash table. The ratio of the number of elements in the table to the size of the table. A measure of the primary clustering in the table. None of the above.

3

What is the the most common degree of a vertex in a Wheel graph?

O(n)

What is the worst case performance of a hash table lookup?

Revisiting the original hash index

What terminates a failed linear probe in a full hashtable? A node with a non-matching key A deleted node Revisiting the original hash index The end of the array A null/empty entry

The number of levels in the tree. Length of the longest path from root to lowest leaf.

What way(s) can we use to determine the actual tree height (0 or 1 based) of a given tree? The number of levels in the tree. Length of the longest path from root to lowest leaf. Trees don't have height, they have depth. The number of nodes in the tree. The value of n in an n-arry tree. If the tree is balanced or not.

0

Which line of code has a bug? If there is one. If not, enter 0. int Function(int p) { if (p == 0) cout << "0\n"; else cout << Function(p / 2) << endl; return p; }

6

Which line of code has the recursive call? If there is one. If not, enter 0. int Function(int p) { if (p == 0) cout << "0\n"; else cout << Function(p / 2) << endl; return p }

It's a binary search tree. It's a binary tree. It's balanced.

Which of the following are characteristics of an AVL tree? All leaves are at the lowest two levels. It's weight balanced. It's a binary search tree. It's a binary tree. It's balanced.

Pop Push

Which of the following are stack operations? Sort Enqueue Pop None of these. Dequeue Push

It measures in the worst case. It measures the space/time complexity of an algorithm. Is used to compare algorithms that address the same operation.

Which of the following are true of Big-Oh notation. Answer, It measures in terms of n and cares about small values of n. It measures in the worst case. It measures the space/time complexity of an algorithm. Is used to compare algorithms that address the same operation. Is used to compare algorithms that solve different problems. Measures how many seconds it will take to solve a problem.

Fixed Size Can be ordered. Can be used to implement a queue. Can be used to implement a stack. Random Access Contiguously Allocated (One single block of memory)

Which of the following is/are true for arrays? Fixed Size Can be ordered. Random Access Can be used to implement a queue. Can be used to implement a stack. Grows Easily Dynamic Size Contiguously Allocated (One single block of memory)

Can be ordered. Can be used to implement a stack. Can be used to implement a queue. Dynamic Size

Which of the following is/are true for linked lists? Fixed Size Contiguously Allocated (One single block of memory) Can be ordered. Can be used to implement a stack. Random Access Grows Easily Can be used to implement a queue. Dynamic Size

int* x = &i; int* x; int* x = 0;

Which of the following lines will create a pointer variable? Assume referenced code elements exist if necessary. int x = 0; int* x = &i; int* x; None of these. int x; int* x = 0;

Bubble

Which of the following sorts will swap the most times in the worst case? Merge Bubble Selection Insertion Impossible to tell. Quick

Its Big-Oh is O(lg n) The array needs to be sorted.

Which of the following statements are true for an array based binary search? Its Big-Oh is O(lg n) The array needs to be sorted. It's like a linear search and starts at the first element of the array. Its Big-Oh is O(n) Best case, worst case, and average case are the same complexity.

Is less vulnerable to clustering that linear or quadratic probing (Produces a second index in the array is partially correct)

Which of the following statements is true about Double Hashing? Produces a second index in the array Hashing of the Hash Value Is less vulnerable to clustering that linear or quadratic probing Produces a second index in the array Prevents collisions by keeping two tables Avoids collisions by computing a Hash Value that's a double instead of a int

Could result in a stack overflow exception for a poorly written base case. A function is recursive if there is a call to itself in the function body. A function can be recursive, even if there isn't a call to itself in the function body, when the first function calls another function, who in turn calls the first function. Requires a base case to stop recursive calls from being made.

Which of the following statements pertain to recursive functions? Could result in a stack overflow exception for a poorly written base case. A function is recursive if there is a call to itself in the function body. An algorithm that can be solved with a loop, should be rewritten as a recursive function to leverage stack state. Every function is recursive by nature. A function can be recursive, even if there isn't a call to itself in the function body, when the first function calls another function, who in turn calls the first function. Requires a base case to stop recursive calls from being made.

(key % 10) - (key / 10)

Which of these Hash Functions yields a perfect hash with a 10 element array for the following values? (Remember to use integer math) 6, 31, 51, 54 key % 10 key / 10 (key % 10) + (key / 10) (key % 10) - (key / 10) None of these

key / 10

Which of these Hash Functions yields a perfect hash with a 10 element array for the following values? (Remember to use integer math) 6, 33, 77, 96 key % 10 key / 10 (key % 10) + (key / 10) (key % 10) - (key / 10) None of these

Insertion

Which sort algorithm is the following code implementing? int out, car, key; for(car = 1; car < n; car++) { key = array[car]; for(out = car - 1; (out >= 0) && (array[out] > key); out--) { array[out+1] = array[out]; } array[out+1] = key; }

Max Heap Min Heap

Which trees are array based for standard implementation? Max Heap Min Heap AVL Tree Binary Search Tree None Listed


Ensembles d'études connexes

English File Advanced Vocabulary : Money

View Set

Resistance and the Abolition Movement

View Set

PN 131 Comprehensive Final NCLEX Practice

View Set