CSC345 - Final Review

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

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

3

[Complex sorts] How many inversions are in the following array? [34 977 917 304 263]

6

Suppose that a particular algorithm has the time complexity T(n) = 8n and that executing an implementation 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.

64n

Assume that for some implementation, a pointer requires 4 bytes and a data object requires 14 bytes. Write a fraction to show how the full array should be for the break even point, that is, the point beyond which the array-based implementation needs less space than the linked list implementation. Give your fraction in the lowest terms

7/9

What is the minimum number of nodes in a complete binary tree with height 3?

8

Assume that for some binary tree node implementation, a pointer requires 4 bytes and a data objet requires 25 bytes. Further assume that all nodes are implemented to store two pointers and a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms

8/33

Suppose that a particular algorithm has the time complexity T(n) = n^2 and that executing an implementation 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

A type is: An implementation An integer Another name for an ADT A collection of values A variable

A collection of values

A composite type is: Another term for an Abstract Data Type Instance of a class A type comprised of other types

A type comprised of other types

[Complex Sorts] Mergesort works by splitting a list of n numbers in half, then sorting each half recursively, and finally merging the two halves. Which of the following list implementations would allow Mergesort to work in O(n log(n)) time. (1) A singly linked list (2) A double linked list (3) An array A. (1), (2), and (3) B. (3) only C. (1) and (2) only D. (1) only E. (2) only F. None of them G. (2) and (3) only

A. (1), (2), and (3)

[Graphs] A graph without cycles is called a/an Complete graph Connected graph Undirected graph Acyclic graph None of the above

Acyclic graph

[Complex Sorts] Which of these is the best definition for a stable sorting algorithm? 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 is as fast as the best one known 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

An ADT is most like which of the following A class An interface A data structure An object A method A program

An interface

In the linked list, where does the insert method place the new entry? After all other entries that are greater than the new entry At the rear At the head After all other entries that are smaller than the new entry At the current position

At the current position

The following sequence of operations is performed on a queue: enqueue(1) enqueue(2) dequeue() enqueue(1) enqueue(2) dequeue() dequeue() dequeue() enqueue(2) dequeue() The values values will be output in this order: A. 2 2 1 1 2 B. 1 2 1 1 2 C. 1 2 1 2 2 D. 2 2 1 2 2 E. 2 1 2 2 2

C

[Graphs] Given a subset S of the vertices in a graph, when all vertices in S connect to all other vertices in S, this is called a: Sparse matrix Directed graph Connected component Clique

Clique

[Graphs] A graph containing all possible edges is a _______ graph Complete Full Sparse None of the above

Complete

[Graphs] A digraph is a DAG Directed graph Undirected graph None of the above

Directed graph

It is an error to pop data from a(n) _______ stack Empty Array-Based Linked Initialized Full

Empty

[Hashing] Hashing is good for which queries? Exact match queries Range queries Find the maximum key value All of these None of these

Exact match queries

A BST is another name for a binary tree True or False?

False

A problem is an instantiation of an algorithm implemented in a specific programming language True or False?

False

An algorithm can only work if written in the right type of programming language True or False?

False

For integers a and b, a is equivalent to b if and only if a + b is odd. True or False, this is an equivalence relation?

False

In an array-based list implementation, to access the predecessor of the current node we must start at the first node in the list True or False?

False

No algorithm for searching in an unsorted array can be worse than O(n) since any algorithm must look at every value in the array in the worst case True or False?

False

Relation isFatherOf on the set of people is symmetric True or False?

False

The best case for the sequential search algorithm occurs when the array has only a single element True or False?

False

The following relation defines a partial ordering on the indicated set isFatherOf on the set of people True or False

False

The following relation defines a partial ordering on the indicated set. {<a,b>, <a,a>, <b,a>} on the set {a,b}

False

The upper bound for a problem is defined as the upper bound cost for the worst algorithm that we know True or False?

False

There are some algorithms that do not terminate for certain inputs True or False?

False

[Complex Sorts] Binsort's time complexity depends on the initial ordering of the keys in the input array True or False?

False

