Trees Flashcards

1
Q

What is a Tree?

A

A tree is a widely used abstract data type that represents a hierarchical structure with a set of connected nodes. Each node in the tree can be connected to many children, but must be connected to exactly one parent, except for the root node, which has no parent.

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

Components of a tree?

A

-A tree is an undirected and connected acyclic graph.
-There are no cycles or loops. Each node can be like the root node of its own subtree, making recursion a useful technique for tree traversal.

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

Neighbor

A

Parent or child of a node

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

Ancestor

A

A node reachable by traversing its parent chain

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

Descendant

A

A node in the node’s subtree

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

Degree

A

Number of children of a node

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

Width

A

Number of nodes in a level

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

Level/Depth

A

Number of edges along the unique path between a node and the root node

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

Binary tree

A

Binary means two, so nodes in a binary tree have a maximum of two children.

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

Complete binary tree

A

A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.

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

Balanced binary tree

A

A binary tree structure in which the left and right subtrees of every node differ in height by no more than 1.

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

In-order traversa

A

Left -> Root -> Right
Result: 2, 7, 5, 6, 11, 1, 9, 5, 9

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

Pre-order traversal

A

Root -> Left -> Right
Result: 1, 7, 2, 6, 5, 11, 9, 9, 5

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

Post-order traversal

A

Left -> Right -> Root
Result: 2, 5, 11, 6, 7, 5, 9, 9, 1

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

Binary search tree (BST)

A

In-order traversal of a BST will give you all elements in order.

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

Operation Big-O
Access
Search
Insert
Remove

A

Operation Big-O
Access O(log(n))
Search O(log(n))
Insert O(log(n))
Remove O(log(n))

17
Q
A