CMSC341 Final Study Guide

¡Supera tus tareas y exámenes ahora con Quizwiz!

We have an application with a circular array implementation of queue. The size of array is n. We insert n data points and the array becomes full. For the next insertion we create a new array with the size n+1. Every data point will be copied to the new array and the last data point will be inserted into the new array. What is the amortized cost of an insertion in this application? Assume, the cost of an insertion is 1, and the cost of a transfer to the new array is 1. -(2n+1) / (n+1) -n+1 -(n+1) / (2n+1) -2n+1

(2n+1) / (n + 1)

ADT stands for ... -Abstract Domain Template -A Data Test -Abstract Data Type -A Domain Template

-Abstract Data Type

In a C++ program the message Segmentation Fault means we are trying ... (Please select all cases that apply.) -to access a variable in our program which no memory is allocated for it. -to access a memory section in our program in which global variables are stored. -to access a memory section which does not belong to our program. -to access a variable in our program which no memory is allocated for it. -to access a memory section in our program in which local variables are stored. -to access a wrong section of memory.

-to access a variable in our program which no memory is allocated for it. -to access a memory section which does not belong to our program. -to access a variable in our program which no memory is allocated for it. -to access a wrong section of memory.

What list presents the results of storing the following data in a hash table using linear probing collision handling. Assume the table has 9 buckets, and the hash function is h(k) = k % 9. 5,28,19,15,20,33,12 -28,19,12,20,5,15,33 -28,19,12,20,5,33,15 -28,19,20,12,5,33,15 -28,19,20,12,5,15,33

28,19,20,12,5,15,33

Write the result of in-order traversal for the following tree. Enter your answer without any separator character like a space or a comma. [A] F B G A D C

ABCDFG

Write the result of post-order traversal for the following tree. Enter your answer without any separator character like a space or a comma. [A] F B G A D C

ACDBGF

The C++ STL map template class is implemented as .... -Sorted Array -Skew Heap -Binary search Tree -Hash Table

Binary search Tree

What is the array representation of nodes for the following heap data structure in an array implementation? (That is the order of nodes stored in the array.) Please note, the alphabet characters specify the priority. For example, the character "Z" represents the lowest priority. D K Q Z S Y -DKQZSY -DKZSQY -ZKSDYQ -ZSKYQD

DKQZSY

We constructed the following AVL tree after inserting the nodes F,B,G,A,D,C. What node requires re-balancing once all insertions are complete? Write the name of the node's key. [A] F B G A D C

F

Write the result of pre-order traversal for the following tree. Enter your answer without any separator character like a space or a comma. [A] F B G A D C

FBADCG

A hash function converts the data part of a (key-data) pair to an index number to find the storage location. -True -False

False

A hash table provides efficient operations (search, insert, remove) when sorting the data is required. -True -False

False

A hash table with quadratic probing guarantees finding an empty bucket in the table. -True -False

False

An algorithm with the running time of O(2^n) practically is able to run and process the large amount of data. -True -False

False

Generally, the Queue ADT provides "First In Last Out" data storage. -True -False

False

Generally, the stack ADT provides "First In First Out" data storage. -True -False

False

If we declare class A as a friend in class B, it means that class B has access to all members of class A. -True -False

False

In C++ we can call non-constant functions on constant objects. -True -False

False

In GDB we can debug the executable produced by the following compile command. " >> g++ test.cpp -o out " -True -False

False

In Tree ADT a leaf node is a node with two children. -True -False

False

In a binary tree data structure every node has one or two parents. -True -False

False

In a class with memory allocation we do not need to implement an assignment operator. The one provided by the compiler makes deep copies of objects -True -False

False

In a class with memory allocation we do not need to implement an assignment operator. The one provided by the compiler makes deep copies of objects. -True -False

False

In a doubly linked list we can access directly a member of the list using a key value. -True -False

False

In a hash table using open addressing collision handling, we can store multiple data items in every bucket. -True -False

False

In a non-circular array implementation of the queue ADT, both enqueue and dequeue operations run in O(1). -True -False

False