[Complex Sorts] Quicksort (as shown in class and the book) is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys. True or False?

False

[Graphs] Two vertices can be adjacent even if they are not neighbors True or False?

False

[Hashing] A problem with using tombstones is that they take up slots in the table that cannot be reused, so that over time the effective table size shrinks. True or False?

False

[Hashing] When deleting a record from a hash table, we can just do a normal search and then remove the record from the slot where we find it True or False?

False

[Sorting] In shellsort, it is illegal to have an increment of 5 when the array size is 14. True or False?

False

Which of the following operations is performed more efficiently by a doubly-linked list implementation than a singly-linked list. Searching an unsorted list for a given item Removing the current node Finding the node preceding the current node Traversing a list to process each node

Finding the node preceding the current node

[Algorithm Analysis] Which of the following sorting algorithms has a worst case complexity of O(n log(n))? Heap Sort Selection Sort Bubble Sort Insertion Sort Radix Sort

Heap Sort

[Hashing] The binning hash function makes use of Low order digits or bits of the key Middle order digits or bits of the key High order digits or bits of the key None of the above

Higher order digits or bits of the key

[Inversions] If I is the number of inversions in an input array of n records, then Insertion Sort will require how many swaps? n2/2 I I - n

I

[Complex Sorts] Consider what happens if someone accidentally calls sort on a file that is already sorted. Which of the following sorting methods will be the most efficient if the input is already in sorted order. Bubble Sort (good joke) Mergesort Selection Sort Insertion Sort

Insertion Sort

[Hashing] What is one disadvantage of quadratic probing as a collision resolution? Memory usage increases with each insertion You have to check whether or not a node needs to be split Insertions can fail even if there are empty slots in the table Primary clustering can degrade performance

Insertions can fail even if there are empty slots in the table

[Complex Sorts] A disadvantage of Heapsort is: None of these answers It needs a lot of auxiliary storage Its average case running time is Ө(n2) It is not stable (i.e. records with equal keys might not remain in the same order after sorting)

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

[Complex Sorts] What is the most complicated part of the Mergesort algorithm? Merging the sorted halves back together Achieving the base case Finding the midpoint Partitioning the array

Merging the sorted halves back together

[Graphs] A simple cycle... Must have all vertices be unique except that the first and last vertices are the same Must have all vertices be unique Allows repetition of vertices so long as the length of the path is less than 5 None of the above

Must have all vertices be unique except that the first and last vertices are the same

In an array-based list, the successive elements in the list Must occupy contiguous memory None of these Must not occupy contiguous space in memory

Must occupy contiguous memory

[Complex Sorts] Is the following a legal series of increments when running Shellsort on an array of 16 values? → 6,4,6,1 Yes No

No

[Simple Sort] Is the following a legal series of increments when running Shellsort on an array of 16-values? > 8, 4, 2, 3, 1 Yes No

No

You are given this set of growth functions: n!, 2n, 2n^2, 5n*log(n), 20n, 10n For the growth function 20n, write a value (a positive integer) for which this function is the most efficient of the six. If there is no integer value for which is the most efficient, answer with "none"

None

[Complex Sorts] The order of the input records has what impact on the number of comparisons required by Selection Sort (as presented in the books and class)? There is a constant factor difference There is a big difference, the asymptotic running time can change None

None

[Graphs] A graph with directed edges is called Labeled Graph Weighted Graph Complete Graph None of the above

None of the above

[Algorithm Analysis] When implementing Insertion Sort, a binary search could be used to locate the position within the first i-1 records of the array into which record i should be inserted. Using binary search will: Speed up the asymptotic running time because to position to insert will be found in O(log(i)) time None of these answers is correct Not speed up the asymptotic running time because shifting the records to make room for the insert will require O(i) time. Speed up the asymptotic running time because shifting the records to make room for the insert will require O(i) time.

Not speed up the asymptotic running time because shifting the records to make room for the insert will require Θ(i) time

Which of these is the best (tightest) upper bound for a growth rate of 5n+3 O(1) O(nlog(n)) O(n^2) O(log(n)) O(n)

O(n)

Determine Ө 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(nlog(n))

