Csce 221 Exam 2 Quizlet

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

Deletion example (delete a position in root) (AVL) (2,4)/(2,3,4) tree delete 24 (10,15,24) / / \ \ (2,8) (12) (8) (27,32,35) / / \ / \ / \ / / \ \ x x x x x x x x x x x

(10,15,24) / / \ \ (2,8) (12) (8) (27,32,35) / / \ / \ / \ / / \ \ x x x x x x x x x x x delete 24, replace with 27 the in order next of kin (10,15,27) / / \ \ (2,8) (12) (8) (32,35) / / \ / \ / \ / / \ \ x x x x x x x x x x x

4. There is a unique red-black tree associated with a given 2-4 tree.

(a) False, Node 3 can have one red child to the right or to the left.

1. A subtree of a red-black tree is itself a red-black tree.

(a) False, the tree can contain red and black roots, thus it is possible for a red root to be picked as the root of the subtree. This inherently makes it not a red-black tree.

2. The sibling of an external node is either external or red.

(a) True, if a external node had a internal black sibling, then the property that all subnodes must have the same black depth is violated.

Select a sequence generated by the post-order traversal applied to the tree Exp_tree_quiz.png - 2 a 1 - 3 b + - 2 a - 1 + 3 b - + 2 - a 1 3 b

2 a 1 - 3 b +

The height of a 2-4 tree with n input items in the internal nodes is the largest when all nodes are - 2-node - 3-node - 4-node

2 nodes

Balance this AVL if it needs it REMOVE 5 10 / \ 5 20 / \ 15 25

20 / \ 10 25 \ 15

General rule of thumb of stack and Postfix is

Stack <- recieves all operations Queue, recieves all varaibles if two variables recieved from queue, pop one from stack

Can A R-B tree have two consecutive black nodes

T

Consider the BST 15 / \ 5 20 \ 7 Is the tree a valid Red-Black tree? Hint: Can you paint every node using two colors (red and black) in this way that the definition of the R-B tree is satisfied? (t/f)

T (sus)

Convert infix to postfix make a example

https://raj457036.github.io/Simple-Tools/prefixAndPostfixConvertor.html

create an example of infix to postfix check with answer

https://raj457036.github.io/Simple-Tools/prefixAndPostfixConvertor.html

Merge Sort How many recursive CALLS are required by this algorithm to reach the base case (= an array with one element)?

if the number of recursive steps is k = logn as A term of master theorm ^ k 2^k = 1 (terminating term) k = log n thus sum the nodes on each level & make a series out of it 2^0 + 2^1 + 2^2 ...+ 2^K 2^(k+1) - 1 k = logn 2*n-1

unbalanced Tree

linked list tree, the nodes banch out to one

(Red Black) Trees O(__) Operations for binary trees with n nodes search, insert, delete

log(n) the tree is organized and divided evenly, notice the similarity with AVL

The merge sort algorithm reaches the base case after a certain number of recursive steps. Select the number of the recursive steps for the merge sort. - nlog2n - log2n - n - 2^n

log2n

void Recur_fun(int n) { if(n > 0) { Recur_fun(n-1); cout << n << endl; Recur_fun(n-1); } } • What is the output of this function for n=3, n=4, n=5 .

n=3 is 7 n=4 is 15 n=5 is 31 2^n -1

The AVL balancing technique always generates a BST with height of order log2n (t/f)

t

What is the general process for balancing any AVL

take this for example REMOVE 5 10 / \ 5 20 / \ 15 25 label nodes in a-c in least to greatest ON THE SIDE WITH 3 / the most side a / \ 5 b / \ 15 c order them using the middle as a pivot like normal b / \ a c \ 15

root property RB

the root of a red black tree is black https://pages.cs.wisc.edu/~cs400/readings/Red-Black-Trees/

pick a recusive topic and do a example

do it

pick a random recurrence relation solve it

do on paper

3. There is a unique 2-4 tree associated with a given red-black tree.

(a) True, the nodes can be organized based off how many red children they possess. Node 4 has 2 red children, Node 3 has 1 red child, and Node 1 has no red children.

Convert this a/b*(c+(d-e)) A) postfix tree B) postfix FORM

* / \ (\) + / \ / \ a b c - / \ d e this is ab/cde-+*

draw a unbalanced tree height = ? # of operations = ?

1 / \ x 3 / \ x 4 / \ x 5 / \ x x height = n # of operations to processes nodes = O(n^2) <- arithmetic sum

