CS303

Ace your homework & exams now with Quizwiz!

The __________________________ of a node is a measure of its distance from the root.

Level

Operators (Binary Trees)

Lower nodes are evaluated first, thus no need for parentheses

__________________ are associative containers where each element has a key value and a mapped value. No two mapped values can have same key values.

Maps

Heap Insertion and removal are O(?)

O(log n)

Quadratic Probing

Probe Sequence is (Hk+1)^2. Minimizes clustering better at distinguishing items across table. k +=2; index = (index + k) % table.size();

One of the main differences between vectors and arrays is ____________________________

Size of arrays are fixed whereas the vectors are resizable

For the following array: 100 30 75 60 12 5 80 50. Using Quick sort algorithm, show in detail the process of partitioning. Show the array after the first iteration (selecting the first pivot). No Code is required.

Sort of similar to the merge sort algorithm; the quick sort also partitions parts of the array but instead of it being split evenly or down the middle, it is split at a pivot point(or a specific number typically the end of the array). 100 30 75 60 12 5 80 50 (50 is the pivot point) ---> splits into <=50 and >=50 1st) 30 12 5 and 50 and 100 75 60 80 2nd) splits from (<=5 and >=5) and (<=80 and >=80) ---> 5 and 30 12 --> and 75 60 and 80 and 100 (every and is a split in the way it is partitioned) 3rd) <=12 and >=12 ---> 5 12 30 ---> <=60 and >=60 ---> 75 800 100 I am running out of time but I hope you see the explanation I am getting

Selection Sort

Sorts an array by making several passes through the array, selecting a next smallest item in the array each time and placing it where it belongs in the array worst case: O(n^2)

Linear Probing

Step size is 1. Find the index, and keep incrementing by one until you find a free space.

Operands (Binary Trees)

Stored in leaf nodes

Reducing Collisions by expanding the table size

Use prime number for the size of the table, values must be reinserted (rehasing) into the new, larger table. Deleted items are not reinserted

Open Addressing

Uses probes to find an open location to store data.

Binary Search Tree

Worst case O(n), best case O(log n)

Complete Binary Tree

a binary tree of height h is filled to depth h-1 and, at depth h any unfilled nodes are on the right

Full Binary Tree

a binary tree where all internal nodes have exactly 2 children

Heap

a complete binary tree where the value in each node is greater than or equal to all values in the node's subtrees

Shell Sort

a type of insertion sort, but with O(n^3/2) as it uses a divide and conquer approach by sorting many smaller subarrays using insertion sort before sorting the entire array Helps when the data size is larger and O(n^2) becomes more significant

What is the Big O Notation for the following fragment: for (cnt1 = 0, i = 1; i <= 10; i++) for (j = 20; j >= 1; j/=2) cnt1++; a) 1 b) n c) n to the power of 2 d) log(n)

a) 1

When using atomic data synchronization, how many statements could be used with this technique? a) 1 b) 2 c) 4 d) unlimited

a) 1

The following numbers are inserted into an empty binary search tree in the given order: 8, 5, 4, 1, 7, 6, 3, 2. What is the height of the binary search tree (the height is the maximum distance (number of branches) of a leaf node from the root)? a) 5 b) 4 c) 8 d) 6

a) 5

A a double-linked list requires more space comparing to a single-linked list. a) True b) False

a) True

A hash function may give the same hash value for distinct messages. a) True b) False

a) True

Code in an OpenMP program that is not covered by a pragma is executed by one thread a) True b) False

a) True

The following code will result in a data race: #pragma omp parallel for for (i=1; i < 10; i++) { factorial[i] = i * factorial[i-1]; } a) True b) False

a) True

The vector and the list are examples of what the C++ standard calls a sequential container a) True b) False

a) True

Variables defined in the shared clause are shared among all threads. a) True b) False

a) True

When a hash table becomes sufficiently full, a larger table should be allocated and the entries rehashed. a) True b) False

a) True

deque is a double-ended queue allows you to insert, access, and remove items from either end a) True b) False

a) True

inserting or erasing an element from a vector may require the implementation of elements shifting operations. While in linked list, no shifting is required at all. a) True b) False

a) True

What is the Big O Notation for the following fragment: for (cnt3 = 0, i = n; i >= 2; i /= 2) for (j = 1; j <= 10; j++) cnt3++; a) log(n) b) log2(n) c) n*log(n) d) n*log2(n)

a) log(n)

