CS3310 Final Exam Review Question Canvas

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

Suppose that a particular algorithm has time complexity T(n) = 8n and that executing an implementation of it on a particular machine takes t seconds for n inputs. Now suppose that we are presented with a machine that is 64 times as fast. How many inputs could we process on the new machine in t seconds? 8 64n 2^n ​​ 64n^2 ​​ 8n 64 n^2 ​​ 8n^2

64n

Given a hash table size of 100 and the simple mod hash function, what slot in the table will 386 hash to

86

Suppose that a particular algorithm has time complexity T(n) = n^2 ​​and that executing an implementation of it on a particular machine takes t seconds for n inputs. Now suppose that we are presented with a machine that is 64 times as fast. How many inputs could we process on the new machine in t seconds? 8n 64n^2 ​​ 64 64n 8n^2 ​​ 8 n^2 ​​ 2^n

8n

Which is the best definition for algorithm A program A mapping from input to output A recipe

A recipe

Determine \ThetaΘ for the following code fragment in the average case. Assume that all variables are of type "int". Assume that array A contains n values, "random" takes constant time, and "sort" takes n log n time. sum = 0; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) A[j] = random(n); sort(A); }

n^2 long n

In the worst case, the total number of comparisons for Insertion Sort is closest to:

n^2/ 2

best case for quick sort?

nlogn