Post Order traversal Tree do a example 30,60,70,50,25,28,10 30 / \ 25 60 / \ / \ 10 28 50 70

1 Recursively visit all nodes in the left subtree. 2 Recursively visit all nodes in the right subtree. 3 Process the root node.void BinaryNode::postOrderTraversal(TreeOperation& op){if (left != nullptr) left->postOrderTraversal(op); if (right != nullptr) right->postOrderTraversal(op); op.processNode(element);} 10,28,25,50,70,60,30 Binary Search Tree pdf

Red-Black Tree insert steps O(__) ? for n nodes

1) add the node 2) re-establish red-black properties O (logn)

Insertion in a AVL (2,4)/(2,3,4) tree Process, and Overflow Condition

1) try to put in the child of the node it belongs, if it cannot fit (trying to put a 5 th child in the node that can hold 4), overflow will occur thus the node will split A 32 is inserted but its A that causes the overflow every node after root can have 1-3 values, 4 is a overflow every node->child can have 2-4 values the 5th is overflow again (15,24) / / \ 12 18 (27,30,"32",35) / \ / \ / \ / \ \ X X X X X X X X A SPLIT (15,24,"32") / / \ \ 12 18 (27,30) 35 / \ / \ / \ \ / \ X X X X X X X X A

Balance this AVL if it needs it insert 15 5 \ 10

10 / \ 5 15 shift left

Balance this AVL if it needs it what shift? 15 / 10 / 5

10 / \ 5 15 right shift

Balance this AVL if it needs it REMOVE 25 20 / \ 10 25 / \ 5 15

10 / \ 5 20 / 15

How many recursive subproblems are solved by the merge sort algorithm applied to a sequence of n elements? - 2^(n/2) - 2^(log2n) - 1- 2^n - 1- n/2

2^(log2n) - 1

How many external children has an internal node with two items? - 2-children - 3-children - 4-children

3-children

How many operations does it take to solve all sub-problems of the size during the second recursive call of the algorithm? T(n) = 9T(n/3) + n and T(1) = 0- n- 3n- 9n- 27n

3n

draw a balanced tree height = ? # of operations = ?

4 / \ 2 7 / \ / \ 1 3 6 8 / \ / \ / \ / \ x x x x x x x x height is 3 # of operations : sum i = 1 to n of log i <= n*logn

During the insertion operation in 2-4 tree an overflow could occur in - 2-node - 3-node - 4-node

4-node

The height of a 2-4 tree with n input items in the internal nodes is the smallest when all nodes are - 2-node - 3-node - 4-node

4-node

Draw a Proper height = ? # of operations = ? nodes? internal nodes? external nodes?

5 / \ 3 x / \ 2 x / \ x x note this example has it unbalanced if its balanced its a sum < n log n height = 3 # of operations = O(n^2) nodes = 7 internal nodes = 3 ( n (internal) <= (height - 1) / 2 external nodes = 4 ( n (external) <= 2 ^ (height) )

What is the total number of the subproblems solved by the recursive algorithm? T(n) = 9T(n/3) + n and T(1) = 0

81

How many sub-problems are formed by the recursive algorithm at each recursive call? Provide the answer based on the recurrence relation. T(n) = 9T(n/3) + n and T(1) = 0

9

O(__) Height of Red-Black Trees

A Red-Black tree with n internal nodes has height (theta)(logn)

what is a balanced tree define depth define height

A tree where all the nodes have the same depth, and balanced is determined by the children of the node picked depth = how far from root height = how far from the last children balance is (L-R) 2 2 has a balance of (1 - 1) = 0 / \ 4 5 4 has a balance of (0-0) = 0

A B C*+ D/ Convert to prefix

A+B*C/D

AVL's must ALWAYS be what

BALANCED

For a R-B tree to be True what conditions must be met

Balanced Same # of black nodes not counting root on each side

# of operations balanced bst # of operations unbalanced bst

Balanced bst O(nlogn) Unbalanced bst O(n^2)

Describe a doubleLeft AVL rotation provide a example

BinaryNode* doubleLeft(BinaryNode* X) { X->right = singleRight(X->right); return singleLeft(X); }

Describe a doubleRight AVL rotation provide a example

BinaryNode* doubleRight(BinaryNode* X) { X->left = singleLeft(X->left); return singleRight(X); }

Describe a Single Left AVL rotation provide a example

BinaryNode* singleLeft(BinaryNode* X) { BinaryNode Y = X->right; X->right = Y->left; Y->left = X; return Y; }