What is the Big O Notation for the following fragment: for (i = 1; i < n; i++) { cout<<j<<endl; } for (j = 1; j < n; j++) { cout<<j<<endl; } for (k = 1; k < n; k++) { cout<<k<<endl; } a) n b) 3*n c) n to the power of 3 d) n to the power of 2

a) n

A linked list is preferred over a vector when only inserting and deleting elements is implemented at the end the date structure. a) True b) False

b) False

All binary search trees are balanced a) True b) False

b) False

Chained is usually faster than open-addressing hashing when the load factor is low. a) True b) False

b) False

Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4197) and the hash function (x % 7). 1334, 9679, 6171, 4197 hash to the same value. a) True b) False

b) False

The stack's storage policy is First-In, First-Out, while the queue's storage policy is Last-In, First-Out a) True b) False

b) False

You can use a queue to reverse the order of the characters of a string a) True b) False

b) False

What is the Big O Notation for the following fragment: for (i = 1; i < n; i*=2) for (j = 1; j < n; j*=3) for (k = 1; k < n; k*=4) cout<<k*i*j<<endl; a) n to the power of 3 b) log(n) to the power of 3 c) (n*n*n)/9 d) non of these answers is correct

b) log(n) to the power of 3

What is the Big O Notation for the following fragment: for (i = 0; i < n; i++) for (j = 0; j < n; j+=2) a[i][j] = b[i][j] + c[i][j]; a) log(n) b) n to the power of 2 c) n d) n/2

b) n to the power of 2

What is the Big O Notation for the following fragment: for (i = 1; i < n; i++) { for (j = 1; j < n; j++) { cout<<j*i<<endl; } for (k = 1; k < n; k++) { cout<<k*i<<endl; } } a) n to the power of 3 b) n to the power of 2 c) 2*n to the power of 3 d) 2*n to the power of 2

b) n to the power of 2

What is the Big O Notation for the following fragment: for (cnt3 = 0, i = 1; i <= n; i *= 2) for (j = 1; j <= n; j++) cnt3++; a) n to the power of 2 b) n*log(n) c) n*log2(n) d) n

b) n*log(n)

Which one of the following application doesn't utilize stacks for implementation. a) finding palindromes b) tracking printing jobs c) balanced of parentheses in expressions d) evaluating postfix expressions

b) tracking printing jobs

#pragma omp parallel private(i) for (int i = 0; i < 120; i++) { a[i] = i; } How many iterations are executed if eight threads execute the above program? a) 120 b) 15 c) 960 d) 30

c) 960

What is the Big O Notation for the following fragment: for (i=0; i<=n-1; i++) for (j=i+1; j<=n-1; j++) cout<< i*j <<<i*j<<endl; a) n b) log(n) c) n to the power of 2 d) 2 to the power of n

c) n to the power of 2

What is the Big O Notation for the following fragment: for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) cout<<k*i*j<<endl; a) n b) n to the power of 2 c) n to the power of 3 d) n*n*log(n)

c) n to the power of 3

What is the Big O Notation for the following fragment: for (i = 0; i < n; i+=3) for (j = 0; j < n; j++) for (k = 1; k < n; k*=3) cout<<k*i*j<<endl; a) n to the power of 2 b) n to the power of 3 c) n*n*log(n) d) ((n*n)/9)*log(n)

c) n*n*log(n)

If node A is the parent of node B, which is the parent of node C, which in turn is the parent of node D, node A is an ancestor of nodes B, C, and D, and node D is a _____________________________ of nodes A, B, and C.

descendant

Min Heap

each node's value is smaller than the values of its children, and the root node stores the smallest value

Chaining

each table element references a linked list that contains all of the items that hash to the same table index(the linked list is often called a bucket)

A _________________ binary tree is a binary tree where all internal nodes have exactly 2 children

full

Which one of the following hash functions on integers will distribute keys most uniformly over 50 buckets numbered 0 to 49 for i ranging from 0 to 5000?

h(i) =(i to the power of 3) % 50

A(n) _________________________ traversal algorithm traverses the left subtree, visits the root, and then traverses the right subtree.

in order

_________________ traversal outputs the data in sorted order in a BST.

in order

Not considering the race condition when Parallel computing could lead to ______________________________

incorrect results

In an expression tree, operations are stored in the _______________________ node(s).

internal

An Object member of the STL which function as a pointer to have access to memory addresses of STL (Links to an external site.) containers is ___________________________

iterator

In an expression tree, operands are stored in the _______________________ node(s).

leaf

