Midterm 2

Ace your homework & exams now with Quizwiz!

greedy

A __________ algorithm is an algorithm which has: ●A set of partial solutions from which a solution is built ●An objective function which assigns a value to any partial solution

abstract tree (abstract hierarchy)

A _____________ does not restrict the number of nodes (degree) in the tree

2

A binary tree has a restriction where each node has exactly how many children? Each child is either empty or another binary tree

a full node or a leaf node

A full binary tree is where each node is ____________

Depth First (Traversal)

A path from backtracking is _____________________ traversal. ●At any node, we proceed to the first child that has not yet been visited ●Or, if we have visited all the children (of which a leaf node is a special case), we backtrack to the parent and repeat this decision making process ●We end once all the children of the root are visited

internal

All nodes other than leaf nodes are sad to be ________, that is they are _______ to the tree.

full or leaf

All red nodes are either _______ or ________ nodes? (Two different words)

Alternating (Lecture 11, slide, 14)

Any worst-case red-black tree must have ___________ color patterns down one side

recursion or a stack

Depth-first traversal can be implemented with ___________ or __________ (this one is a data structure)

unique (Lecture 13, Slide 11)

Divide-and-conquer approach is good if the sub-problems are essentially _________

binary search

For a red-black tree if we use top-down deletions we us a similar strategy as done in a _____________ tree: ●replace the node with the minimum element in the right sub-tree ●then delete that element from the right sub-tree

bottom-up

For red-black trees __________________ insertion inserts at the leaves

top-down

For red-black trees __________________ insertion inserts at the root

BFT visits all nodes at a given depth (each node is traversed level by level).

How does breadth first traversal(BFT) visit nodes? Remember BFT is potentially memory expensive.

(Caleb playing cricket noises on his phone)

How many of you remember Windows 3.1?

O(n)

If a binary search tree is close to a linked list structure what is its time complexity?

0 (Lecture 9, slide 4)

If a node is a leaf node, what is its degree?

black

If we have a perfectly balanced tree and the tree is red-black, then each node in the red-black tree is ______ (color)

Rotate (Easier to see on Lecture 11, slide 25)

If we insert a node (bottom-up) and its grandparent has one child, what function do we have to perform?

swap the colors (of the child nodes. This may cause issues with the parent and the grandparent)

If we insert a node (bottom-up) and its grandparent has two children, what function do we have to perform?

maximize

In a greedy algorithm, the target is to _____________ the total weight (minimize or maximize)

black and the corresponding children are red

In a red-black tree nodes with a single child are colored ___________ and the corresponding children are _________ Hint: Each blank is a different color

operating system (Lecture 12, slide 23)

In preemptive multitasking process scheduling, the ____________ _____________ controls access the processor. (2 words)

2k (This can also simplify to O(n), see Lecture 11, slide 20)

Let k represent the number of black nodes per null path, what will the height of a worst-case scenario red-black tree be? h=___________

null (Lecture 11, Slide 3)

Red-Black trees are used to define what type of path? Hint: This path is defined as any path from the root where the last node is not a full node (leaf node)

Why use a red-black tree instead of an AVL tree?

Red-black tree uses less memory

Ok

Review Lecture 11, Bottom-Up insertion examples

Ok

Review Lecture 11, Top-Down insertion examples

Linked List(s)

Rooted tree data structures are similar to _____________ because they share the following characteristics: • There is a first node/root • Each node has a variable number of references to successors • Each node except root has exactly one node point to it

Prove that if a node P has exactly one child, that node P must be black.

Since the child is a red leaf node, and the red-black tree rules require that a red node must have two black children, node P must be black, because it does not have two black children.

Prove that every red node must be either a full node or a leaf node

Suppose node S has one child L. The one child L must be black. The null path path ending at S has k black nodes. Any null path containing the node L will therefore have at least k + 1 black nodes.

Prove that if a node P has exactly one child, the child must be a red node.

Suppose that the child is black. Then the null path ending at P will have one fewer black nodes than the null path passing through C. This contradicts the requirement that each null path has the same number of black nodes. Therefore the one child must be red.

Prove that if a node P has exactly one child, the child must be a red leaf node.

Suppose the child is not a leaf node. Since it is red: its children can't be red because that would contradict the requirement that all children of a red node are black; and its children can't be black, because that would cause any leaf node under the child to have more black nodes than the null path ending in P. Therefore the child must be a leaf node.

False (Lecture 10, slide 10: If we insert an object already in the tree the program is supposed to return)

T/F: A binary search tree can contain duplicates.

False (Lecture 11, slide, 13)

T/F: A complete tree is a red-black tree if: • Each node at the lowest depth is colored black • All other nodes are colored black