Describe a single Right AVL rotation provide a example

BinaryNode* singleRight(BinaryNode* X) { BinaryNode Y = X->left; X->left = Y->right; Y->right = X; return Y; }

Master Theorem Cases what is there O(_) T(N) = a*T(n/b) + f(n^d) C1 : O(__) C2 : O(__) C3 : O(__)

C1 : O(n^[logba]) C2 : O[n^d*logb(a)] C3 : O(n^d)

Deletion (AVL) (2,4)/(2,3,4) tree two cases summarized and general process on how to handle them

Case 1): the deleted node has a adjacent node with 2 children Process: Merge the adjacent node (2 kids ) and the now null node , share the pointers to kids and take one from root. This goes from a 1 -> 2 pointers and a null -> 1 ptr to 2 -> 3 ptrs with root having one less Case 2): the deleted node has a adjacent node with 3/4 children Process: Take one from root to deleted node, add the additional pointer to the now not deleted node, take one from the adjacent and put into root, removing one child from the adjacent.

RB Case 1: double red check R

Case 1: x is a red sub node with red parent and its parents sibling is red, sol recolor middle two & root

Which sequence is generated by In-order traversal operation for the tree in Q7-I.pdf ? - D H F P V T M - D F H M P T V - M F D H T P V

D F H M P T V

TO DO void Recur_fun(int n) { if(n > 0) { Recur_fun(n-1); cout << n << endl; Recur_fun(n-1); } } What is the recurrence relation for the algorithm? How many sub-problems are formed by the algorithm? What portion of the input does each sub-problem receive? How many operations does it take to form the sub-problems? When does the algorithm stop splitting the problem? How many operations does it take to combine the solutions together?

DO TO DO!

Underflow (AVL) (2,4)/(2,3,4) tree

Deleting an entry from a node v may cause an underflow, where node v becomes a 1-node with one child and no keys

Merge Sort Use the big-O notation to estimate the number of comparisons done by this algorithm at each level of the recursive tree during the conqueror steps.

Dividing the array into half takes O(1) and it is log n levels of recursion to hit base case. Then it takes O(n) to remerge everything, meaning the upperbound is O(logn) with n merges O(n*logn)

Define a Red - Black Tree

Every node is either Red or Black if one node is red the children are black B / \ R R R / \ B B

What are extended Binary trees give examples

Extended Binary Trees are: A binary tree in which special nodes are added wherever a null subtree was present in the original tree so that each node in the original tree (adds like boxes) etc we've been using x's Binary Search, Empty set, One Node

T/F The AVL balancing technique always generates a BST with height of order log_2(n)?

F log2(n+1)

Is this a valid AVL 30 / \ 15 x / \ 10 x

False balances means no chains > than 3 this would need to balance to 15 / \ 10 30

Hash table Map implement Operations Find: Put: Erase: general Facts:

Find: 1 (expected) Put: 1 (expected) Erase: 1 (expected) general Facts: no order map methods simple to implement

Skip Lists Implement Operations Find: Put: Erase: general Facts:

Find: logn (high prob) Put: logn (high prob) Erase: logn (high prob) general Facts: randomized insertion simple to implement

AVL, (2,3,4) or a (2,4) tree Implement Operations Find: Put: Erase: general Facts:

Find: logn (worst case) Put: logn (worst case) Erase: logn (worst case) general Facts: a pain in the butt to implement

Fusion (AVL) (2,4)/(2,3,4) tree This is a Underflow and Fusion Demonstrate with example below u ( 9 , 14 ) / \ \ (2,5,7) w (10) v (91) / / \ \ / \ \ x x x x x x x

Fusion operation: we merge v with an adjacent sibling w and move an entry from u to the merged node v V has been deleted This is Case 1) [the adjacent siblings of v are 2-nodes] u ( 9 , 14 ) / \ \ (2,5,7) w (10) v (x) / / \ \ / \ \ x x x x x x x now we merge with w and u u ( 9 ) / \ (2,5,7) wv (10,14) / / \ \ / \ \ x x x x x x x notice W children preserved

When should a tree be a used

Hierarchy, structure of a organization, your computer files

Merge Sort How many recursive steps are required by this algorithm to reach the base case (= an array with one element)? When does merge sort pivot

Its based on the height of the tree, and it is the B term of the master theorem. put B^K and apply to end condition 2 ^ k = 1 k = log n thus log n pivot is always middle merge sort