Postorder Traversal

left, right, root

Inorder Traversal

left, root, right

The __________ is the same as the set except that it does not impose the requirement that the items be unique.

multi set

The Big O notation for the operation of deleting an element in a vector (Assuming you know location of the element to be deleted) is ___________________

n

The Big O notation of the worst case scenario of pushing back an element into a stock implemented using a vector is _______________

n

the worst case Big O notation for search, insert and delete operations in a BST is __________________

n

It was found out that the speedup factor of a programming project equal to 1.6. If the parallel part was %40 and the serial part was %60. How many threads were used in this project?

n = 16

A(n) _________________________ traversal algorithm traverses the left subtree, traverses the right subtree, and then visits the root.

post order

A(n) _________________________ traversal algorithm visits the root, traverses the left subtree, and then traverses the right subtree.

pre order

When a vector is full and a new item is to be added, the method __________________________ will be called

reserve

Each node in a tree has exactly one parent except for the _________________________ node, which has no parent.

root

Preorder Traversal

root, left, right (imagine a mouse walking along the outside of the tree, also called a Euler tour)

Quicksort

selects a specific value called a pivot and rearranges the array into two parts (called partitioning) all the elements in the left subarray are less than or equal to the pivot all the elements in the right subarray are greater than the pivot O(nlogn)

The ________________ of a binary tree refers to the number of nodes it has.

size

Load Factor

the number of filled cells divided by the table size (has the greatest effect on has table performance, the lower the load factor, the better the performance as there is a smaller chance of collision when a table is sparsely populated)

Max Heap

the root node stores the largest value

The main different between a map and a set pf pairs is that ______________________________________

with set of pairs, you can have pairs with repeated key values

Deleting an item using open addressing

you must replace the deleted data with a dummy value or mark the location as available, deleted items reduce search efficiency, you cannot replace a deleted item with a new item until you verify that the new item is not in the table

What is the result of performing the following operation? {2, 3, 4, 5}+{1, 3, 5, 7}

{1,2,3,4,5,7}

What is the result of performing the following operation? {1, 3, 5, 7} - {2, 3, 4, 5}

{1,7}

What is the result of performing the following operation? {2, 3, 4, 5}-{1, 3, 5, 7}

{2,4}

What is the result of performing the following operation? {1, 3, 5, 7} * {2, 3, 4, 5}

{3,5}

sets and maps in STL are implemented using ___________________________________

Balanced Binary Search Tree

Like a vector, a set has an subscript operator function (operator[]). a) True b) False

b) False

The probability of collusion to happen is lower when the size of the hash table is close to the size of the data a) True b) False

b) False

OpenMP uses the _______________________ for parallel execution

fork-join model

The equivalent infix expression for the post fix expression (20 35 - 5 / 10 7 * +) is

(20-35)/5+10*7

The Big O notation for the operation of Inserting an element in a linked list (Assuming you know where to insert the element) is ___________________

1

The Big O notation for the operation of accessing an element in a vector is ___________________

1

The Big O notation of the worst case scenario of pushing back an element into a queue implemented using a list is _______________

1

Algorithm for Rehasing

1) Allocate a new hash table with twice the capacity of the original 2) Reinsert each old table entry that has not been deleted into the new hash table 3) Reference the new table instead of the original

Algorithm for Inserting into a Heap

1) Insert the new item in the next position at the bottom of the heap 2) while new item is not at the root and new item is smaller than its parent 3) swap the new item with its parent, moving the new item up the heap

Algorithm for removing and item from a heap

1) Remove the item in the root node by replacing it with the last item in the Heap(LIH) 2) while item LIH has children and item LIH is larger than either of its children 3) swap item LIH with its smaller child, moving LIH down the heap

Indicate whether you should use an iterator or a const_iterator as a parameter in new functions for the list class that would perform each of these operations. 1) Insert a new element after the current iterator position: 2) Replace the data stored in the currently selected item: 3) Retrieve the data stored in the currently selected item: 4) Insert a new element before the currently selected item:

1) iterator 2) iterator 3) const_iterator 4) const_iterator

Advantages relative to open addressing

1) only items that have the same value for their hash codes are examined when looking for an object 2) you can store more elements in the table than the number of table slots (indices) 3) once you determine an item is not present, you can insert it at the beginning or end of the list 4) to remove an item, you simply delete it; you do not need dummy values

The preorder traversal sequence of a binary search tree is 8, 5, 4, 1, 3, 2, 6, 7. Which one of the following is the inorder traversal sequence of the same tree?

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

