data structures final

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

Suppose that a selectionsort of 100 items has completed 42 iterations of the main loop. How many items are now guaranteed to be in their final spot (never to be moved again)?

42

Suppose that a non-leaf node in a B-tree has 41 entries. How many children will this node have?

42 number of subtrees below a non leaf node with n entries is always n+1

Can you have an empty binary tree? T or F

True

A chained hash table has an array size of 512. what is the maximum number of entries that can be placed in a table?

no max

In a single function declaration, what is the maximum number of statements that may be recursive calls?

no max

What is the maximum depth of recursive calls a function may make?

no max

Consider the following function: void super_write_vertical(int number) // Postcondition: The digits of the number have been written, // stacked vertically. If number is negative, then a negative // sign appears on top. // Library facilities used: iostream.h, math.h { if (number < 0) { cout << '-' << endl; super_write_vertical(abs(number)); } else if (number < 10) cout << number << endl; else { super_write_vertical(number/10); cout << number % 10 << endl; } } Which call will result in the most recursive calls?

**super_write_vertical(-1023)** super_write_vertical(0) (incorrect) super_write_vertical(100) (incorrect) super_write_vertical(1023) (incorrect)

Suppose you run a O(log n) algorithm with an input size of 1000 and the algorithm requires 110 operations. When you double the input size to 2000, the algorithm now requires 120 operations. What is your best guess for the number of operations required when you again double the input size to 4000?

130

Suppose we are sorting an array of eight integers using heapsort, and we have just finished one of the reheapifications downward. The array now looks like this: 6 4 5 1 2 7 8 How many reheapifications downward have been performed so far?

2

There is a tree in the box at the top of this section. How many children does the root have? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40

2, The children of the root node (14) are 2 and 11. So, the number of children of the root node (14) are 2.

Suppose T is a binary tree with 14 nodes. What is the minimum possible depth of T?

3 levels of depth

There is a tree in the box at the top of this section. What is the depth of the tree? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40

3, DEPTH = LEVELS The depth of a tree refers to the maximum number of levels between the root and the deepest leaf.

There is a tree in the box at the top of this section. How many leaves does it have? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40

4 Nodes with no children are called leaves, or external nodes. Nodes which are not leaves are called internal nodes. Nodes with the same parent are called siblings.

Consider the following function: void test_a(int n) { cout << n << " "; if (n>0) test_a(n-2); } What is printed by the call test_a(4)?

4 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? 20 40 200 400

400

Consider this binary search tree: 14 / \ 2 16 / \ 1 5 / 4 Suppose we remove the root, replacing it with something from the left subtree. What will be the new root?

5 Max value from the left sub tree will be the root. node 14 has two children. After deleting the node 14 we can replace the root element by inorder successor of Predecessor of that node. so, from the given tree either 5 or 16 will be the next root node. Node 16 will be from right sub tree, so 5 will be the correct answer which is from left sub tree.

how many B-tree rules are there?

6

There is a tree in the box at the top of this section. How many of the nodes have at least one sibling? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40

6 Nodes with the same parent are called siblings. Nodes with no children are called leaves, or external nodes. Nodes which are not leaves are called internal nodes.

Consider this function declaration: void quiz(int i) { if (i > 1) { quiz(i / 2); quiz(i / 2); } cout << "*"; } How many asterisks are printed by the function call quiz(5)?

7

There is a tree in the box at the top of this section. How many descendants does the root have? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40

8 A descendant node of a node is any node in the path from that node to the leaf node (including the leaf node). The immediate descendant of a node is the "child" node. An ancestor node of a node is any node in the path from that node to the root node (including the root node). The immediate ancestor of a node is the "parent" node. If node A is an ancestor of node B then node B is a descendant of node A.

What is the minimum number of nodes in a complete binary tree with depth of 3? 3 4 8 11 15

8, the depth of a complete binary tree is d then the number of nodes are 2^d.

When a function call is executed, which information is not saved in the activation record?

Current depth of recursion is not saved in the activation record, when ever a function call is executed.

If G is an directed graph with 30 vertices, how many boolean values will be needed to represent G using an adjacency matrix? 30 900 300 600