Quick Sort (average Case) Prove it (what is it caused by) (Height) (tree operations) (show cascade)

L | R c^(hl) = 1/n | (1-c)^hr = 1/n hl = -log(base c) n | hr = -log(base 1-c) 1/n hl = -log(base c) n | hr = log(base 1/(1-c)) n n*c^2 + 2c(1-c)n + n*(1-c)^2 = 0 n operations

Merge Sort What is a run time recurrence equation for the merge sort algorithm to sort any input of size n? when does merge sort pivot

M(N) = 2(M/2) + n M(1) = 0 pivot is always middle merge sort

Find Solution to below Recurrence Relations 1) T(n) = 3*T(n/3) + O(n) T(1) = 0 2) T(n) = 3*T(n/3) + O(1) T(1) = 0 3) T(n) = 3*T(n/3) + O(n^2) T(1) = 0

Master Method MUST be used its a recurrence relation Master Theorem formula: T(n) = (N) = a*T(n/b) + f(n^d) Apply Variables to : n^(log(base b) a) 1) Case 2 : O(n logn) <- O[n^d*logb(a)] 2) Case 1 : O(n) <- n^[logb(a)] 3) Case 3 : O(n^2), C is 1/3 <= c < 1 <- O(n^d) C work below a*f(n/b) <= c*f(n) 3*f(n/3)^2 <= c*(f(n))^2 3*(n^2/9) <= c*n^2 3/9 <= c 1/3 <= c apply c < 1 condition!

Merge Sort (what does it do) 1) Recurrence Relation 2) how many sub problems formed 3) what portion of the input does each subproblem form 4) How many operations does it take to form the sub-problems 5) When does the algorithm stop splitting

Merge sort splits until there is 1 element, compares swaps then merges 1) T(n) = 2T(n/2) + n T(1) = 0 2) k = logn its A^ k = 1 where a is 2 3)half 4) O(n logn) its logn to split, then O(N) to remerge 5) T(1) = 0, log (n) steps

Uses for R-B Trees

Most of the self-balancing BST library functions like map and set in C++ (OR TreeSet and TreeMap in Java) use Red-Black Tree. It is used to implement CPU Scheduling Linux. Completely Fair Scheduler uses it. Besides they are used in the K-mean clustering algorithm for reducing time complexity. Moreover, MySQL also uses the Red-Black tree for indexes on tables.

Rules of (2,3,4)/(2,4) Trees Node-Size, Depth, Conditions for Node Size

Node-Size Property: every internal node has at most four children Depth Property: all the external nodes have the same depth Depending on the number of children, an internal node of a (2,4) tree is called a 2-node, 3-node or 4-node

Binary Search Tree Operations Runtime? (Search, Insert, Delete)

O(H) H is height height is bounded by logn <= height <= n

The expected number of comparisons for the delete operation in a skip list is - O(1) - O(log2n) - O(n) - O(nlog2n)

O(log2n)

The number of comparisons for unsuccessful search in a 2-4 tree is - O(log2n) - O(n) - O(nlog2n)

O(log2n)

Balanced Search Trees Operations O(__) n nodes insert, search, delete,

O(logN) all Online some say insertion O(n) notes say different

Merge Sort Tree Height O(__)

O(logn)

O(__)? of INORDER TRAVERSAL a R-B tree

O(logn)

How do you do a Rotation in RB tree O(__) of rotation

O(logn) p1 b(y) / \ r(x) 3 / \ 1 2 Right Rotation (T,y) r(x) / \ 1 b(y) / \ 2 3

What is the number of comparisons to build a R-B tree with n nodes

O(n log n)

solve recurrence relation for Quick Sort Best Case

O(n logn)

What is the number of comparisons done by the merge sort on an input which is already sorted? Provide a solution using big-O asymptotic notation.

O(n logn) Josh's rational merge sort is not smart enough to do a precursor check -wikipedia best case is also O(nLogn)

The number of operations to extract sorted data from alredy existing red-black tree is:

O(n)

The number of comparisons for building an AVL tree with n items is:

O(n*logn)

The number of comparisons for building an Red-Black tree with n items is:

O(n*logn)

The number of comparisons for building an AVL tree with n items is: - O(log2n) - O(n) - O(nlog2n) - O(n^2)

O(nlog2n)

Merge Sort Runtime O(__) when does merge sort pivot, how does it affect the runtime (worst,best,average)

O(nlogn) pivot is always middle merge sort all O(nlogn)

Merge Sort the big-O notation to provide running times for the best, average and worst cases for this algorithm.