The system will support range queries, when stored in main memory, working on a dynamic database (supports inserts and deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Binary Search Tree (assume that it is balanced)

Which of these is a true statement about the worst-case time for operations on heaps? Neither insertion nor removal are better than linear Both insertion and removal are 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

The system will perform exact mach queries only, when stored in main memory, working on a dynamic database (supports inserts and deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Closed Hash Table

The system will perform exact mach queries only, when stored in main memory, working on a static database (no inserts or deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Closed Hash Table

Hashing is good for which queries?

Exact match queries

Heapsort (as the code is written in this module) is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys. True False

False

If you are given the order of the nodes as visited by a preorder traversal and the order of the nodes as visited by a postorder traversal, do you have enough information to reconstruct the original tree? Assume that the nodes all have unique values. (T/F)

False

The best case for binary search occurs when the first element of the array is the value being searched for.

False

The physical order in memory for the nodes of a linked list is the same as the order in which the nodes appear in the list. (T/F)

False

Which of the following sorting algorithms has a worst case complexity of \Theta(n \log n)Θ(nlogn)? Selection Sort Bubble Sort Heap Sort Radix Sort Insertion Sort

Heap Sort

Which feature of heaps allows them to be efficiently implemented using an array? Heaps are full binary trees Heaps can easily be complete binary trees Heaps can easily be binary search trees Heaps are binary trees

Heaps can easily be complete binary trees

If I is the number of inversions in an input array of n records, then {Insertion|Bubble} Sort will require how many swaps? n​^2​​/2 n−I I n-1

I

When is Insertion Sort a good choice for sorting an array? Each record requires a large amount of memory The array contains only a few records The array contains many records The processor speed is fast

the array contains only a few records

A b tree is a generalization of the 2-3 tree

true

A search tree can be used to implement a search tree as well as a priority queue. (T/F)

true

Are b trees height balanced

true

In a b tree each internal node, except for the root has between Ceiling(m/2) and m children

true

In a b tree the root is either a leaf or has two children

true

Is merge sort stable ?

true

The upper bound for a problem is defined as the cost of the best algorithm that we know (T/F)

true

The upper bound for a problem is defined as the upper bound cost for the best algorithm that we know.(T/F)

true

a 2-3 tree is a B-tree of order 3

true

if f(n) is O(g(n)) this means that f(n) grows asymptotically no faster than g(n) if f(n) is Ω(g(n)) this means that f(n) grows asymptotically no slower than g(n) if f(n) is Θ(g(n)) this means that f(n) grows asymptotically at the same rate as g(n)

true

Which is the best definition for collision in a hash table? Two records have the same key and the same hash value Two records with different keys have the same hash value Two records are identical except for their keys Two records with the same key have different hash values

two records with different keys have the same hash value

The order of the input records has what impact on the number of comparisons required by Quicksort (as presented in this module)?

yes

The mid-squares method hash function makes use of: The low order digits or bits of the key The high order digits or bits of the key The middle digits or bits of the key None of the above

None of the above

A disadvantage of Merge Sort is: It is not stable(i.e. records with equal-valued keys might not be in the same order in the output as they were in the input) None of the given choices It is a quadratic time sort its a recursive sort It needs auxilliary storage beyond the input array

None of the given choices

Determine \ThetaΘ for the following code fragment in the average case. Assume that all variables are of type "int". sum = 0; for (i = 1; i ≤ n; i *= 2) for (j = 1; j ≤ n; j++) sum++;

O(n log n)

Heap Sort Time Complexity when all values are equal

O(n)

What is the running time of Insertion Sort when the input is an array where all record values are equal?

O(n)

Consider the following recurrence relation: T(n) = 3 if n =1 T(n) = T(n-1) + 3n if n>=2 What is the tight solution of T(n) in the asymptotic sense?

O(n^2)

Determine \ThetaΘ for the following code fragment in the average case. Assume that all variables are of type "int". Assume array A contains a random permutation of the values from 0 to n-1n−1. sum = 0; for (i = 0; i < n; i++) { for (j = 0; A[j] != i; j++) sum++; }

O(n^2)

What is the average-case time for Insertion Sort to sort an array of n records?

O(n^2)

What is the running time for Insertion Sort when the input array has values that are in reverse sort order? Θ(logn) Θ(nlogn) Θ(n^2) Θ(n)

O(n^2)

What is the running time of Selection Sort when the input is an array that has already been sorted?

O(n^2)

In the worst case, the total number of comparisons for Selection Sort is closest to:

O(n^2/2)

From the given choices, which one is the best upper bound for a growth rate of 5n-20*sqrt(n)+30? O(nlogn) O(logn) O(n^2) O(1)

O(nlogn)

In a min-heap containing n elements and implemented using array based representation of trees, what is the position of the element with the largest value? The rightmost leaf node 2∗n+1 n-1 2∗n+2 n 0 n+1 Possibly in any leaf node

Possibly in any leaf node

Which of the following sorting methods will be best if the number of swaps done is the only measure of effeciency? Insertion Sort Mergesort Bubble Sort Selection Sort Quicksort

Selection Sort

The lower bound for a problem is defined to be The cost of the best case input for the problem The maximum cost that any algorithm to solve the problem could have The same as the upper bound for the problem The best possible cost for any algorithm that solves the problem The cost of the best algorithm that we know for the problem

The best possible cost for any algorithm that solves the problem

The upper bound for a problem is defined to be: The cost of the worst case input for the problem The cost of the best algorithm that we know for the problem The cost of the worst algorithm that we know for the problem The same as the lower bound for the problem

The cost of the best algorithm that we know for the problem

BST search and insert operations typically run in time O(d). What is d? The height of the relevant node in the tree The number of divisions at each level The total number of entries in all the nodes of the tree The depth of the relevant node in the tree The number of entries in each node The number of nodes in the tree

The depth of the relevant node in the tree

Assuming that the number of digits used is not excessive (i.e., no more than the number of bits needed to represent n distinct values), the worst-case cost for Radix Sort when sorting n keys with distinct key values is: Θ(n) Θ(n2​​) Θ(n logn) Θ(N)

Θ(n logn)

What is the running time of Heapsort when the input is an array where all key values are equal?

Θ(n)

Given an array-based list implementation, deleting the current element takes how long in the average case?

Θ(n) time

The n nodes in a binary tree can be visited in: Θ(n^​2​​) time Θ(nlogn) time Θ(logn) time Θ(1) time Θ(n) time

Θ(n) time

Assuming "sort" takes Θ(nlogn) time and "random" takes O(1)-time, what is the time complexity of the following code: sum = 0; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) A[j] = random(n); sort(A); }

Θ(n*n* log n)

What is the running time for Selection Sort when the input array has values that are in reverse sorted order?

Θ(n^​2​​)

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

Θ(n^​2​​)

What is the average-case time for Heapsort to sort an array of n records that each have unique key values?

Θ(nlogn)

What is the best-case time for Heapsort to sort an array of n records that each have unique key values?

Θ(nlogn)

(Assuming no duplicate key values:) The order of the input records has what impact on the number of comparisons required by Heapsort (as presented in this module)? There is a constant factor difference There is a big difference, the asymptotic running time can change None

There is a constant factor difference

A program is an instance of an algorithm implemented in a specific programming language. (T/F)

True

When is Mergesort a good choice for sorting an array We need a reasonably fast algorithm with a good worst case cost The processor speed is fast Each record requires a small amount of memory None of these situations

We need a reasonably fast algorithm with a good worst case cost

When is Mergesort a good choice for sorting an array? Each record requires a large amount of memory We need a reasonably fast algorithm with a good worst case cost The processor speed is fast None of these situations

We need a reasonably fast algorithm with a good worst case cost

A problem is an instantiation of an algorithm implemented in a specific programming language (T/F)

false

A program maps inputs to outputs (T/F)

false

An algorithm maps inputs to outputs (T/F)

false

Heap sort is stable (T/F).

false

No algorithm for searching in an unsorted array can be worse than O(n)O(n) since any algorithm must look at every value in the array in the worst case.(T/F)

false

The lower bound for a problem is defined as the cost of the best algorithm that we know (T/F)

false

The worst case lower bound for sorting an array is O(n \log n)since this is the cost of the best algorithm (in the worst case) that we know about.(T/F)

false

Compare the asymptotic analysis (i.e., big-oh / big-Theta) for the following two code fragments. //Code fragment1 sum1 = 0; for (i=1; i<=n; i++) // First double loop for (j=1; j<=n; j++) // do n times sum1++; //Code fragment2 sum2 = 0; for (i=1; i<=n; i++) // Second double loop for (j=i; j>=1; j--) // do i times sum2--; first and second code fragments have the same asymptotic time complexity, but the second one is slower. they can't be compared second code fragment takes more time than the first in the asymptotic sense first code fragment takes more time than the second in the asymptotic sense first and second code fragments have the same asymptotic time complexities, but the second one is about twice as fast as the first

first and second code fragments have the same asymptotic time complexities, but the second one is about twice as fast as the first

You must merge 2 sorted lists of size m and n, respectively. The number of comparisons needed in the worst case by the merge algorithm will be: m+n-1 max(m,n) min(m,n) mn m+n

m+n-1

You must merge 2 sorted lists of size m and n, respectively. The number of comparisons needed in the worst case by the merge algorithm will be:

m+n−1

What is the best-case time for Heapsort to sort an array of n records that each have unique key values?

n log n

The total number of distinct pairs of records among n records is: 2n^2 n! n!/2 n(n−1)/2 n 2n n(n+1)/2 n^2/2 nlogn

n(n−1)/2

Suppose that a particular algorithm has time complexity T(n) = 3*2^n ​​ and that executing an implementation of it on a particular machine takes t seconds for n inputs. Now suppose that we are presented with a machine that is 64 times as fast. How many inputs could we process on the new machine in t seconds? 6n 3 6 n^2 ​​ n+3 3n 64 64n n+6

n+6

XYZ computer is 100 times faster than the computer of company prunes. Prune's computer can excute n inputs in an hour. how many inputs can XYZ handle if the growth rate is n^2

n10 (Ten times faster than prunes)

Determine \ThetaΘ for the following code fragment in the average case. Assume that all variables are of type "int". for (i = 0; i < n - 1; i++) for (j = i + 1; j < n; j++) { tmp = AA[i][j]; AA[i][j] = AA[j][i]; AA[j][i] = tmp; }

n^2

In a max-heap containing n elements, what is the position of the element with the greatest value? The rightmost leaf node n 0 The leftmost leaf node n+1 Possibly in any leaf node n-1n−1 2*n+1 2*n+2

0

Hardware vendor XYZ Corp. claims that their latest computer will run 5 times faster than that of their competitor, Prunes, Inc. If the Prunes, Inc. computer can execute a program on input of size n in one hour, what size input can XYZ's computer execute in one hour for an algorithm whose growth rate is sqrt(n) ?

25n

The maximum number of nodes in an n-node tree where rank 4 element can possibly exist in an array implementation of min-heap is 0 1 4 n 14 n/4 n-4 6

4

The mid-squares method hash function makes use of: The low order digits or bits of the key All of the digits or bits of the key The high order digits or bits of the key None of the above

All of the digits or bits of the key

Which of these is the best definition for a stable sorting algorithm? An algorithm that is as fast as the best one known An algorithm that always gives the right answer An algorithm that does not change the relative ordering of records with identical keys An algorithm that always gives the same order for duplicate keys from run to run

An algorithm that does not change the relative ordering of records with identical keys

The system will support range queries, when stored on disk, working on a dynamic database (supports inserts and deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

B+ Tree

In which cases are the time complexities the same for Quicksort? Best and Average only Worst, Average, and Best Worst and Average only Worst and Best only

Best and Average only

When is Quicksort a good choice for sorting an array None of the specified choices Each record requires a small amount of memory The processor speed is fast In most standard situations where you want to sort many records

In most standard situations where you want to sort many records

A person sorting a hand of cards might reasonably use which sorting algorithm? Bubble Sort Quicksort Mergesort Insertion Sort

Insertion Sort

A disadvantage of Heapsort is: Its average case running time is O(n^​2​​) It is not stable (i.e., records with equal keys might not remain in the same order after sorting) It needs a lot of auxilliary storage None of the given answers

It is not stable (i.e., records with equal keys might not remain in the same order after sorting)

Assume that a doubly linked list L consists of at least 1000 elements. The best case time (in the big-oh sense) occurs in the linear search algorithm when Insufficient information to answer the question Item is not in L at all Item is the 1000th element of L Item is somewhere in the middle of L Item is the last element of L Item is stored in the third node of L Item is in the 500th position in L In all cases, it does not matter where the item appears in L

Item is the 1000th element of L Item is in the 500th position in L Item is stored in the third node of L

The system will support range queries, when stored on disk, working on a static database (no inserts or deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Linear Index

When is Selection Sort a good choice to use for sorting an array? None of these answers When the cost of a swap is large, such as when the records are long strings When the array has only a few elements out of place When each component of the array requires a small amount of memory

When the cost of a swap is large, such as when the records are long strings

In which case might the number of comparisons NOT be a good representation of the cost for a sorting algorithm? When we are comparing strings of widely varying length When there are lots of records When the amount of available space is small When the CPU is really fast

When we are comparing strings of widely varying length

Sometimes, the constant factors in an algorithm's runtime equation are more important thant its growth rate. When the problem is sorting, this can happen in which situation? When the records are nearly sorted When the records are nearly reverse sorted When the CPU is really fast When there are lots of records When the amount of available space is small When we are sorting lots of small groups of records.

When we are sorting lots of small groups of records.

In which cases are the time complexities the same for BSTsort? Worst and Best Worst and Average Best and Average Worst, Average and Best

Worst, Average and Best

In which cases are the time complexities the same for Heapsort? Worst, Average and Best Best and Average Worst and Average Worst and Best

Worst, Average and Best

In which cases are the time complexities the same for Mergesort? Worst, Average and Best Worst and Average Best and Average Worst and Best

Worst, Average and Best

In which cases are the time complexities the same for Heapsort?

Worst, best, and average

What is a disadvantage of linear probing? The algorithm is difficult to program It can lead to allocating a lot of extra memory You tend to get primary clustering None of the above

You tend to get primary clustering

Which boolean expression indicates whether the values for the nodes pointed to by p and q are different? Assume that neither p nor q is null. (Answer it based on list ADT.) p.next != q.next p.element() != q.element() p != q p.element != q.element !(p == q) None of the given choices p.e != q.e

p.element() != q.element()

To access the node at position i in a singly-linked list takes one step takes two steps requires that all its predecessors be visited requires that all its successors be visited

requires that all its predecessors be visited

Consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree. If R has a parent, where will the parent's position be in the array? 2∗i+1 ⌊(i−1)/2⌋ 2∗i+2 None of the above

⌊(i−1)/2⌋


Ensembles d'études connexes

Jensen Chapter 1: The Nurse's Role in Health Assessment

View Set

Neuromuscular Pharmacotherapeutics - Mehdi

View Set

Skills Performance Skills Checklists

View Set