In a priority queue ADT, the smallest key always has the highest priority. -True -False

False

In a priority queue, the items leave the queue in the order that they arrived. -True -False

False

In a singly linked list with only a head pointer, inserting a node at its tail is as efficient as inserting a node at the tail of a doubly linked list with two pointers to head and tail. Note: efficiency means the number of required node visits. -True -False

False

In an AVL tree for every internal node the heights of its children differ by at least 1. -True -False

False

In asymptotic analysis of an algorithm, the upper bound indicates the minimum running time of algorithm. -True -False

False

In programming "Exception handling" refers to the fact that a program works exceptionally well -True -False

False

In the Map ADT the keys are always integer numbers. -True -False

False

In the following tree, the height of the tree is equal to the depth of the node A. F B G A D C -True -False

False

Pre-order traversal can be used to evaluate arithmetic expressions. -True -False

False

The following hash function provides proper locations in the hash table for storing data. int hash (string key) { int value = 0; for (int i = 0; i < key.length(); i++) { value += key[i]; } return value; } -True -False

False

The running time of search operation in an AVL tree is O(n), where n is the number of nodes -True -False

False

The space required for the stack ADT for n data points, is O(log n). -True -False

False

The storage space of a Heap data structure is O(log n). -True -False

False

Three is no difference in space usage, between a doubly linked list and a singly linked list. -True -False

False

We can store multiple data objects with the same key in a STL map container. -True -False

False

The clustering problem most commonly happens in ... -Hashing with chaining -Hashing with double hashing -Hashing with quadratic probing -Hashing with linear probing

Hashing with linear probing

What curve represents the growth rate of O(log n)?

L flipped 90 degrees to the right C

After inserting C in the following AVL tree, the tree is unbalanced. What is(are) the operation(s) to re-balance the tree? Specify the operation's name and the node that the operation would happen. F B G A D C

Left rotation about B , then right rotation about F Note, the answer should specify the node at which the rotation happens.

What operation is required to re-balance the following tree in order to maintain the AVL tree height property? J H L K M N -Left rotation about L -Left rotation about M -Double rotation (left rotation about L, left rotation about J) -Left rotation about J

Left rotation about J

Which list provides the in-order traversal of the following binary tree. Please note, it is not important whether this is a binary search tree or just a binary tree. K M I N L J H -N M L K J I H -N L M J H I K -K M N L I J H -H I J K L M N

N M L K J I H

Does the following tree represent a valid max-leftist-heap? Please note, in this tree the alphabet characters represent the priority. For example, "A" shows the lowest priority. G F D E B C A -Yes -No

No, because the NPL value at F is 0 and at D is 1, then F and D must be swapped.

Find the worst-case running time of the following function in big-O notation. Show your work, counting the primitive operations, finding the big-o function, and the values for C and n0. Note: write the count of operations for every line of code and add the total count at the end, for example, Line 2: 2 operations, 1 declaration, 1 assignment .... Total: Then, show your work in finding big-O function, and finally the values for the constant C, and n0.

Note, in worst case at every iteration we do comparison at line 4 and then we execute line 5, Line 2: 2 (declaration, assignment) Line 4: 2n (accessing array, comparison), (1 point for this count) Line 5: 2n (increment, assignment) or n (increment), (1 point for this count) Line 6: n (comparison), (1 point for this count) Line 7: 1 (return) Total: 5n + 3 or 4n + 3 5n+3 <= (5+3)n (2 points for this relation or the relation in the next line, the numbers can be a little different due to count differences) 5n+3 <= 8n C = 8, if we use 4n + 3 then C = 7, (1 point for the C value) N0 = 1, N0 can be equal or greater than 1, (1 point for the N0 value) O(n), there is only one possible final answer (3 points)

Algorithm A executes an O(log n)-time computation for each entry of an n-element array. What is the worst-case running time of algorithm A?

O( n log n )

The height of a regular Heap data structure is ... -O(n log n) -O(n) -O(log log n) -O(log n)

O(log n)