O(nlogn) pivot is always middle merge sort

Post order O(__) give balanced and unbalanced

O(nlogn) balanced O(n^2) unbalanced

Analysis Deletion (AVL) (2,4)/(2,3,4) tree Process of Deletion let T be a tree with N nodes height of T: O of Deletion O of Fusion O of Transfer

Process of Deletion: visit O(logn) nodes, find thing to delete, delete, O(logn) fusions, followed by@ most one transfer Height: logn Deletion: O(log n) Fusion: O(1) Transfer: O(1)

Preorder traversal Tree do a example 30,60,70,50,25,28,10 30 / \ 25 60 / \ / \ 10 28 50 70

Process the root node. 2 Recursively visit all nodes in the left subtree. 3 Recursively visit all nodes in the right subtree. //this is a continuation of the struct BinaryNode//TreeOperation is a class//with one function: processNode()void BinaryNode::preOrderTraversal(TreeOperation& op){ op.processNode(element); if (left != nullptr) left->preOrderTraversal(op); if (right != nullptr) right->preOrderTraversal(op);} 30,25,10,28,60,50,70 Binary Search Tree pdf

recurrence relation for Quick Sort Best Case

Q(n) = 2*Q(n/2)+ n Q(1) = 0

recurrence relation Quick Sort (worst case)

Q(n) = Q(n-1) + n Q(1) = 0

Write a sorting algorithm based on a R-B tree

Quicksort (the one where you select the pivot randomly/just pick one fixed, making worst case Omega(n^2)) might be better than Red-Black Trees because (not necessarily in order of importance)

Recurrence Relation for void Recur_fun(int n) { if(n > 0) { Recur_fun(n-1); cout << n << endl; Recur_fun(n-1); } }

R(N) = 2R(n-1)+O(1) R(0)=1

inorder traversal Tree do a example 30,60,70,50,25,28,10 30 / \ 25 60 / \ / \ 10 28 50 70

Recursively visit all nodes in the left subtree. 2 Process the root node. 3 Recursively visit all nodes in the right subtree. void BinaryNode::inOrderTraversal(TreeOperation& op) {if (left != nullptr) left->inOrderTraversal(op); op.processNode(element); if (right != nullptr) right->inOrderTraversal(op);} 10,25,28,30,50,60,70 Binary Search Tree pdf

Height of a RB tree NOT counting black height just general n nodes

Red Black Tree with n nodes has height <= 2Log2(n+1)

Size of a Tree

S(t) = 1 + S(L) + S(R) Sl is size of left, S(R) is size of right

What is the recurrence relation equation for the merge sort algorithm? - T(n) = T(n/2) + O(n) and T(1) = 0 - T(n) = T(n/2) + O(nlog2n) and T(1) = 0 - T(n) = 2T(n/2) + O(n) and T(1) = 0 - T(n) = T(n/2) + O(nlog2n) and T(1) = 0

T(n) = 2T(n/2) + O(n) and T(1) = 0

Quick Sort (average Case) Prove it (what is it caused by) (Recurrence Relation) (O(_) case)

T(n) = T(cn) + T((1-c)n)+O(1) T(1) = 0 this requires the height and the recurrence relation to find the n case hr * n = hr * n O(n log n) PRINT THE FORMULA SHEET MATH BACKGROUND

Create a Factorial Recurrence Relation

T(n) = T(n-1) + 1 T(0) = 1 <- unconfirmed but the idea was 0! = 1

Quick Sort Worst Case Prove it (what is it caused by) (Recurrence Relation) (O(_) case)

T(n) = T(n-1)+n T(1)=0 O(n^2) quick sort divides into halfs, this WORST CASE occurs if you pick an element that is the LEAST or the MOST element https://canvas.tamu.edu/courses/136654/files/35930553?wrap=1

Quick Sort (best case) Prove it (what is it caused by) (Recurrence Relation) (O(_) case)

T(n) = T(n/2)+T(n/2)+n = simplify 2T(n/2)+n T(1) = 0 O(n*logn) // remember you do up to the 2^k step then set 1 = 2^k and solve for n as n = 2^k The best case is caused by picking the middle value

Master Theorem Formula plug into what? When is it C1, C2, C3 C3 special case here :)

T(n) = a*T(n/b) + f(n^d) Apply Variables to : n^(log(base b) a) C1 : if n^(log(base b) a) is polynomically > f(n) C2 : if n^(log(base b) a) is polynomically = to f(n) C3 : if n^(log(base b) a) is polynomically < f(n) C3: Special Case c as constant, c < 1! a*f(n/b) <= c*f(n)