False (The Dumbledore's Army problem from Lecture 12)

T/F: A greedy algorithm is ALWAYS the most optimal solution

True

T/F: After an bottom-up insertion is performed we must satisfy all rules of red-black tree.

True (Thus when we insert a node it must be red. We then travel up the tree to the root fixing the requirement that the children of a red node must be black.)

T/F: After inserting a node (bottom-up) that is black into a red-black tree we cause the balance of all other ancestor nodes to become unbalanced

False (For all nodes other than the root node there is one parent node)

T/F: Every Binary Tree node has a parent.

False (insertion happens at the leaf node)

T/F: For a binary search tree, an insertion will be performed at the parent node.

True

T/F: For a binary search tree, if we want to delete a leaf node (node that has no children). We can simply remove it from the list.

False (If a node we want to delete has only one child we can simply promote the sub-tree associated with the child)

T/F: For a binary search tree, if we want to delete a node that has one child. We can simply remove it from the tree.

False (If a node we want to delete has two children, we must search the right subtree of the minimum object and then promote it to the node we wish to delete.)

T/F: For a binary search tree, if we want to delete a node that has two children. We can promote a random child node.

True

T/F: For all Binary Tree nodes, each node will have zero or more children?

False (Lecture 9, Slide 5: Each node has a unique path from root node to that node)

T/F: For each node in a tree there are multiple paths from the root node to that node.

False

T/F: For red-black trees the root node must always be red.

False (Each null path must have the same number of black nodes)

T/F: For red-black trees, each null path must have the same number of nodes.

True

T/F: For red-black trees, if a node is red, both of its children must be black.

True

T/F: If a black node has one child, then the child must be red, the child must be a leaf node, and the parent must always be black.

True (Lecture 9, slide 3)

T/F: In a binary tree, nodes with the same parent are siblings.

False (We sort the processes by their deadlines)

T/F: In interval scheduling the first step is to sort the processes by their start times.

False (Our goal is to find tree structures where we can maintain a height of O(log(n))

T/F: Our goal will be to find tree structures where we can maintain a height of O(n)

True (Lecture 9, Slide 6)

T/F: The height of a tree is the maximum depth of any node within the tree

False (Time complexity for delete on BST is O(h))

T/F: The time complexity for deleting node in a binary search tree is T(n) = O(n)

True (Lecture 11, slide 19)

T/F: To determine the number of nodes in a worst-case tree we can use the formula: F(k) = F(k-1) + 2 + 2(2^[k-1] -1) F(k) = F(k-1) + 2^[k]

length (Lecture 9, Slide 5)

The ______ of a path is the depth of the node you are looking for

Breadth First Traversal

The following describes the implementation of ___________: • Create a queue and push the root node onto the queue • While the queue is not empty: ° Push all of its children of the front node onto the queue ° Pop the front node

processing unit (Lecture 12, slide 21)

The primary resource in any computer is the _____________ ______. (Two words)

2

What is the degree of the node marked 5?

O(h)

What is the memory required for Depth-first traversal?

O(h)

What is the runtime of insertion in a binary search tree?

O(n*log(n)) (This is the time required to sort the list.)

What is the time complexity for a greedy-by-"blank" algorithm? (i.e. a greedy-by-time, greedy-by-expected revenue)

O(n)

What is the time complexity of Breadth First Traversal (BFT)?

O(n)

What is the time complexity of Depth-first traversal?

Θ(n)

What is the time complexity of Memoized Greedy Interval Scheduling?

O(n^2)

What is the time complexity of Non-Memoized Greedy Interval Scheduling?

O(n)

What is the time complexity of a degenerate binary search tree, this essentially the same as having a linked list? Where all nodes are skewed to one side?

O(n)

What is the time complexity of an Abstract Sorted List that uses an array or a linked list? Remember: An insertion could occur anywhere in the linked list or array. Meaning we must traverse or copy on average ______ objects.

O(nlogn) (Lecture 12, slide 47)

What is the time complexity of an interval scheduling greedy algorithm implementation?

Θ(n)

What is the time complexity of iterative bottom-up interval scheduling?

O(h)

What is the time complexity of most all relevant operations on a binary search tree?

T(n) = Θ(F(n)) = Θ(2^n)

What is the time complexity of the algorithm to find Fibonacci sequence?

O(h) or O(log(n))

What is the time complexity of the find (search) function in a binary search tree?

O(nW)

What is the time complexity of the memoized dynamic programming solution to the knapsack problem?

O(h) or O(log(n))

What is the time complexity to find the min or max value in a binary search tree?

abstract tree (abstract hierarchy)

What type of tree is implemented by using a class that: • Stores a value • Stores the children in a linked-list

Find the count of all objects in the container (Lecture 10, Slide 23: This, along with other simple functions [insert, select, delete] is suggested to be implemented with a hashtable.)

Which of the following does not belong for operations specific to linearly ordered data: • Find the kth value of the container • Find the count of all objects in the container • Find the next largest and previous smallest object of a given object which may or may not be in the container. • Iterate through those objects that fall between an interval [a,b]

Euclidean GCD

Which of the following is NOT a divide and conquer algorithm: ●Binary search ●Depth-first tree traversals ●Merge sort ●Euclidean GCD ●Quicksort

Binary search tree (BST)

______ data types have the following properties: • The left sub-tree (if any) is a ________ where all values are less than the root value • The right sub-tree (if any) is a ________ where all values are greater than the root value

multiprogramming (Lecture 12, slide 22)

_________________ is defined as the ability to run processes in batches.


Related study sets

Microeconomics for Life | CH. 10

View Set

Chapter 16 Fair Housing Misrepresentation

View Set

Chemistry, Chapter 7: Chemical Reactions and Quantities

View Set

Economics Chapter 4 and 5/Mr. Holland's class

View Set

Anatomy Exam 3/Lecture 5-Temporal region

View Set