[Graphs] When a vertex Q is connected by an edge to a vertex K, what is the term for their relationship. Q and K are insecure Q and K are incident Q and K are adjacent None of the above

Q and K are adjacent

[Hashing] Which of the following is true of open hashing? The algorithm running time is determined by probes of different table cells until an empty one is found Records are stored on a list associated with a slot in the hash table All records are stored directly within the hash table

Records are stored on a list associated with a slot in the hash table

Which of these is NOT one of the three standard steps to follow when selecting a data structure to solve a problem Quantify the resource constraints for each operation Select the data structure that best meets the requirements determined in the prior steps of the process Analyze your problem to determine the basic operations that must be supported Run simulations to quantify the expected running time of the program

Run simulations to quantify the expected running time of the program

Which data structure would be used to implement recursion Queue Array-Based List Linked List Tree Stack

Stack

[Algorithm Analysis] Which of these will NOT affect the RELATIVE running times for two sorting algorithms? The number of records The allowable range for the record values The CPU Speed The amount by which the values are out of order

The CPU Speed

[Simple Sorts] When is Insertion Sort a good choice for sorting an array? Each record requires a small amount of memory None of these situations The processor speed is fast The array contains only a few records

The array contains only a few records

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

The depth of the relevent node in the tree

A data structure is: The implementation for an ADT A specification for an implementation A type Another name for an ADT A collection of values

The implementation for an ADT

[Algorithm Analysis] Which of these is a traditional measure for the cost of a sorting algorithm? The memory size The number of records The number of comparisons The amount by which the values are out of order

The number of comparisons

[Algorithm Analysis] Which of these is a traditional measure for the cost of a sorting algorithm The amount by which the values are out of order The number of records The number of swaps The memory size

The number of swaps

[Hashing] An open hashing table has an array size of 99. What is the maximum number of records that can be stored in the table? 99 49 98 There is no maximum

There is no maximum

[Simple Sort] When is Bubble Sort a good choice for sorting an array? The array has only a few items out of place There is no situation where Bubble Sort is the best choice over all the others we will study Each component of the array requires a small amount of memory Each component of the array requires a large amount of memory

There is no situation where Bubble Sort is the best choice over all the others we will study

Which of the following is not a linear data structure Linked List Tree Stack Queue Array-Based List These are all linear structures

Tree

A problem maps inputs to outputs True or False?

True

Big-Theta notation, Ө, defines an equivalence relation on the set of functions True or False?

True

Relation R = {<x,y> | x % y = 0} for x,y is the set of {1,2,3,4} is antisymmetric True or False?

True

Relation R = {<x,y> | x^2 + y^2 = 1} for real numbers x and y is symmetric True or False?

True

The Sequential Search algorithm is in O(n)

True

The following relation defines a partial ordering on the indicated set: isOlderThan on the set of people True or False

True

The following relation defines a partial ordering on the indicated set: {<2,1> <1,3> <2,3>} on the set {1,2,3} True or False?

True

The worst case upper bound for sorting an array is O(nlog(n)) since this is the cost of the best algorithm (in the worst case) that we know about. True or False?

True

This relation is an equivalence relation: For integers a and b, a is equivalent to b if and only if a + b is even True or False?

True

[Complex Sorts] Consider an array A of n records each with a unique key value, and ARthe same array in reverse order. Any given pair of records must be an inversion in exactly one of A or AR. True or False?

True

[Graphs] A DAG is a directed graph without cycles True or False?

True

[Hashing] Closed hashing works well for disk-space hash systems True or False?

True

[Inversions] Consider an array A of n records, each with a unique key value, and Ar, the same array in reverse order. Any given pair of records must be an inversion in exactly one of A or Ar. True or False?

True

[Simple Sort] In Shellsort, how are the sublists sorted? Using Insertion Sort because Shellsort generally makes each subarray reasonably close to sorted Using Quicksort, because this is generally the fastest sort Using Shellsort since this is a recursive algorithm Using Bubble sort since that is the most appropriate sort in this situation Using any sort that you like, it doesn't matter so long as they are sorted

Using Insertion Sort because Shellsort generally makes each subarray reasonably close to sorted

