COP3530 Final Exam (Chapters 10,12,13)

Ace your homework & exams now with Quizwiz!

In hash tables, as the ________ increases more collisions are likely and the performance degrades.

load factor

A heap organizes list elements in such a way that insertions and removal of the largest (or smallest) element can be done in O(______) time.

log n

In the worst case, binary search requires O(_____) time on a sorted array with n elements.

log n

The Big O time analysis of Binary Search algorithm-array/vector is O(______)

log n

The computational complexity of a balanced binary tree is O(___).

log n

In most current applications, which is most important?

time

What two criteria are usually used to measure an algorithm's efficiency?

time and space

If you do separate chaining, whats the time to access the info now?

time to hash + get spot in linked list

A(n) _____ consists of nodes (or vertices) and directed arcs that connect pairs of nodes.

tree (or directed graph)

Is this binary tree balanced? _________(A) _______/_____ \ ______(B)____ (C) ______/ \______/ \ ___(D) (E)__(F) (G) ____/ __(H)

yes

_______15 _____/____\ ____3____25 ___/ \___/ __1__8__23 If you added a right child, 30, to node 25, would this tree be perfect, full, and complete?

yes

_______15 _____/____\ ____3____25 ___/ \___/ __1__8__23 Is this tree a complete binary tree?

yes

Is this a balanced tree? ____4 ___/ \ __5__8 _____/ ____1

yes Explanation: A balanced binary tree, also referred to as a height-balanced binary tree, is defined as a binary tree in which the height of the left and right subtree of any node differ by not more than 1.

A tree with only a single node (hence both a root and leaf) has depth and height ______.

zero

The root node and the leaf nodes have depth ______.

zero

Search in an unbalanced tree always has O(log n) complexity.

false

Selection sort is stable (T/F)

false

Use standard algorithms to implement operations instead of reinventing the wheel.

true

For small lists, linear insertion sort performs well.

true best case is O(n)

Is a load factor of 0 possible?

yes

What is the computational complexity of building a heap in place in the worst case? O(log n), O(n), O(n^2), O(n log n), or O(1)

O(n)

Name and describe the two parts of a recursive definition of a function.

(1) An anchor or base case that specifies the value of the function for one or more values of the parameter(s). (2) An inductive or recursive step that defines the function's value for the current value of the parameter(s) in terms of previously defined function values and/or parameter values.

Draw the BST that results when the C++ keywords are inserted in the order given: do, case, for, if, switch, while, goto

...

Draw the BST that results when the C++ keywords are inserted in the order given: if, do, goto, case, switch, while, for

...

Draw the BST that results when the C++ keywords are inserted in the order given: while, switch, goto, for, if, do, case

...

Show the BST that results when the node containing 20 is deleted from the given BST. .......................80 ................./............\ ...........30.................90 ........../ \.....................\ .....20......60..................100 ...../........./ \ 10........50....70 ........../ .....40

.......................80 ................./............\ ...........30.................90 ........../ \.....................\ .....10......60..................100 ................/ \ ...........50....70 ........../ .....40

Show the BST that results when the node containing 30 is deleted from the given BST. .......................80 ................./............\ ...........30.................90 ........../ \.....................\ .....20......60..................100 ...../........./ \ 10........50....70 ........../ .....40

.......................80 ................./............\ ...........40.................90 ........../ \.....................\ .....20......60..................100 ...../........./ \ 10........50....70

Show the BST that results when the root is deleted from the given BST. .......................80 ................./............\ ...........30.................90 ........../ \.....................\ .....20......60..................100 ...../........./ \ 10........50....70 ........../ .....40

.......................90 ................./............\ ...........30................100 ........../ \ .....20......60 ...../........./ \ 10........50....70 ........../ .....40

For the function, find f (0). int f(int n) { if (n == 0) return 0; else return n + f(n - 1); }

0

For the function, suppose + is changed to * in the inductive case. Find f(5). int f(int n) { if (n == 0) return 0; else return n + f(n - 1); }

0

Assume a hash table with 7 locations and the hashing function h(i) = i % 7. Show the hash table that results when the integers are inserted in the order given. 5,11,18,23,28, 13,25, with collisions resolved using chaining..

0 -> 28..................... 1................................. 2 -> 23.................... 3................................ 4 -> 25 -> 18 -> 11 5 -> 5...................... 6 -> 13....................

