• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/30

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

30 Cards in this Set

  • Front
  • Back

What is a red/ black tree?

A balanced binary search tree such that:


-all nodes are either red or black


-root is black


-leaves all point to null


-all nulls are black (same as root)


-all red nodes have at only black children (0-2)

What's a critical property of red/black trees?

The path from the root to the furthest leaf is no more than twice the length of the path from the root to the closest leaf,

What is the average case time complexity to access a red/black tree?

O(log(n))

What is the worst case time complexity to access a red/black tree

O(log(n))

What is the average case time complexity to search a red/black tree

O(log(n))

What's the worst case time complexity to search a red/black tree?

O(log(n))

What's the average case time complexity to insert into a red/black tree?

O(log(n))

What's the worst case time complexity to insert into a red/black tree?

O(log(n))

What's the average case time complexity to delete from a red/black tree?

O(log(n))

What's the worst case time complexity to delete from a red/black tree?

O(log(n))

What's the worst case space complexity?

O(n)

What's a left-leaning red/black tree?

A red black tree such that:


-If a node is red, it is the left child of it's parent


-on any root-null path, no more than two consecutive nodes are red


-all root-null paths have same number of black nodes

what's an n-ary tree?

A tree where every parent has at most n children

How do you contruct a tree?

nodes with a link to parent and links to any/all children

What's bfs?

Breadth first search. Explores all of the nodes at height k before moving to nodes at height k+1

What's dfs?

Depth first search. Explores all of the nodes on a root-null path, maintaining maximum height k at every choice.

What's inorder?

When doing depth first search, you first traverse the left subtree by recursively calling the in-order function, then display the data of the root, then traverse the right subtree by recursively calling the in-order function

What's preorder?

When doing depth first search you display the root first, then traverse the left subtree recursively calling pre-order, then traverse the right subtree recursively calling pre-order

What's postorder

When doing depth first search you traverse the left subtree recursively calling post order, then the right subtree recursively calling post order, then display the data of the root element.

What is a splay tree?

A binary tree such that nodes that are accessed frequently are near the root, because every time a node is accessed the splay operation is called

What is avl tree

A binary tree such that the heights of the two child subtrees of any node differ by at most one.

What is trie tree?

It's a tree that stores the prefix of the current value in the parent. For exameple.


t


r h


e y e


e

What's the result for right rotate on a binary search tree:


------------y-


------x--------gamma


alpha beta

result should be


-------------x-


-------alpha -y-


------------beta gamma


Write some pseudo code for left rotate on a bst


-------------x-


-------alpha -y-


------------beta gamma

y = x.right


x.right = y.left


if y.left != NULL, y.left.p = x


y.p = x.p


if x.p == NULL, T.root = y


elseif x == x.p.left, x.p.left = y


else x.p.right = y


y.left = x


x.p = y

What's the result for left rotate on a BST


-------------x-


-------alpha -y-


------------beta gamma

------------y-


------x--------gamma


alpha beta

Write some pseudo code for right rotate on a bst



------------y-


------x--------gamma


alpha beta

x = y.left


y.left = x.right


if x.right != NULL, x.right.p = y


x.p = y.p


if y.p == NULL, T.root = x


elseif y == y.p.right, y.p.right = x


else y.p.left = x


x.right = y


y.p = x

Write some pseudo code to insert into a r/b bst

insert(T,z)


y = T.nil


x = T.root


While x != T.nill


y = x


if z.key < x.ky, x = x.left


else x = x.right


z.p = y


if y == T.nil, T.root = z


elseif z.key < y.key, y.left = z


else y.right = z


z.left = T.nil


z.right = T.nil


z.color = red


Insert-Fixup(T, z)

Write some pseudo-code to fix the results of insert on a r/b tree

While x.p.color == red


if z.p == z.p.p.left,


y = z.p.p.right


if y. color == red


z..color = black


y.color = black


z.p.p.color = red


z = z.p.p


elseif z = z.p.right


z = z.p


left-rotate(T,z)


z.p.color = black


z.p.p.color = red


else (same as above ith right and left exchanged)


T.root..color = black

Write some pseudo-code to delete from a r/b tree

need to add

What's the difference between a bst and a heap?

In a max heap, the root is the max value and any children are less than that (opposite for a min-heap); in a bst, the left child is less than the shared parent is less than the right child.