pick a random topic do a example 1

do it

How many children can the root of a 2-3-4 tree have how many values can the children have? how many children of root->children they have?

The root can have infinite children the children can have 1-3 values internally stored the root->children can have 2->4 children

RB tree property 4

The same # of black nodes from root to leaf

Is this a example of Insert AVL (2,4)/(2,3,4) tree Algorithm put(k, o) 1. We search for key k to locate the insertion node v 2. We add the new entry (k, o) at node v 3. while overflow(v) if isRoot(v) create a new empty root above v v ¬ split(v)

True

T/F are the leaves (RB) tree (external nodes) Null

True

is this AVL balanced 15 \ 6

True

How do you determine the height of a Red Black Tree

Use the black height Geeks for geeks Black height of the red-black tree is the number of black nodes on a path from the root node to a leaf node. # of nodes black nodes on the path from x (where x is the node picked, not counting x) to the leaf the height of a RB tree is the # of all black nodes to the root dont count current

Transfer (AVL) (2,4)/(2,3,4) tree This is a Underflow and Transfer Demonstrate with example below V is deleted u ( 4 , 9 ) / / \ (2) w ( 6 , 8 ) v ( 10 ) / \ / \ \ / x x x x x x

We deleted a node and there was no children left Now we see that This is a Case 2) as w (adjacent to v) is a 3/4 child bearer thus, 9 from u is pulled down to v, 8 from w is sucked up to 9, 9 brings a node child to v V is deleted u ( 4 , 9 ) / / \ (2) w ( 6 , 8 ) v ( x ) / \ / \ \ / x x x x x x u ( 4 , 8 ) / / \ (2) w ( 6 ) v ( 9 ) / \ / \ / \ x x x x x x 1. we move a child of w to v 2. we move an item from u to v 3. we move an item from w to u

2-4 tree can node 4 (typically holding 3 values) have (2 values) and if so how many children will it have

Yes, and 3 kids, if the node has X value, it will have x+1 kids X range (1-3)

what is a root

a child without a node

Formula for Height of a RB tree

a red-black tree of height h has black height >= h/2.

What is a (2,4) or a (2,3,4) tree? What do its nodes and keys hold?

a way to search multiple things and organize it by the # of children they have n For a node with children v1 v2 ... vd storing keys k1 k2 ... kd-1 w keys in the subtree of v1 are less than k1 w keys in the subtree of vi are between ki-1 and ki (i = 2, ..., d - 1) w keys in the subtree of vd are greater than kd-1 n The leaves store no items and serve as placeholders