For the following array: 100 30 75 60. Sort the array using insertion sort. Make sure to show the new array after each pass (show details of how the sorting algorithm is implemented). No Code is required.

100 30 75 60 --> 30 100 75 60 (this algorithm checks the 2 elements closest to each other and switches them until the biggest one is right most then will start over at the next index) 30 100 75 60 (comparing 100 < 75)--> 30 75 100 60(comparing 100<60) --> 30 75 60 100(comparing 75 < 60) -->30 60 75 100(comparing 75 <100) --> done

For the following array: 100 30 75 60. Sort the array using selection sort. Make sure to show the new array after each pass (show details of how the sorting algorithm is implemented). No Code is required.

100 30 75 60 --> 30 100 75 60 (this algorithm finds the smallest index in the unsorted array or list and puts it to the left furthest element) **must increment index by +1 every time in order to not switch the first element every time** 30 100 75 60 --> 30 60 75 100 (the algorithm found 60 to be the next lowest number and switched it with the new left-most element) after that step the algorithm will check for the next lowest number, noticing it is already the left-most it will be done with execution and present results.

For the following array: 100 30 75 60. Sort the array using bubble sort. Make sure to show the new array after each pass (show details of how the sorting algorithm is implemented). No Code is required.

100 30 75 60 --> 30 75 60 100 (since 100 was bigger than all other elements it will go to the end) 30 75 60 100 --> 30 60 75 100 (since 30 was smaller than the next element, it checked 75 < 60, moved it, then 75< 100 is true so it stops) after that the algorithm will check that 60 < 75, after that is proven true we are done.

For the following array: 100 30 75 60 12 50 80 5. Sort the array using Merge sort algorithm. Make sure to show steps of the implementation (show details of how this sorting algorithm is implemented). No Code is required.

100 30 75 60 12 50 80 5 ---> splits into two sections ---> 100 30 75 60 and 12 50 80 5 1st section) 100 30 75 60 ---> (splits again)100 30 and 75 60 ---> 30 100 and 60 75 ---> (reconnects as) 30 60 75 100 2nd section) 12 50 80 5 ---> (splits again)12 50 and 80 5 ---> 12 50 and 5 80 ---> (reconnects as) 5 12 50 80 Final product) both sections reconnect ---> 5 12 30 50 60 75 80 100

Assume chaining method is used to hash 60,000 items in the hash table, and a load factor of 0.75 This requires a table of size ____________ and results in an expected number of comparisons of 3.5

12000

The final result value of evaluating the postfix expression shown below is: 2 3 4 5 6 7 + - + - *

14

what is the maximum number of nodes in a complete binary tree knowing that the tree has 4 levels (level 0 to level 3)

15

The preorder traversal sequence of a binary search tree is 8, 5, 4, 1, 3, 2, 6, 7. Which one of the following is the postorder traversal sequence of the same tree?

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

Given a hash table T with 100 slots that stores 500 elements, the load factor α for T is

5

Merge Sort

A list is split into individual lists, these are then combined (2 lists at a time). O(nlogn)

Hash Table

A table of information that is accessed by way of a shortened search key (the hash value) on average, O(1)

Huffman Tree

A tree that represents Huffman codes for characters that might appear in a txt file (used to compress files)

Consider the following statements: std::map<string,string> a_map; a_map["Romania"]="Bucharest"; a_map["R"] = "Russia"; a_map["R"] = a_map["Romania"]; cout << a_map["R"] << endl; What value will be printed by the last line?

Bucharest

Bubble Sort

Compares adjacent array elements and exchanges their values if they are out of order(smaller values "bubble" up to the top of the array and larger values "sink" to the bottom) worst case: O(n^2) Generally gives the worst performance unless the array is nearly sorted

Insertion Sort

Each items is take in turn, compare to the items in a sorted list and placed in the correct position. worst case: O(n^2) Gives best performance for most arrays, as it takes advantage of any partial sorting in the array and uses less costly shifts


Related study sets

Med-Surg: Lewis: Chapter 28: Lower Respiratory Problems: FOCUSED: Tuberculosis, Pertussis, and Pneumonia

View Set

Новые слова 2-2 «Домашние проблемы»

View Set

Chapter 2: The Project Management and Information Technology Context

View Set

High-Risk Neonatal Nursing Care Olds Maternal-Newborn

View Set

HESI NCLEX-RN Comprehensive Review (Maternity)

View Set