Week 7 Flashcards

1
Q

What is a tree?

A

It is a hierarchial data structure.

It is a collection of vertices(nodes) and edges(arcs)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a vertex? What is an edge?

A

A vertex is like a node. It contains data and pointer information.

An edge connects 2 vertices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How many descendants is a binary tree allowed. How about a Ternary tree?

A

A binary tree is allowed two.

A ternary tree is allowed three.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a parent node, a child node, a sibling and a leaf node?

A

Each node, except the root has only one node above it. It is called the parent node.

A node may have zero or more children, drawn below it.

Nodes with the same parent are called sibilings.

Nodes with no children are called leaf nodes. (Or terminal or external nodes).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a subtree? What is a forest? What is a level?

A

Any node can be the root of the subtree. A subtree consists of it and the nodes below it.

A set of trees is called a forest.

A tree consists of levels. The farther down you go, the higher the level.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is height (depth), and path length?

A

The height (depth) of a tree is the distance from the root to the nodes furthest away.

The path length is the total sum of edges from each node to the root.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a binary tree?

A

Are trees where every node has 0, 1, 0r 2 children.

Each node contains data, a left child pointer, a right child pointer, (a parent pointer which is optional).

It can be uni or bi directional.

Has a root pointer which points to the root node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are Binary Search Trees?

A

Also called ordered binary trees.

Are organized so that every left child is less than or equal to the parent node.

Every right child is greater than the parent node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the best case for a binary search tree?

What is the complexity for searching?

A

In the best case, the tree is balanced and the height is minimized.

This occurs when the height of the left and right subtrees of any node differ by no more than 1.

The complexity is O(log n).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the worst case for a binary search tree?

A

In the worst case, the tree degenerates into a linked list. Height is n-1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the approximate height of a balanced tree?

A

It is approximately log n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How is insertion done in a binary search tree.

A

Insertion requires a search of the existing tree to find the parent node of the new node.

New nodes are always added as leaf nodes.

If the tree is empty, then the new node becomes the root node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the two types of traversal in a binary search tree?

A

Depth first: recursively visits each node starting at the far left.

Breadth-first: starting at the highest level, move down level by level, visiting nodes on each level from left to right.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the complexity when a binary search tree is formed by inserting nodes in random input order?

A

It is O(logn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In a binary search tree, what happens when you delete a node with only one child?

A

Set the parent node’s child pointer to the child of the deleted node (Splice out the node).

Free the deleted node’s memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What happens in a binary search tree when you delete a node with two children?

A

Find the smallest node in the right subtree below the node to delete.

Splice out that node.

Substitute the spliced node for the deleted node, either by copying, or by adjusting pointers.

Free the deleted node’s memory.

17
Q

In depth first, what is preorder traversal?

A

Processes the node first, and then the left tree and the right tree.

18
Q

What is post order traversal in binary search trees?

A

We process the left subtree, then the right subtree, and then the node.