COP3530 Final

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

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

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

40

how many distinct BSTs can be created by inserting 3 distinct keys into a BST in all possible orders?

5 - draw it out and insert in different orders. No formula.

........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

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

5 6 10 20 40 22 21 25 23

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

A B+ tree has n=4, l=4. Its height is 2 (level 0,1,2). Whats the max # of unique keys that it can hold?

64 - not on exam

........40.............. ...../......\............ ..30.........70...... ............./.....\..... ..........65.....80.. .......................\... .......................90 What will be the level order of the AVL tree after rebalancing?

70 40 80 30 65 90

A B tree has n=4, l=4. Its height is 2 (level 0,1,2). Whats the max # of unique keys that it can hold?

79 - not on exam

4 / \ 5 8 / 1 This is a splay tree. Whats the root after we search for 8?

8

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 completely full B tree with n=3, l=10, height =2 (levels 0,1,2) can have how many unique keys maximum?

98 - not on exam

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.

Is this a valid AVL tree? 4 / \ 5 8 / 1

no

simple graph

no loops, no parallel edges

simple path

no repeated vertices

Can dijkstras input graph have negative weight edges?

no!

Which of the following can be modeled as a directed acyclic graph? G= {(V,E)} V= set of pages in the web, E= <A,B> A links to page B V= set of nodes in a social network, E= <A,B> A is a friend of B V= set of cities in a country, E= <A,B> there is a flight from A to B V= set of courses you should take, E= <A,B> A is a pre-req for B

only the last one -- WHY? V= set of courses you should take, E= <A,B> A is a prereq for B

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

Swaps neighboring items

Bubble Sort

We can use _________ for topological sort. BFS/DFS

DFS! It just puts it in reverse order, so place answers in a stack and pop off for correct order.

what data structures do you use for DFS and BFS on a graph?

DFS= stack BFS= queue

BST. What are the possible root elements after we delete "A"? ........A.......... ...../......\....... ..B.........C..... ....\......./...\.. .....D...E.....F.. F,E,C,D,B,A

E and D - the inorder successor/predecessor

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.

Kruskal's Algorithm

start by sorting the weights of the edges. Add minimum edge to set if it doesnt create cycle which we determine with union. O(E log E)

Prim's Algorithm

start with one vertex and add adjacent node with minimum weight to set if not already in. Adjacency matrix= O(V^2), adjacency list+heap= O(ElogV)

Suppose A is an array containing numbers in increasing order, but some number occur more than once. When using binary search for searching for a certain value which is correct it will always find last occurence of # it will always find first occurence of # sometimes it will find last, sometimes 1st, sometimes a value in b/w

the last one

the number that is the root of a huffman tree =?

the total num chars of the word

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

time to hash + get spot in linked list

Organize DAG in linear order

topological sort

Organize tasks in a linear order that allows us to complete them one at a time without violating any pre-reqs?

topological sort

BFS gives shortest path for ___________ graph

unweighted only. If weighted, we need to use prims or kruskals

dijkstras pseudocode

uses 2 sets. Set S is the vertices we've already determined shortest path. Set V-S we havent done yet. Uses relaxation technique

DFS for a graph

visit kids before siblings, implemented w stack ex. topological sort

BFS for a graph

visit siblings before kids, implemented with a queue

There are 3 questions from quiz 9 that had pictures of graphs so I couldn't include but review those

ya

do greedy algorithms always ensure optimal solution?

yaaaa! fast but not always right

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 a load factor of 0 possible?

yes

is this a valid AVL tree? D / \ A M / \ F Z

yes

What graph would be helpful for: soldering the shortest set of wires needed to connect a set of terminals on a circuit board and connecting a set of cities by telephone lines in such a way as to require the least amount of cable.?

MST

Splits the array into halves and sorts each half

Merge Sort

15 / \ 3 25 / \ / 1 8 23 Is this tree full?

No, because 25 only has one child

Heap Sort

Non-stable, in place sort which has an order of growth of NlogN. Requires only one spot of extra space. Works like an improved version of selection sort. It divides its input into a sorted and unsorted region, and iteratively shrinks the unsorted region by extracting the smallest element and moving it into the sorted region. It will make use of a heap structure instead of a linear time search to find the minimum. Dont know found this on quizlet

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)

What is the computational complexity of right rotating a bst at a given node in worst case? O(log n), O(n), O(n^2), 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)