The worst case running time for an algorithm with (log n^2) primitive operations is ..... -O(log n) where c=2 and n0=1 -O(n) where c=2 and n0=2 -O(n) where c=2 and n0=1 -O(log n) where c=2 and n0=2

O(log n) where c=2 and n0=2

What is the worst case running time for heap sort algorithm? -O ( 1 ) -O ( n ) -O ( n log n ) -O ( n2 )

O(n log n)

Which one is the worst growth rate in running an algorithm? -O(1) -O(n log n) -O(10) -O(n)

O(n log n)

Which one is the worst growth rate in running an algorithm? -O(10) -O(n log n) -O(1) -O(n)

O(n log n)

In a sorted list implementation of priority queue, the worst case running time of insertion operations is ... -O(n) -O(1) -O(log n) -O(n2)

O(n)

In an unsorted list implementation of priority queue, the worst case running time of removal operations is ... -O(1) -O(n) -O(log n) -O(n2)

O(n)

The rehashing operation runs in ... -O(1) -O(log n) -O(n) -O(n log n)

O(n)

What is the cost of push operation In the array implementation of stack when we get an overflow situation and we need to resize the array, i.e. increasing the size of array by one? -O(4n) -O(n) -O(2n) -O(1)

O(n)

What is the upper bound for the growth rate of insertion at an arbitrary location in a linked list? -O(1) -O(n log n) -O(10) -O(n)

O(n)

What is the upper bound for the growth rate of insertion at the head of an array? O(n log n) -O(n) O(1) O(10)

O(n)

What is the upper bound for the growth rate of the following function? void aFunction(int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cout << i * j << " "; cout << endl; } -O(3n) -O(n^2) -O(2^n) -O(n^3)

O(n^2)

A full binary tree is a tree in which every node has zero or two children. -True -False

True

A hash table data structure is an implementation of the Map ADT. -True -False

True

An ADT is the implementation of a data structure. -True -False

True

Finding a specific node takes the same amount of time whether we use a singly linked list or a doubly linked list to store the same data. -True -False

True

If T(n) is O( f ( n ) ) then there is a constant c > 0 such that T(n) ≤ c f (n) for all non-negative n. -True -False

True

If the following relationship holds true we can say that f(n) is big omega of g(n). We can also say f(n) is big O of g(n). c' g(n) < f(n) < c" g(n) -True -False

True

If we do not know the number of data items in advance, we can use a resizable array data structure such as C++ STL vector class. -True -False

True

If we know the number of data points in advance, using an array is more efficient than a linked list with regard to space usage. -True -False

True

In Tree ADT the root of tree is at depth zero. -True -False

True

In a C++ class a data member can be a class itself. -True -False

True

In a C++ class we can overload the constructor. -True -False

True

In a Heap data structure implementation, the tree does not have to preserve the binary search tree property. -True -False

True

In a doubly linked list implementation of the queue ADT, both enqueue and dequeue operations run in O(1). -True -False

True

In an array implementation of the stack ADT, both pop and push operations run in O(1). -True -False

True

In an overloaded assignment operator first we need to implement protection against self-assignment. -True -False

True

In the context of hash tables a good hash function is the one that distributes the data items uniformly across the bucket lists (array). -True -False

True

The Python Dictionary type is an implementation of the Map ADT. -True -False

True

The circular singly linked list is more efficient than a doubly linked list with regard to space usage, when implementing the queue ADT. -True -False

True

The following tree is not a complete tree. A K Q Z Y -True -False

True

The function (3n^2 + 5n^2 log n + n) is O(n^2). -True -False

True

The ideal running time for search operation in the Map ADT is O(1). -True -False

True

Considering the following function, explain when the function runs in its worst-case running time. Note: if there are multiple cases you should explain all. int test(int array[], int n, int x) { int i = 0; do { if (x == array[i]) return i; else i++; } while (i < n); return -1; }

Worst case run time is when x never equals an integer in array[] and n > i. While the complete worst case scenario is that x never equals an integer in array[] and n equals infinity - as that will be an infinte loop - from my understanding you can't really set an int to infinity like that. Simply however, if x never equals a value in the array and n is greater than i, the function will have its worst running time possible. Correct Answer: X is in the last index of the array (2.5 points) X is not in the array (2.5 points)