900, Adjacency Matrix is a 2D array of size n x n where n is the number of vertices in a graph. Every row represents the edge from that element row to the column name. If it is 1 at A[1][3] means there is an edge originating from 1 and ending at 3 means directed from 1 tom 3. If 0 is there means no edge present. Now, if we have to represent the directed grapg we will need n*n places meaning n*n 2D matrix. 900 for 30 vertices.

Whats a compete binary tree?

A complete binary tree is a binary treein which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

what is a full binary tree?

A full binary tree (sometimes proper binary tree or 2-tree) is a tree in which every node other than the leaves has two children.

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 shortest-path algorithm.

A shortest-path algorithm. a shortest-path algorithm is used to find the best sequence of connections from one city to another.

How are loops represented in an edge-list representation of a graph?

A vertex will be on its Own Edge - List The loops are represented in an edge-list representation of the graph with the Help of the Vertex hat will be on its own edge

Which statement is true for a B-tree? All entries of a node are greater than or equal to the entries in the node's children. All leaves are at the exact same depth. All nodes contain the exact same number of entres. All non-leaf nodes have the exact same number of children.

All leaves are at the exact same depth.

Suppose that X is a B-tree leaf containing 41 entries and having at least one sibling. Which statement is true? Any sibling of X is also a leaf. Any sibling of X contains at least 41 entries. The parent of X has exactly 42 entries. X has at least 41 siblings.

Any sibling of X is also a leaf.

Selectionsort and quicksort both fall into the same category of sorting algorithms. What is their category?

Average time is quadratic

Select the true statement about the worst-case time for operations on heaps. Niether insertion nor removal is better than linear. Insertion is better than linear, but removal is not. Removal is better than linear, but insertion is not. Both insertion and removal are better than linear.

Both insertion and removal are better than linear

depth first search vs breadth first search

Breadth First Search is generally the best approach when the depth of the tree can vary, and you only need to search part of the tree for a solution. For example, finding the shortest path from a starting value to a final value is a good place to use BFS. Depth First Search is commonly used when you need to search the entire tree. It's easier to implement (using recursion) than BFS, and requires less state: While BFS requires you store the entire 'frontier', DFS only requires you store the list of parent nodes of the current element.

What graph traversal algorithm uses a queue to keep track of vertices which need to be processed?

Breadth-Frist Search

What is a chained hash table?

Chaining is a technique used for avoiding collisions in hash tables. In the chaining approach, the hash table is an array of linked lists i.e., each index has its own linked list. All key-value pairs mapping to the same index will be stored in the linked list of that index.

Mergesort makes two recursive calls. Which statement is true after these recursive calls finish, but before the merge step? The array elements form a heap. Elements in each half of the array are sorted amongst themselves. None of the above.

Elements in each half of the array are sorted amongst themselves.

Select the one FALSE statement about binary trees Every binary tree has at least one node. Every non-empty tree has exactly one root node. Every node has at most two children. Every non-root node has exactly one parent.

Every binary tree has at least one node.

Select the one true statement. Every binary tree is either complete or full. Every complete binary tree is also a full binary tree. Every full binary tree is also a complete binary tree. No binary tree is both complete and full.

Every full binary tree is also a complete binary tree.

What is a priority queue

Every item has a priority associated with it. An element with high priority is dequeued before an element with low priority. If two elements have the same priority, they are served according to their order in the queue.

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

Graph vertices may be linked in any manner. A graph with no vertices is just empty but not non-existent

What feature of heaps allows them to be efficiently implemented using a partially filled array?

Heaps are complete binary trees.

What feature of heaps allows them to be efficiently implemented using a partially filled array? Heaps are binary search trees. Heaps are complete binary trees. Heaps are full binary trees.

Heaps are complete binary trees. In a complete binary tree the nodes are completely filled at all levels except possibly the last one. If there are remaining edges at the last level, then they are oriented on the left side of the tree. The left node of a node with index i has a index of 2*i whereas , the right node has index of 2*i + 1. All the elements can be stored using this property in an array, without having any unoccupied space between two elements.