Assume a hash table with 7 locations and the hashing function h(i) = i % 7. Show the hash table that results when the integers are inserted in the order given. 5,11,18,23,28, 13,25, with collisions resolved using linear probing.

0 28 1 13 2 23 3 25 4 11 5 5 6 18

Assume a hash table with 7 locations and the hashing function h(i) = i % 7. Show the hash table that results when the integers are inserted in the order given. 5,11,18,23,28, 13,25, with collisions resolved using quadratic probing.

0 28 1 25 2 23 3 18 4 11 5 5 6 13

We are given a set of n distinct elements and an unlabelled binary tree with n nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree? (GATE CS 2011)

1

Bubble Sort is performed on an array with values [6, 1, 2, 0, 5, 4]. What are the array values after two passes of the Bubble Sort? The largest value in the array is moved to the correct location after each pass.

1, 0, 2, 4, 5, 6

Level of root is ____ and levels of left and right children of root is ____.

1, 2

[0]auk, [1]bat, [2]cow, [3]eel, [4]elk, [5]fox, [6]gnu, [7]pig, [8]rat Give the indices of the elements of critter in the order that the components are examined during a binary search for... 1. gnu 2. eel 3. fly 4. ant 5. yak

1. 4, 6 2. 4, 1, 2, 3 3. 4, 6, 5 4. 4, 1, 0 5. 4, 6, 7, 8

What is the computational complexity of finding an element in a linked list in the worst case? O(log n), O(nlogn), O(n), O(n!), or O(1)

O(n)

Which node is the root? 10 / \ 20. 30 \ \ 40. 50 / \ 60. 70

10

what is node 9s in order successor? __________6 ________/____\ _______4_______9 ______/________/__\ _____2________8___11 ___/__\_____/_____/ __1____3___7____10

10

Show the array used to represent this binary tree. .........10 ......./.....\ ...20........30 ......\ ..........\ .......40........50 ..................../ \ .................60..70

10,20,30, ,40, ,50, , ,60,70,...

Perform an inorder traversal of this BST. _________80 ______/ ______\ ____30_______90 ____/ \_________ \ __20__60_______100 _/_____/ \ 10___ 50_70 ______/ _____40

10,20,30,40,50,60,70,80,90,100

Perform an postorder traversal of this BST. .......................80 ................./............\ ...........30.................90 ........../ \.....................\ .....20......60..................100 ...../........./ \ 10........50....70 ........../ .....40

10,20,40,50,70,60,30,100,90,80

What does the following function print for n = 25? void fun(int n) { if (n == 0) return; cout << n%2; fun(n/2); }

10011

Consider the following recursive function fun(x, y). What is the value of fun(4, 3) int fun(int x, int y) { if (x == 0) return y; return fun(x - 1, x + y); }

13

For the following recursive function, find f(5): int f(int n) { if (n == 0) return 0; else return n + f(n - 1); }

15

The array representation of the heap is ? _________15 _______/____ \ _____20_____30 _____/ \ _____/ \ ___21__40 32__31 __/ 35

15 20 30 21 40 32 31 35

The array representation of the heap is ? 15 / \ 20 30 / \ / \ 21 40 32 31 / 35

15,20,30,21,40,32,31,35