in adj mat to check if 2 nodes are connected or to find out what node is adjacent to, time complexity =?

O(1) to see if connected- direct access O(|V|) to see what adjacent to, traverse row

std:unordered_set time complexity

O(1). I think O(n) for worst case

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

O(N)

whats the time complexity to see adjacent nodes in adjacency matrix?

O(V)

traversing graph complexity is?

O(V+E)

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)

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

O(log n)

std::set time complexity

O(log 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)

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)

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)

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

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

O(n+logm)

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(log n), O(n), O(n^2), O(n log n), or O(1)

O(n^2) (quadratic)

in adj list, to check if 2 nodes are connected or to find out what a node is adjacent to, time complexity=?

O(out-degree)

Partitions the array around a pivot

Quick Sort

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

Selection Sort

does brute force always ensure correct solution?

yuh not always fast tho

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

adjaceny matrix is good for sparce or dense graphs?

dense

DAG

directed acyclic graph

whats a priority queue again?

each node has some "prioirty" associated with it. Can implement with sorted/unsorted array. Sorted linkedlist. Or binary heap which is O(logn) and super cool!

a good hash function does what

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

If you have a good pivot for quick sort, how many recursive calls? Bad pivot?

good = log n calls, bad = n calls

which trees are freq used for compressing data transmission?

huffman

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

increased

As the load factor increases, what happens to performance?

it slows down

there were 2 qs from quiz 4 that i could not type bc trees

kk

........40.............. ...../......\............ ..30.........70...... ............./.....\..... ..........65.....80.. .......................\... .......................90 What operation is needed to balance the AVL tree?

left rotation

which is not an in place sorting algorithm?

merge sort

Which belong to the family omega (n^3*(log n))? n^3 (log(log n)) n! n^2+n n^3*log base3 n n^3 .00001n^4 100000

n! n^3 *log (base 3 n) .0001n^4

What are the 4 rules of red-black tree?

1) root is always black, 2) a red node must have black kids 3) the # of black nodes in any path from root to leaf must be the same 4) all nodes are red or black

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

10

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 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

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

What algorithm can we use to optimally compute the shortest path between 2 vertices in an unweighted graph? BFS, DFS, or both

BFS

Time complexity of finding shortest path

BFS = O(V+E) Dijkstra's = O(V^2) or O(E log V) if implemented w heap Bellman-Ford= O(VE) //can have neg weight

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

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

prims

at every step, choose the smallest weight from the current node. Similar to Dijkstras but prims is based on current node and dijkstras is based on starting node.

Whats the issue with open-addressing, linear probing?

clustering!

Minimum Spanning Tree (MST)

connects all the vertices together w/o cycles and w/ minimum weight. Implemented with prims and kruskals

you can use prims to find mst of a graph with what properties?

cyclic, weighted, undirected, connected

implement huffman tree with ?

priority queue

We can implement topoligcial sort with a ______________ queue/stack

queue! Place vertices with in-degree of 0 on the queue. When we dequeue them, subtract 1 from the in-degree of neighbors and repeat.

12 \ 19 / 16 This tree has a _________ imbalance and requires a ___________ rotation.

right-left right-left

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

separate chaining

kruskals

sort the weight of edges small to big and process starting at the smallest edge. Add edge to MST if it doesnt create a cycle. See if it creates a cycle by unioning the sets.

adjaceny list is good for sparse or dense graphs?

sparse

Relationship b/w # edges and vertices for dense and sparse graph

sparse: |E| < |V^2| dense: |E| =~ |V^2|

which trees are freq used to search freq used text in optimal times?

splay tree

How to check if parenthesis are balanced? array, stack, queue, linked list

stack


Kaugnay na mga set ng pag-aaral

Psych: Chapter 9 Legal Issues, Psych CH9

View Set

Health Assessment Final Review (Prep U)

View Set

Science 600 - Unit 5: Chemical Structure and Change Quiz 2: Periodic Table

View Set

A & P Biol 2401 anatomy 1 and lab chapters 8,9,10

View Set

Stress, Strain and Work Done Definitions

View Set

CHEM Midterm: Chemistry Period Elements, Chemistry Unit 1, Chemistry Unit 4 Test, Chemistry Unit 5&6, CHEM Significant Figures, Chem Ch 3&10

View Set

Exam Evolution and the diversity of life

View Set