what is the worst-case time for serial search (linear search, synomamous) finding of a single item in an array?

Linear Time

What is the worst-case time for binary search finding a single item in an array?

Logarithmic Time (O(log n)) binary search its assuming the list is already sorted and makes comparisons till its got

A chained hash table has an array size of 512. What is the maximum number of entries that can be placed in the table?

No max

A simple graph has no loops. What other property must a simple graph have?

No multiple edges its just part of the definition. no loops or parallel lines.

What is the worst-case time for heapsort to sort an array of n elements?

O(n log(n))

What is the worst-case time for mergesort to sort an array of n elements?

O(n log(n))

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? (Assume n vertices are in the graph and m edges terminate at the desired node.)

O(n)

This question is appropriate if you studied a flood fill (which was not part of the text). Suppose that a flood fill starts at the point marked with an o in this diagram: XXXXXXXXXX XX XXXX This is row num1 XX XX XXXX This is row num2 XX oXXX This is row num3 XXXXXXXXXX Suppose that the first recursive call is always left; the second recursive call is always right; the third recursive call is always up; the fourth recursive call is always down. How will the rows be completely filled?

Row 1 is filled first, then row 2, then row 3

Suppose we are sorting an array of eight integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: 2 4 5 7 8 1 3 6 Which statement is correct? (Note: Our selectionsort picks largest items first.) The algorithm might be either selectionsort or insertionsort. The algorithm might be selectionsort, but it is not insertionsort. The algorithm is not selectionsort, but it might be insertionsort. The algorithm is neither selectionsort nor insertionsort.

The algorithm is not selectionsort, but it might be insertionsort. Reason : If selection sort then 1 value be must at first position.

Suppose we are sorting an array of ten integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: 1 2 3 4 5 0 6 7 8 9 Which statement is correct? (Note: Our selectionsort picks largest items first.) The algorithm might be either selectionsort or insertionsort. The algorithm might be selectionsort, but could not be insertionsort. The algorithm might be insertionsort, but could not be selectionsort. The algorithm is neither selectionsort nor insertionsort.

The algorithm might be either selectionsort or insertionsort.

When is insertionsort a good choice for sorting an array?

The array has only a few items out of place.

what additional requirement is placed on an array, so that binary search may be used to locate an entry?

The array must be sorted because binary is just half chops of the array.

Tree algorithms typically run in time O(d) . What is d? The depth of the tree. The number of divisions at each level. The number of entries in each node. The number of nodes in the tree. The total number of entries in all the nodes of the tree.

The depth of the tree.

Suppose that a B-tree has MAXIMUM of 10 and that a node already contains the integers 1 through 10. If a new value, 11, is added to this node, the node will split into two pieces. What values will be in these two pieces? The first piece will have only 1 and the second piece will have the rest of the numbers. The first piece will have 1 through 5 and the second piece will have 6 through 11. The first piece will have 1 through 5 and the second piece will have 7 through 11. The first piece will have 1 through 6 and the second piece will have 7 through 11. The first piece will have 1 through 10 and the second piece will have only 11.

The first piece will have 1 through 5 and the second piece will have 7 through 11. 6 is at the root

What is flood filling?

The flood-fill algorithm takes three parameters: a start node, a target color, and a replacement color. The algorithm looks for all nodes in the array that are connected to the start node by a path of the target color and changes them to the replacement color.

14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40 Consider the binary tree in the box at the top of this section. Which statement is correct? The tree is neither complete nor full. The tree is complete but not full. The tree is full but not complete. The tree is both full and complete.

The given binary tree is complete, but it is not full. A binary tree is said to be full binary tree if each node of the tree is either the leaf node or possess exactly two child nodes. A binary tree is said to be a complete binary tree if all the levels, except the last level are full completely and the last level has the nodes on the left side. In the given tree, each node (except the leaf nodes) does not possess two children but all levels are completely full except the last level.

what kind of initialization needs to be done for a chained hash table?

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. or The head pointer of each chain must be set to NULL.

The key at each array location must be initialized.

what kind of initialization needs to be done for an open-address hash table