Predict the output of following program: int fun(int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { cout << fun(2); return 0; }

16

No node in a binary tree has more than ____ children

2

What is the worst case time complexity for search, insert and delete operations in a general Binary Search Tree?

O(n)

The array representation of the heap after 2 deletions is ? _________15 _______/____ \ _____20_____30 _____/ \ _____/ \ ___21__40 32__31 __/ 35

21 31 30 35 40 32 since this is a min heap (minimum is at root). Choose last element in heap/array and swap it with the root and then heapifydown by choosing the smaller element

Find the height of the tree. 10 / \ 20. 30 \ \ 40. 50 / \ 60. 70

3

Find the height of the tree. _________(A) _______/_____ \ ______(B)____ (C) ______/ \______/ \ ___(D) (E)__(F) (G) ____/ __(H)

3

What's the ouptut? set <int> s1; s1.insert(5); s1.insert(2); s1.insert(4); s1.insert(11); s1.insert(2); s1.erase(2); cout << s1.size();

3

........40.............. ...../......\............ ..30.........70...... ............./.....\..... ..........65.....80.. .......................\... .......................90 What node is unbalanced in this AVL tree?

40

........1................ ...../......\............ ..0..........5......... ............./.....\..... ...........3........6... What will be the level order traversal of the AVL tree after we delete "1"?

5 0 6 3 or 3 0 5 6

................5.............. ......../.............\............ ......20..............10...... ...../...\........../.....\..... ..23..40.....22.....21.. ../........................... 25...................... The array representation of this heap is?

5 20 10 23 40 22 21 25

List all the leaves. _________10 ______/ _____\ ____20________30 ___/____________\ __40____________50 _/ \ 60 70

50,60,70

The array representation of the heap after 6 is inserted is ? _________15 _______/____ \ _____20_____30 _____/ \ _____/ \ ___21__40 32__31 __/ 35

6 15 30 20 40 32 31 35 21

While inserting the elements 71, 65, 84, 69, 67, 83 in an empty binary search tree (BST) in the sequence shown, the element in the lowest level is______

67

Perform an preorder traversal of this BST. ..................80 ............/...........\ ........30..............90 ......../ \................ \ .....20...60..............100 ...../...... / \ ...10....50...70 ........./ .......40

80,30,20,10,60,50,40,70,90,100

State the level-order traversal of the BST after inserting the following 91 97 64 17 16 47 24 87 93 63

91 64 97 17 87 93 16 47 24 63

A program that uses the STL algorithms must contain the directive #include _____.

<algorithm>

The library ___ contains algorithms designed for processing sequences of numbers.

<numeric>

Describe the divide-and-conquer approach to problem solving.

A problem is repeatedly partitioned into simpler subproblems, each of which can be considered independently, continuing until subproblems are obtained that are sufficiently simple that they can be solved (i.e., conquered).

Which of the following situations would benefit from a hash table? A program who's main purpose is to lookup student grades and print out ordered list. A table used for looking up memory addresses. A program who's main purpose is to store and lookup student grades. A program who's main purpose is to solve mathematical equations.

A table used for looking up memory addresses. A program who's main purpose is to store and lookup student grades.

Show the array used to represent this binary tree. _________(A) _______/_____ \ ______(B)____ (C) ______/ \______/ \ ___(D) (E)__(F) (G) ____/ __(H)

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

What is a complete tree?

All levels are filled except possibly the bottom, for which the nodes are in the leftmost positions.

Simple selection sort performs better for partially sorted lists than for random lists. (True or false)

false

Fill in the missing line: _______ MAXIMUM(T) { if (n.right == NULL) return n; else return __________ ; }

Node * , MAXIMUM(n.right)

What search algorithm provides the best worst-case performance? Linear Search or Binary Search

Binary Search

Swaps neighboring items

Bubble Sort

Like QuickSort, Merge Sort is a ____________algorithm.

Divide and Conquer

________ is a problem-solving approach that divides the original problem into simpler subproblems, perhaps repeatedly, until subproblems are obtained that are sufficiently simple that they can be solved.

Divide-and-conquer

The Binary Tree array implementation is space efficient for incomplete trees.

false

_________ sorts systematically interchange pairs of elements that are out of order until no such pairs remain and the list is sorted.

Exchange

Describe dual hashing?

Find the location i == h1(x) of an item x in the hash table with a first hash function h1. If a collision occurs, compute an increment k == h2(x) using a second hash function h2, and then examine the locations i + k, i + 2k, i + 3k, .... , with all operations done modulo the table size, continuing until an empty slot is found where the item can be stored.

What are properties of a good hash function?

Given an input, it produces the same output every time. Runs in constant time. Evenly distributes values across the table.

List all the leaves. _________(A) _______/_____ \ ______(B)____ (C) ______/ \______/ \ ___(D) (E)__(F) (G) ____/ __(H)

H, E, F, G

What is quadratic probing?

If a collision occurs at index i, examine the locations i + 1^2, i - 1^2, i + 2^2, i - 2^2, i + 3^2, i-3^2 ... with all operations done modulo the table size, continuing until an empty slot is found where the item can be stored.

______ recursion occurs when a function calls other functions, and some chain of function calls eventually results in a call to the first function.

Indirect

_______ sorts repeatedly insert a new element into a list of already sorted elements so that the resulting list is still sorted.

Insertion

What are some reasons a sorting method may not be appropriate for files?

It requires direct access to the list elements. It may make many passes through the list.

What is common in three different types of traversals (Inorder, Preorder and Postorder)?

Left subtree is always visited before right subtree

The worst- and average-case computing times for binary search is:

O (log n)

Describe how selection sorts work.

Make a number of passes through the list or a part of the list, and on each pass, select one element to be correctly positioned.

Splits the array into halves and sorts each half

Merge Sort

In the linked list implementation of binary trees, a leaf node have both pointers (left and right) set to _________.

NULL

_______15 _____/____\ ____3____25 ___/ \___/ __1__8__23 Is this tree full?

No, because 25 only has one child

Is this binary tree complete? If not, explain why it isn't. ..........10 ......./.....\ ...20........30 ......\ ..........\ .......40........50 ......./ \ ....60..70

No, the third level is not full

Is this binary tree balanced? If not, explain why it isn't. ............10 ........./....\ ....20........30 ........\............ \ ..........40...........50 ........./ \ ....60.....70

No. For node 20, the left subtree has height 0, but the right subtree has height 2.

What is the time complexity of this recursive function? double power(double x, unsigned n) { if (n == 0) { return 1.0; } else if (n % 2 == 0) { return power(x*x, n/2); } else { return x * power(x*x, (n-1)/2); } }

O (log n) ---- logarithmic

What is the computational complexity of adding an item to a stack using a linked list implementation in worst case? O(log n), O(nlogn), O(n), O(n!), or O(1)

O(1)

What is the computational complexity of removing an item from a stack in the worst case? O(log n), O(nlogn), O(n), O(n!), or O(1)

O(1)

for (int i=0; i<10; i++) for (int j=0; j<i; j++) whats the complexity?

O(1)

in the std template library, whats the complexity of performing all hash table (unordered_map) function (insert, delete, search, etc)?

O(1)

What is the time complexity of this recursive function? unsigned fib(unsigned n) { if (n <= 2) { return 1; } return fib(n - 1) + fib(n - 2); }

O(2^n) ---- exponential

What is the best case time complexity of insertion sort and bubble sort?

O(N)

The worst case running time to search for an element in a balanced binary search tree with n2^n elements is _______

O(log n)

What is the computational complexity of inserting an item into a heap worst case? O(log n), O(n), O(n^2), O(n log n), or O(1)

O(log n)

What is the computational complexity of inserting an item into a heap worst case? O(log n), O(n), O(n^2), O(n log n), or O(1)

O(log n)

Which of the orders of magnitude is the best O notation to use to express the worst-case computing time as a function of n. while (n >= 1) n /= 2;

O(log n)

int x=1 while (x<n) x*=2 whats the complexity?

O(log n)

The computing time for searching and inserting into a balanced binary search tree is ______ . As BSTs become increasingly unbalanced, their performance deteriorates. In the worst case, the BST degenerates into a linked list and the complexity of these operations becomes _____. Rebalancing methods are required to keep this from happening.

O(log n), O(n)

What is the computational complexity of sorting an array of items using merge sort in the best case? O(log n), O(n), O(n^2), O(n log n), or O(1)

O(n log n)

The computational complexity of a linear search if the items are in order. (worst case)

O(n)

The worst- and average-case computing times for linear search is:

O(n)

What is the computational complexity of adding an item to a BST in worst case? O(log n), O(nlogn), O(n), O(n!), or O(1)

O(n)

What is the computational complexity of an in-order tree traversal in the average case? O(log n), O(nlogn), O(n), O(n!), or O(1)

O(n)

What is the computational complexity of building a heap in place in the worst case? O(log n), O(n), O(n^2), O(n log n), or O(1)

O(n)

Which of the orders of magnitude is the best O notation to use to express the worst-case computing time as a function of n. n = 0; sum = 0; cin >> x; while (x !== -999) { n++; sum +== x; cin >> x; }

O(n)

What is the computational complexity of adding an item to a BST in worst case?

O(n) Explanation: If you have a "pure" binary search tree that doesn't do any balancing, then the worst-case runtime for inserting an element is O(n). This happens if you have a degenerate binary search tree (one where each node has exactly one child) and the element you end up inserting ends up as a child of the deepest node.

What is the computational complexity of sorting an array of items using insertion sort in the best case? O(log n), O(n), O(n^2), O(n log n), or O(1)

O(n) - when already sorted

What is the time complexity of this recursive function? double power(double x, unsigned n) { if (x == 0) return 1; else return x * power(x, n - 1); }

O(n) ---- linear

for (int i=0; i<n; i++) for (int j=1; j<m; j*=2) whats the complexity?

O(n+logm)

Which of the orders of magnitude is the best O notation to use to express the worst-case computing time as a function of n. for (int i 0; i < n - 1; i++) { for (int j = 0; j < n - 1; j++) if (x[j] > x[j + 1]) { temp = x[j]; x [j] = x[j + 1]; x[j + 1] = temp; } }

O(n^2)

Which of the orders of magnitude is the best O notation to use to express the worst-case computing time as a function of n. for (int i == 0; i < n; i++) for (int j = 0; j < n; j++) c [i][j] == a [i][j] + b[i][j] ;

O(n^2)

for (int i=0; i<n; i++) for (int j=0; j<i; j++) whats the complexity?

O(n^2)

when you have a bad pivot whats the time complexity for quick sort?

O(n^2)

What is the computational complexity of sorting an array of numbers using selection sort in the worst case?

O(n^2) (quadratic)

Which of the orders of magnitude is the best O notation to use to express the worst-case computing time as a function of n. for (int i 0; i < n; i++) for (int j == 0; j < n; j++) { c[i][j] == 0; for (int k = 0; k < n; k++) c[i][j] += a[i][k] * b[k][j]; }

O(n^3)

_____ and ____ are common collision-resolution strategies.

Open addressing, chaining

Describe how exchange sorts work.

Systematically interchange pairs of elements that are out of order until eventually no such pairs remain and the list is therefore sorted.

Partitions the array around a pivot

Quick Sort

Describe how insertion sorts work.

Repeatedly insert a new element into a list of already sorted elements so that the resulting list is still sorted.

What is linear probing?

Searching sequentially for the next open slot. If a collision occurs at index i, examine the locations i + 1, i + 2, i + 3, .... with all operations done modulo the table size, continuing until an empty slot is found where the item can be stored.

Describe how quicksort uses a divide-and-conquer sorting strategy.

Select an element, called a pivot, and then perform a sequence of exchanges so that al1 elements that are less than or equal to this pivot are to its left and al1 elements that are greater than the pivot are to its right. This correctly positions the pivot and divides the (sub)list into two smaller sublists, each of which may then be sorted independently in the same way.

________ sorts make a number of passes through a list or part of a list and, on each pass, select one element to be correctly positioned.

Selection

Finds smallest element and puts in lowest index, then puts second smallest in the second index, and so on

Selection Sort

Describe how items must be stored in a priority queue.

So that those with higher priority are removed before those of lower priority.

Why is mergesort so named?

The basic operation involved is merging: combining two lists that have previously been sorted so that the resulting list is also sorted.

What is the heap-order property?

The data item stored in each node is greater than or equal to the data item stored in each of its children.

Define what it means to write T(n) is O(f(n)).

There is some constant C such that T(n) <=C . f(n) for all sufficiently large values of n.

Given two functions T1 = n^2 + n + log2n T2= n^2*log3n (T/F) The function T1 will take less time to execute than T2 for same inputs to both functions for large inputs (T/F) The order of growth of T1 is lesser than the order of growth of T2

True True

Using the first list element as pivot works well for partially-sorted lists. (True or false)

false

If the hash function, f(x) = x % table_size, and table_size is 20, when will the table size be increased for the 1st time if we have implemented open addressing? Max Load factor is 0.75

When the number of items in the table is 15

a good hash function does what

evenly distributes data, be easy to compute, gets same index each time

Whenever a function begins execution, an ________ is created to store the current environment for that function.

activation record

Linear search is used by find() in <________>.

algorithm

The Standard Template Library contains more than 80 function templates known as generic ________.

algorithms

In a recursive function, one must ensure that each recursive call makes progress towards the ________ so that it will eventually be reached; otherwise, infinite recursion (resulting in stack overflow) will result.

anchor case

A recursive definition of a function has two parts: (1) an ____ or base case and (2) an _____ or recursive case.

anchor, inductive

_______ sorting algorithms examine the data only by comparing two elements with a comparison operator.

comparison

A heap is a ________ binary tree that satisfies the heap-order property: Each node stores a value that is greater than (less than) or equal to the values in its children.

complete

All binary search trees are balanced

false

An array or vector can be used to store a heap efficiently because a heap is a(n) ___ binary tree.

complete

Heap sort is stable (T/F).

false

If we want to maintain load factor of .5 and have array of capacity 20. when do we increase size of array?

at 10 elements

Binary trees are trees in which each node has ______.

at most 2 children

Big-O notation is commonly used to represent an algorithm's ________. It gives an upper bound on the algorithm's computing time for large inputs.

efficiency

If T(n) > 5000n^3 for all n < 100000, then T(n) cannot be O(n^3). (True or false)

false

The more buckets you have in a hast table, the _____ the performance.

better

If the computing time of an algorithm is O(2^n), it should perform acceptably for most large inputs. (True or false)

false

Always make certain that a tree is not _____ before processing it. Same holds for subtrees.

empty

Most of the STL algorithms operate on specific containers. (True or false)

false

Quick sort is stable (T/F)

false

A collision strategy in which the hash table is an array or vector of linked lists that store the items is known as ____.

chaining

If you have hash table with high load factor. What collision resolution should we use?

chaining

Nodes that are directly accessible from a given node (by using only one directed arc) are called the _______ of that node, which is said to be the ______ of these nodes.

children, parent

Whats the issue with open-addressing, linear probing?

clustering

The case of two items needing to be placed at the same location in hash table is called a(n) ____.

collision

Hash tables are designed for _______ searches, insertions, and deletions.

constant time

The inorder and preorder traversal of a binary tree are d b e a f c g and a b d e c f g, respectively. The postorder traversal of the binary tree is:

d e b f g c a

An advantage of chained hash table (external hashing) over the open addressing scheme is______________

deletion is easier

In most recursive tree-processing algorithms, the empty tree provides the anchor case for the recursion. As a result, checking whether a tree is empty makes it possible to avoid: • _______ a null pointer • generating an ______ recursion

dereferencing, infinite

_____ recursion refers to a function calling itself directly.

direct

Quicksort is a _________ sorting method with average complexity of O(______). Industrial-strength versions, such as the sort() algorithm in STL, use a nontrivial pivot selection strategy such as the median-of-three rule, and use some other sorting method such as insertion sort to sort small sublists.

divide-and-conquer, n log n

Most of the STL algorithms designate sequences by two iterators. Where in the sequence are these iterators positioned?

first element, and just past the last element

What is the fastests searching and retrieval algorithm?

hash table

In a(n) ______ , the location of an item is determined directly by applying a function to the item. The function is called a(n) _____ function.

hash table, hash

One of the most efficient implementations of a priority queue uses a _________.

heap

The Big O of a Binary Search Tree is dependent of its _____

height

_____ sorting algorithms only need O(1) memory beyond the items being sorted.

in place

The size of a hash table can be dynamically _________ to reduce load factor

increased

A(n) ________ sort uses an index table that stores the positions of items to be sorted and moves the entries in this index rather than the records themselves.

indirect

For the function, what happens with the function call f(-1)? int f(int n) { .......if (n == 0) ............return 0; .......else ............return n + f(n - 1); }

infinite recursion

An ______ traversal of a binary search tree visits the nodes in ascending order of the values stored in them.

inorder

Which of the traversals in binary search tree gives sorted list: _________ (inorder, postorder, preorder)

inorder

LETTERS: A, C, R, E, S. a. Draw the BST that results when the letters are inserted in the order given. b. Perform INORDER, PREORDER, and POSTORDER traversals of the tree that results and show the sequence of letters that results in each case.

inorder: A,C,E,R,S preorder: A,C,R,E,S postorder: E,S,R,C,A

LETTERS: R, A, C, E, S. a. Draw the BST that results when the letters are inserted in the order given. b. Perform INORDER, PREORDER, and POSTORDER traversals of the tree that results and show the sequence of letters that results in each case.

inorder: A,C,E,R,S preorder: R,A,C,E,S postorder: E,C,A,S,R

Sorting methods are classified as _____ or _____ according to whether they are used for lists stored in main memory or for lists stored in secondary memory.

internal, external

As the load factor increases, what happens to performance?

it slows down

Nodes with no outgoing arcs are called ________.

leaves

The minimum in a binary search tree is the _______ most node, and the maximum is the ______ most node.

left, right

What is the time complexity of this recursive function? void recBinarySearch(ArrayType a, int first, int last, ElementType item, bool &found, int &loc) { if (first > last) { found = false; } else { loc = (fist + last) / 2; if (item < a[loc]) recBinarySearch(a, first, loc - 1, item, found, loc); else if (item > a[loc]) recBinarySearch(a, loc + 1, last, item, found, loc); else found = true; } }

log n

The complexity of the insert and delete-max operations for a heap are O(______).

logn

The worst case computing time of binary search is O(____).

logn

A hash table or hash map is a data structure that _____ keys to values using a ______ function to store in an array of ________

maps, hash, buckets

The structure of a recursive function is the same as for proofs by _______________.

mathematical induction

The _______ rule selects the median of the first, middle, and last elements in each sublist as the pivot.

median-of-three

What sort algorithm provides the best worst-case performance? Merge sort or quick sort

merge sort

Fill in the missing line: int fact(int num) { if (num == 0) return 1; else return _________; }

num * fact(num - 1)

For small lists, linear insertion sort performs O(___).

n

The Big O time analysis of Binary Search algorithm-linked list is O(______)

n

The computational complexity of an unbalanced binary tree is O(___).

n

The worst case computing time of linear search is O(____).

n

Complete the Recursive Power Function: double power(double x, unsigned n) { if (_____________) return 1; else return x * power(x, n - 1); }

n == 0

Heapsort is an O(_____) selection sort that is based on storing the items in a heap.

n log n

Mergesort is an O(______) sorting method that can be used either as an internal or external sort. Natural mergesort takes advantage of partially sorted lists and is thus preferred over binary mergesort.

n log n

The worst-case complexity of mergesort is O(______).

n log n

Fill in the missing line: Node * MINIMUM(T) { if ( _______ ) return n; else return MAXIMUM(n.left); }

n.left == NULL

The worst-case complexity of quicksort is O (_____).

n^2

Simple selection sort, bubble sort, and insertion sort are O(___) sorts and do not perform well for _____ lists.

n^2, large

The average-case complexity of mergesort is O( ).

nlogn

The average-case complexity of quicksort is O (_____).

nlogn

The complexity of heapsort is O(______ ).

nlogn

simple path

no repeated vertices

Non-recursive functions usually (but not always) execute more rapidly and use memory more efficiently than do the corresponding recursive subprograms. Thus, if the problem can be solved recursively or non-recursively with little difference in effort, it is usually better to use the ________ version.

non-recursive

Which is the approach with better time complexity to resolve the fibonacci sequence? recursive / non-recursive

non-recursive approach

In the early days of computing, which was more important?

space

collision resolution techniques

open- addressing: if spot is full go to next one (linear or quadratic probing) separate chaining: if spot is full just add, linked list implementation

Linear probing is an example of what is known as an _________ strategy for resolving collisions.

open-addressing

Fill in the missing line: int palindrome_check(string s, int start, int end) { if(end - start == 1 || start == end) { return 1; } else { if(s[start] == s[end]) { return ______________; } else { return 0; } } }

palindrome_check(s, start+1, end-1)

______ is also called syntax analysis or syntactic analysis.

parsing

The item properly positioned on each call to quicksort is called a(n)_______.

pivot

Which of the following pairs of traversals is not sufficient to build a binary tree from the given traversals? preorder and inorder preorder and postorder inorder and postorder

preorder and postorder

Program testing can show only the _____ of errors, not the ______ of errors.

presence, absence

Making a hash table capacity a __________ facilitates scattering of data values throughout the table.

prime number

Each data item in a _____________ has a priority associated with it, and these items are stored in such a way that those with higher priority are removed before those of lower priority.

priority queue

Each recursive call of a function involves _______ of activation records onto/from the run-time stack.

pushing/popping

Fill in the missing line: void recBinarySearch(ArrayType a, int first, int last, ElementType item, bool &found, int &loc) { if (first > last) { found = false; } else { loc = (fist + last) / 2; if (item < a[loc]) recBinarySearch(a, first, loc - 1, item, found, loc); else if (item > a[loc]) _____________________; else found = true; } }

recBinarySearch(a, loc + 1, last, item, found, loc)

For a recursive algorithm, a(n) ______ relation expresses the computing time for inputs of size n in terms of smaller-sized inputs.

recurrence

_____ is the phenomenon of a function calling itself.

recursion

_____ algorithms for some binary tree operations are simpler than _____ ones because binary trees can be viewed as recursive data structures.

recursive, non-recursive

A binary tree can be defined as a _______ data structure in a very natural way and several of the operations on a binary tree can thus be implemented most easily by ______ functions.

recursive, recursive

A node that has no incoming arcs but from which every other node in the tree can be reached by following a unique sequence of consecutive arcs is called a(n) ________.

root

A ______ stack is used to store an activation record for each call to a recursive function.

run-time

We also saw that because the last function interrupted is the first one to be reactivated, a _______________ is used to store the activation records so that they can be retrieved in a last-in-first-out order.

run-time stack

The two main criteria for evaluating an algorithm's efficiency are _______ utilization and ______ efficiency. Time efficiency is considered the more important and is usually measured as the number of times the algorithm's instructions are executed.

space, time

_____ is important to preserve order over multiple sorts on the same data set.

stability

____ sorting algorithms sort equal elements in the same relative order of records that they appear in input with equal keys.

stable

Unlike a binary search tree, a heap cannot become lopsided as items are inserted or removed.

true

A heap can be used to implement a priority queue efficiently. (True or false)

true

A non-recursive function for computing some value may execute more rapidly than a recursive function that computes the same value. (True or false)

true

A recursion tree is used to trace a recursive function calls.

true

Algorithms with exponential complexity are practical only for solving problems with few inputs.

true

Because a heap is a complete binary tree, it can be stored efficiently in an array.

true

Binary search is appropriate only for array-based lists, since it requires direct access to the list elements to be efficient.

true

Binary trees' nodes contain two pointer members.

true

Bubble sort is stable (T/F)

true

Bubble sort performs better for partially sorted lists than for random lists. (True or false)

true

Bubblesort is inefficient in almost every situation and should not be used as a general sorting scheme.

true

Calculating powers and finding Fibonacci numbers are examples of problems that can be solved with nearly equal ease using either a non-recursive or a recursive algorithm.

true

Deletion from a binary search tree can also cause it to become unbalanced.

true

For lists in general, quicksort, Shell sort, or heapsort is the method of choice.

true

If T(n) <= 5000n^3 for all n >= 100000, then T(n) is O(n^3). (True or false)

true

If T(n) <= 5000n^3 for all n >= 100000, then T(n) is O(n^4). (True or false)

true

In a post-order traversal, root nodes comes at the last.

true

Insertion sort is stable (T/F)

true

Linear insertion sort performs better for partially sorted lists than for random lists. (True or false)

true

Linear insertion sort performs well for small lists (with 15-20 elements). (True or false)

true

Linear search can be used for both array-based and linked lists.

true

Merge sort is stable (T/F)

true

Merge sort may be both recursive and non-recursive

true

Node values in a binary search tree are ordered

true

Selection, exchange, and insertion are three categories of sorts.

true

The Binary Tree array implementation is not space efficient for incomplete trees.

true

The C++ standard sort() algorithm uses quicksort. (True or false)

true

The array-based implementation works very well for complete binary trees, but it becomes increasingly less space efficient as the tree becomes more lopsided.

true

There is no such thing as one universally good sorting scheme. For lists in general, quicksort, Shell sort, or heapsort are the methods of choice.

true

Three significant factors in the performance of a hash table are the table capacity, the hash function, and the strategy for resolving collisions. The hash function should be easy to compute and should scatter items in the hash table.

true

Tree traversal is a linear operation.

true

Trees are linked structures.

true

Algorithm efficiency is usually measured for its ______ performance or, where feasible, its ______ performance.

worst-case, average-case

Complete the Recursive Power Function: double power(double x, unsigned n) { if (n == 0) return 1; else return ___________; }

x * power(x, n - 1)


Related study sets

AP Physics Semester 1 Study Guide

View Set

American Sign Language 2 (double letters)

View Set

Statistics Chapter 9 MC Questions

View Set

Chapter 3 Assignment for Module 12

View Set