Use a tree (a/b)*(c+(d-e) to post fix and what is the post fix

ab/cde-+* // rule of thumb here is the two elements to the LEFT of the operand apply to the WHOLE operand, start in middle https://raj457036.github.io/Simple-Tools/prefixAndPostfixConvertor.html

What is a tree

abstract data model of hierarchy and structure, consist of parent and child nodes

RB Tree insert Node color

assume the nodes inserted are red

Build R-B tree using the sequence: 26, 13, 17, 36, 46, 56 state the cases 1-3 you used and why

b(17) / \ b(13) r(36) / \ b(26) b(46) \ r(56)

Preform a Left Rotation(T,x) on this RB tree b(y) / \ r(x) 3 / \ 1 2

b(y) / \ r(x) 3 / \ 1 2

A Red-Black tree is what type of Tree

balanced / (AVL) potentially

What color are the external nodes of a RB tree

black

Number of Operations in a BALANCED tree draw one as a visual

count nodes summation bounded upper by node * lower bound i = 1 summing log i <= n logn * ( this could be n-1 like unbalanced was)

Number of Operations in a UNBALANCED tree draw one as a visual

count nodes (if your count starts at 0 remove -1 likely terrible idea though) sum bounded upper by nodes lower bound i = 1 summing i as it counts to n-1 this becomes a simple arithmetic sum (n-1)(n) / 2 and thus O(n^2) note this and the balanced are bounded by the same, the need is to remove the log(0) case

Define Deletion (AVL) (2,4)/(2,3,4) tree

delete the node either root or the nodes off the root, but not the root->node->kids else delete in replace the data in the root we need

Which rotation should be used to fix the property of AVL tree below? 7 / 4 \ 5 Hint:Double left - two rotations: the first right above the child of the pivot, the second left above the pivot.Double right - two rotations: the first left above the child of the pivot, the second right above the pivot.- single left- single right- double left- double right

double right

rule 4 red black trees (black external) nodes

each external node (guarenteed to be black) must have the same depth ( # of black nodes above it)

What is a proper Tree

each node has 2 children nodes

Is the merge sort an in-place algorithm? (t/f)

f

sum = 0; for (int i = 1; i < n; i*=4) sum = sum + 1; - f(n)=2log2n+1 and f(n)=O(log2n) - f(n)=2log2n+3 and f(n)=O(log2n) - f(n)=2log4n+1 and f(n)=O(log2n) - f(n)=2log4n+3 and f(n)=O(log2n)

f(n)=2log4n+1 and f(n)=O(log2n) (sus)

Sorting algorithm based of BST How do you tell which O( ) to use for traversal, how many operations?

first question is it balanced or unbalanced balanced : O(n log n) <- check knowledge with summation as proof (term-36) unbalanced : O(n^2) <- check knowledge with summation as proof (term-31) Run in order traversal = O(n) O(n logn) + O(n) = O(n logn) best case O(n^2) + O(n) = O(n^2) worst case

Height of a (2,4)/(2,3,4) Tree

h = O(Logn) where n is number of items stored. proof Let h be the height of a (2,4) tree with n items Since there are at least 2i items at depth i = 0, ... , h - 1 and no items at depth h, we have n ³ 1 + 2 + 4 + ... + 2^h-1 = 2^h - 1 Thus, h £ log (n + 1)

Proper tree formula height BOTH

h >= log(n+1)-1 (bc number external (leaves) = (n+1)/2 and h<=number internal nodes <= (n-1)/2 as number internal nodes = (n-1)/2

Build AVL tree using the sequence: 26, 13, 17, 36, 46, 56. height?

height = 3 36 / \ 17 46 / \ / \ 13 26 x 56 / \ / \ / \ x x x x x x source on disc as RB Tree example

[ (2,4)/(2,3,4) tree] If T is a AVL Tree of n items: what is the height? What is the # of steps and they're operations for insert

height is log n 1) step (log n) <- visit all nodes [guess (find pos)] 2) step O(1) <- takes one time [guess call new] 3) step (log n) <- split here for each [log n]

IF STRUGGLING WITH AVLS, BALANCING , (2,3,4),(2,4) USE THIS

https://canvas.tamu.edu/courses/136654/files/35930558/download

do a AVL example

https://canvas.tamu.edu/courses/136654/pages/avl-trees?module_item_id=4723237

do a inorder traversal BST

https://canvas.tamu.edu/courses/136654/pages/binary-trees?module_item_id=4723231

do a post order traversal BST

https://canvas.tamu.edu/courses/136654/pages/binary-trees?module_item_id=4723231

do a preorder traversal BST

https://canvas.tamu.edu/courses/136654/pages/binary-trees?module_item_id=4723231

Build a binary expression tree starting from its postfix form using a stack. Illustrate all the merging steps during the construction of the tree.

https://canvas.tamu.edu/courses/136654/pages/linked-lists?module_item_id=4723217

build a bst to postfix using stack p2

https://canvas.tamu.edu/courses/136654/pages/linked-lists?module_item_id=4723217

Build a 2-4 tree state overflow, underflow and fusion

https://canvas.tamu.edu/courses/136654/pages/multiway-and-2-4-trees?module_item_id=4723236

do a build a 2-4 tree example label overflow and underflow, fusion deletions

https://canvas.tamu.edu/courses/136654/pages/multiway-and-2-4-trees?module_item_id=4723236

pick a recursion example

https://canvas.tamu.edu/courses/136654/pages/recursion-the-classification-of-recursive-algorithms?module_item_id=4723225

build a avl with input

https://canvas.tamu.edu/courses/136654/pages/red-black-trees?module_item_id=4723235

build a red-black with input

https://canvas.tamu.edu/courses/136654/pages/red-black-trees?module_item_id=4723235

Draw a Full Tree height = ? # of operations = ? nodes? internal nodes? external nodes?

note how a full tree is a proper tree square is a rhombus here 4 / \ 2 7 / \ / \ 1 3 6 8 / \ / \ / \ / \ x x x x x x x x height = 3 # of operations : sum i = 1 to n of log i < = log n nodes = 15 internal nodes = 7 external nodes = 8

what are external nodes, and what are they in a R-B tree

null ptrs in a red black tree they will be red children