[Hashing] If you double the size of the hash table, can you keep using the same hash function? Yes, it works fine since the table size does not matter to the hash function Yes, but you will not hash to the new cells No, the hash function would now generate illegal values

Yes, but you will not hash to the new cells

Determine the proper relationship between the following pair of functions f(n) = 2^n g(n) = 10n^2 A. f(n) is in O(g(n)) B. f(n) is in Ω(g(n)) C. f(n) is in Ө(g(n))

f(n) is in Ω(g(n))

Rewrite the following in the form log(c) log(3) + log(2)

log(6)

[Complex Sorts] You must merge two 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 m * n max(m, n) min(m, n)

m + n - 1

[Complex Sorts] In the worst case, the total number of comparisons for Mergesort is closest to: n n^2 (n^2)/2 n log(n)

n log(n)

The number of permutations for n numbers is: n! 2^n n log(n) n^2 n^n

n!

Given a linked list implementation, deleting the current element takes how long in the average case? Ө(log n) time Ө(nlog (n)) time Ө(n) time Ө(1) time

Ө(1) time

[Simple Sort] If I is the number of inversions in an input array, then Insertion Sort will run in what time? Ө(n + I) Ө(I - n) Ө(I) Ө(n2)

Ө(n + i)

The n nodes in a binary tree can be visited in: Ө(1) time Ө(log(n)) time Ө(n) time Ө(nlog(n)) time Ө(n^2) time

Ө(n)

[Algorithm Analysis] What is the best-case time for Insertion sort to sort an array of n records? Ө(n logn) Ө(logn) Ө(n) Ө(n2)

Ө(n)

[Complex Sorts] What is the running time of Insertion Sort when the input is an array where all record values are equal. Ө(n^2) Ө(logn) Ө(n logn) Ө(n) Ө(n^n)

Ө(n)

Given an array-based list implementation, deleting the current element takes how long in the average case? Ө(nlog(n) time Ө(log(n)) time Ө(n) time Ө(1) time

Ө(n) time

Given an array-based list implementation, inserting a new element to the current element takes how long in the average case? Ө(nlog(n) time Ө(log(n)) time Ө(n) time Ө(1) time

Ө(n) time

Given an array-based list implementation, inserting a new element to the current position takes how long in the average case? Ө(log(n)) time Ө(nlog(n)) time Ө(n) time Ө(1) time

Ө(n) time

[Algorithm Analysis] What is the average-case time for Selection Sort to sort an array of n records? Ө(n) Ө(n logn) Ө(n^2) Ө(logn)

Ө(n^2)

[Complex Sorts] What is the worst-case cost for Quicksort to sort an array of n elements? Ө(nlogn) Ө(logn) Ө(n^2) Ө (n)

Ө(n^2)

[Simple Sort] What is the running time for Insertion Sort when the input array has values that are in reverse order? Ө(n logn) Ө(logn) Ө(n^2) Ө(n)

Ө(n^2)


Kaugnay na mga set ng pag-aaral

GLEIM PRIVATE PILOT TEST PREP CH. 2

View Set

CHAPTER 5: EXPANDING THE TALENT POOL RECRUITMENT AND CAREERS

View Set

ΕΠΑΝΑΛΗΨΗ 2ου Κεφ: ΕΙΣΑΓΩΓΗ, ΠΑΡΑΓΩΓΗ ΘΡΕΠΤ. ΟΥΣΙΩΝ ΣΤΑ ΦΥΤΑ, ΠΡΟΣΛΗΨΗ ΟΥΣΙΩΝ & ΠΕΨΗ ΣΤΟΥΣ ΜΟΝΟΚΥΤΤΑΡΟΥΣ ΟΡΓΑΝΙΣΜΟΥΣ, ΣΤΟΥΣ ΖΩΪΚΟΥΣ ΟΡΓΑΝΙΣΜΟΥΣ & ΣΤΟΝ ΑΝΘΡΩΠΟ

View Set

Chap 11 les politiques conjoncturelles

View Set

Final Exam U.S. History II UNIT 1: THE CIVIL WAR

View Set