What data structure can be used for implementing a hash table in order to obtain running time O(1) for search operation? -a singly linked list -a doubly linked list -an array -a binary search tree

an array

How do we prevent modifications to an object, when we pass the object by reference to a function? -in the function we make sure object is not modified -we cannot prevent such modifications -by passing the address of the object iby passing the object as const

by passing the object as const

Which one is the final shape of the regular min-heap after inserting the node "B" in the following min-heap? Please note, the alphabet characters specify the priority. For example, the character "Z" represents the lowest priority. D K Q Z S Y -a -b -c -d

c (B GETS SHOVED ON TOP)

A binary tree in which every external node is at the same level and all external nodes are filled in left to right is called a ... -proper tree -full tree -complete tree -linked list tree

complete tree

In the application A after 1000 data points insertion at the cost of 3 per insertion we need to transfer all data to the application B for some processing and take them back. The total cost of transfer is 500. The total cost of processing data points by application B is 2400. What is the amortized cost of insertion? Show your work on how you calculate the cost.

cost of insertiion in A is 3 x 1000 = 3000 cost of transfer is 500 cost of processing in B is 2400 the total cost is 5900 (3 points) amortized cost per insertion is 5900 / 1000 = 5.9

In a C++ class a destructor has a return type. -True -False

false

How do we deallocate memory for the following variable? int * testVar[100];

for (int i = 0; i < 100; i++) { if (testvar[i] != nullptr) { delete testvar[i]; testvar[i] = nullptr; }

The following function prototype takes an array, an index within the array indicated by i, and the array size indicated by n. The function calculates the sum of array values from index i to the end of array and it returns the summation. Implement the function recursively, i.e. the function calls itself recursively to find the results. Notes: The function running time should not be greater than O(n) The algorithm of function should work correctly. If there is a syntax error such as missing a semicolon, the answer will not lose points. int add ( int anArray [ ], int i , int n );

int add( int anArray[], int i, int n) { int returnInt; if (i != n) { returnInt = anArray[i]; returnInt += add(anArray[], i++, n); } return returnInt; }

How many internal nodes are there in a perfect BST with a height of three? -greater than 2^3 -less than 2^3 -less than or equal to 2^3 -equal to 2^3

less than 2^3

What is the big O function for the space used by a stack data structure? -n -log n -n log n -n2

n

In the array implementation of a Heap data structure, the index of the left child of a node is determined by ... -nodeIndex / 2 -nodeIndex * 2 -nodeIndex + 2 -nodeIndex % 2

nodeIndex * 2

In the C++ STL class "std::priority_queue" the insertion operation is called ... -insert (...) -push (...) -pushEnd (...) -enqueue (...)

push (...)

We are designing an application for the airport control tower which keeps track of airplanes ready for take off. Airplanes take off in the order they get ready. What ADT is a proper one to store the list of planes so that the tower can use to issue the take off permission?

queue

We want to design an application which its job is to cypher a message. The algorithm reads the message as a stream of characters, changes some characters randomly and converts them to another character, at the end it writes the message in a reversed stream of characters. Then the reversed message will be sent to the destination. What is the proper ADT to be used in this algorithm?

stack

In Tree ADT the height of a node is ... -the number of edges between the node and the tree root. -the number of edges between the root and the deepest leaf. -the number of edges between the node and the closest leaf. -the number of edges between the node and the farthest leaf.

the number of edges between the node and the farthest leaf.

Considering the following function, explain when the function runs in its best-case running time. Note: if there are multiple cases you should explain all. int test(int array[], int n, int x) { int i = 0; do { if (x == array[i]) return i; else i++; } while (i < n); return -1; }

when x is in index 0 of the array or n = 0


Conjuntos de estudio relacionados

Prepu: Chapter 5: Growth and Development of the Preschooler

View Set

24. Veřejná obchodní společnost, komanditní společnost

View Set

TopHat chapter 17 Blood Questions

View Set

Chapter 19: Advertising, Public Relations, and Sales Promotions

View Set