The key at each array location must be initialized.

Suppose that we have implemented a priority queue by storing the items in a heap. We are now executing a reheapification downward and the out-of-place node has priority of 42. The node's parent has a priority of 72, the left child has priority 52 and the node's right child has priority 62. Which statement best describes the status of the reheapification.? The reheapification is done. The next step will interchange the two children of the out-of-place node. The next step will swap the out-of-place node with its parent. The next step will swap the out-of-place node with its left child. The next step will swap the out-of-place node with its right child.

The reheapification is done. The next step will swap the out-of-place with its right child

In a real computer, what will happen if you make a recursive call without making the problem smaller?

The run-time stack overflows, halting the program

When the compiler compiles your program, how is a recursive call treated differently than a non-recursive function call?

There is no difference between a recursive call and non-recursive call except for the fact that if the stack size is limited and recursion occurs above that limit, the recursion would fail somehow, There is no issue about the primitive values and reference values in the difference between them. There is no issue about turning a reference variable to primitive value or primitive to reference. Local variables are created using a specific data structure called the "stack frame". Each recursion creates its own new stack frame which does not interfere with the older recursion stack frame. Hence, the local variables would not interfere in any form. That is not something based on which a recursive method differs from a non-recursive method because the stack frame is created exactly the same way in both type of methods. The only really interesting difference is that the recursion looks simpler in code, it offers a substitute for a loop by several self-calls. NONE OF THE BELOW ARE CORRECT: Parameters are all treated as reference arguments Parameters are all treated as value arguments There is no duplication of local variables

heaps are complete binary trees True or False?

True

if reheapification is downwards we ignore the root True or false?

True

What is the best definition of a collision in a hash table?

Two entries with different keys have the same exact hash value. If there is any collision(i.e. two different elements have same hash value) then store both the elements in the same linked list.

what is max heap

Where the value of the root node is greater than or equal to either of its children.

what is min heap?

Where the value of the root node is less than or equal to either of its children.

what index do roots get to in heaps?

[0]

If a heap is implemented using a partially filled array called data, and the array contains n elements (n > 0), where is the entry with the greatest value?

data[0] if a heap is implemented using a partially filled array called data, and the array contains n elements (n > 0), then the entry with the greatest value is data[0] .

a heap is implemented using a partially filled array called data, and the array contains n elements (n > 0), where is the entry with the greatest value? data[0] data[n-1] data[n]

data[0] if a heap is implemented using a partially filled array called data, and the array contains n elements (n > 0), then the entry with the greatest value is

What is the best definition of a collision in a hash table?

different keys same hash

two binary tree rules

entry must be bigger than all children. tree is a complete binary

space complexity is what?

how much memory

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

is_present

Which formula is the best approximation for the depth of a heap with n nodes? log (base 2) of n The number of digits in n (base 10) The square root of n n The square of n

log(base 2) of n

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

m / s

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

n

In a select sort of n elements, how many times is the swap function called in the complete execution of the algorithm?

n-1 because last one doesn't need to be swapped

Consider the following function: void super_write_vertical(int number) // Postcondition: The digits of the number have been written, // stacked vertically. If number is negative, then a negative // sign appears on top. // Library facilities used: iostream.h, math.h { if (number < 0) { cout << '-' << endl; super_write_vertical(abs(number)); } else if (number < 10) cout << number << endl; else { super_write_vertical(number/10); cout << number % 10 << endl; } } What values of number are directly handled by the stopping case?

number < 10

time complexity is what?

runtime

what is selection sort?

selection sort is an in-place comparison sorting algorithm. It has an O(n2) time complexity, which makes it inefficient on large lists, and generally performs worse than the similar insertion sort.

depth first search is stack or queue?

stack


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

ch16: life cycle nutrition: infancy, childhood, and adolescence

View Set

CPH Exam- a mixture of everything

View Set

Arizona Laws and Rules Pertinent to Insurance chapter 18

View Set

ECONS200 Waikato Short Answer June 2019

View Set

Section A: Introduction to Supply Chain

View Set

Ch 3 - Vectors and two dimensional motion

View Set