Proper tree formula number of leaves (external nodes) eq 2

number external nodes <= 2 to the height

Proper tree formula for number of leaves (external nodes) eq 1

number external nodes = number internal +1

Use the obtained binary tree to evaluate the expression for x = 2 and y = 4. Which tree traversal operation should be used?

post traversal Geeks for geeks

describe this tree in preorder: postorder: inorder: height: internal nodes: external nodes: number operations: 9 / \ 7 10 / \ / \ x 8 x 13 / \ / \ x x x x

preorder: 9 , 7 , 8 , 10 , 13 postorder: 8 , 7 , 13 , 10 , 9 inorder: 7 , 8 , 9 , 10 , 13 height: 3 internal nodes: 5 * external nodes: 6 * number operations: balanced tree sum upper bound n lower bound i = 1 summing log 2 i which is < = n log n * O(n logn) * means unconfirmed but likey

Build a red-black tree according to the algorithm provided on the lecture slides using the sequence: 26, 13, 17, 36, 46, 56. What is the root and height of the tree? Include the edges to the external nodes. - root=46, height=5 - root=26, height=4 - root=36 , height=3 - root=17, height=4

root=36 , height=3

Which rotation should be used to fix the property of AVL tree below? 1 \ 2 \ 3 Hint: Single right Single left Double left - two rotations: the first right above the child of the pivot, the second left above the pivot. Double right - two rotations: the first left above the child of the pivot, the second right above the pivot.

single left

Which data structure listed below is non-deterministic? - Linked lists - AVL trees - 2-4 trees - Skip lists

skip lists

Stack and queue ADT and their implementations using linked lists.

stack, implemented with top being the head, push being new node@ to the top of the stack, pop deletes the top queue first node is the first pos, push pushes to the back

Balance this AVL if it needs it INSERT 10 15 / 5

step 1 15 / 10 / 5 step 2 10 / \ 5 15

Balance this AVL if it needs it INSERT 10 5 \ 15

step 1 5 \ 10 \ 15 step 2 10 / \ 5 15

Evaluate the statement, "Every AVL tree is a Binary Search Tree (BST)". (t/f)

t

Is this recursive function correct? int sum(int n) {if (n == 0) return 0; return (n - 1) + sum(n);} (t/f)

t

RB Case 3: black property shifter Left child case, explain case and how to fix

the sibling of the parent is black, and parent and LEFT child share color (red), Right shift occurs move child up, child parent up, root down right, root->right one more right root is still black, root->left is red, root->right is red, root->right->right is black

RB Case 2: double red check L

the sibling of the parent is black, and parent and RIGHT child share color (red), then a shift of child <- and parent contains old child data (last bit sus)

POST FIX a/b*(c+(d-e)) using a STACK

this was too long to type out https://canvas.tamu.edu/courses/136654/pages/binary-trees?module_item_id=4723231

What is the InOrder Traversal Sequence for a R-B Tree describe it process no O(__)

traverses based on the lowest value of the subtree structure then goes back to parent https://www.youtube.com/watch?v=TOyxaFusqg0

Merge Sort (describe process no n's etc) How is the division of an array/subarray done by this algorithm during the partition steps?

use the 1/2 point, pivot, check size, if 2 sort, merge

Which case of the quick sort algorithm cannot be solved by the Master method? - best - worst - average

worst

Convert an algebraic expressions from infix to its post fix form using queue and stack. For example, (x + y)^2+ (x −4)/3.

x y+2^ x − 43/+ https://raj457036.github.io/Simple-Tools/prefixAndPostfixConvertor.html

The postfix form for the expression: x + y - z + t is

xy + z - t +

should a tree be used here to convert (a/b)*(c+(d-e) to post fix

yes, queue implemented tree

Does R-B Black Height depend on the nill black nodes

yes, the nill black nodes are the external leaves

Is a R-B tree AVL (assume balancing factor applied to every node)

yes?


Conjuntos de estudio relacionados

Construction Management 1011 Don Schneider Midterm

View Set

11th Grade Anatomy Human Skeletal System Part 2 Notes

View Set

Reconstruction & Southern Redemption

View Set

Exam "Networks and The Internet"- past Video Q's

View Set

Civil War and Reconstruction Test

View Set

Health Insurance Policy Provisions

View Set

communication studies- verbal and non verbal communication

View Set

Why are cells small and SA/ volume concept

View Set

Med Surg - Chapter 40 - Care of Patients with Hematologic Problems

View Set