Trees Flashcards

(50 cards)

1
Q

Define binary tree.

A

A tree data structure where each node has at most two children.

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

What is the height of a tree?

A

The length of the longest path from the root to a leaf.

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

True or false: A leaf node has no children.

A

TRUE

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

Fill in the blank: A full binary tree has ______ children per node.

A

Two

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

What does in-order traversal do?

A

Visits nodes in the left subtree, then the root, then the right subtree.

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

Define balanced tree.

A

A tree where the height of the left and right subtrees differ by at most one.

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

What is a leaf in a tree?

A

A node with no children.

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

True or false: A binary search tree allows duplicate values.

A

FALSE

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

What is the root of a tree?

A

The topmost node in a tree structure.

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

Fill in the blank: A complete binary tree is fully filled on all levels except ______.

A

The last level

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

Define traversal in trees.

A

The process of visiting all the nodes in a tree.

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

What is a sibling in a tree?

A

Nodes that share the same parent.

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

True or false: A binary tree can be unbalanced.

A

TRUE

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

What is the depth of a node?

A

The number of edges from the tree’s root to the node.

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

Fill in the blank: The maximum number of nodes at level ‘n’ is ______.

A

2^n

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

Define pre-order traversal.

A

Visits the root node first, then the left subtree, then the right subtree.

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

What is a binary heap?

A

A complete binary tree that satisfies the heap property.

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

True or false: A tree can have cycles.

A

FALSE

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

What is the degree of a node?

A

The number of children a node has.

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

Fill in the blank: A trie is a type of tree used for ______.

A

Storing strings

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

Define post-order traversal.

A

Visits the left subtree, then the right subtree, then the root node.

22
Q

What is a subtree?

A

A tree formed by a node and its descendants.

23
Q

True or false: Trees can be used to implement priority queues.

24
Q

What is the level of a node?

A

The number of edges on the path from the root to the node.

25
Fill in the blank: A **red-black tree** is a type of ______.
Self-balancing binary search tree
26
Define **B-tree**.
A self-balancing tree data structure that maintains sorted data.
27
What is the **order** of a B-tree?
The maximum number of children a node can have.
28
الجذر (Root):
أول عقدة تبدأ منها الشجرة، ولا يوجد عقدة أب لها.
29
الحافة (Edge):
الخط الواصل بين عقدتين.
30
الأب/الوالد (Parent):
العقدة التي لها أبناء.
31
الابن (Child):
كل عقدة منبثقة من عقدة أخرى.
32
الأشقاء (Siblings):
عقد لها نفس الوالد.
33
الدرجة (Degree):
عدد أبناء العقدة؛ أما درجة الشجرة فهي أكبر درجة بين كل عقد.
34
العقدة الداخلية (Internal node):
عقدة لها ابن واحد على الأقل.
35
عقدة ورقية (Leaf node):
عقدة بلا أبناء.
36
المستوى (Level):
المسافة من الجذر للعقدة (تبدأ من 0).
37
الارتفاع (Height):
أطول مسار من العقدة حتى أبعد عقدة ورقية تحتها.
38
العمق (Depth):
عدد الحواف من الجذر للعقدة.
39
الشجرة الفرعية (Subtree):
كل ابن يشكل مع أبناءه شجرة فرعية.
40
41
What is a **Full Binary Tree**?
A Binary Tree where every node has 0 or 2 children ## Footnote All nodes except leaf nodes have two children.
42
What defines a **Complete Binary Tree**?
All levels are completely filled except possibly the last level, which has all keys as left as possible ## Footnote Examples include trees where the last level is filled from left to right.
43
What is a **Perfect Binary Tree**?
A Binary Tree where all internal nodes have two children and all leaf nodes are at the same level ## Footnote This structure ensures maximum efficiency in tree operations.
44
In a **Binary Search Tree**, the value of the left node must be ______ the parent node.
smaller ## Footnote Conversely, the value of the right node must be greater than the parent node.
45
What are the steps for **creating a Binary Search Tree**?
* Insert root * Compare and place left or right based on value * Repeat for each element ## Footnote The example provided illustrates the insertion of specific values into the tree.
46
What are the steps for **searching in a Binary Search Tree**?
* Compare with root * Move left if smaller * Move right if larger * Repeat until found or return NULL ## Footnote This method leverages the ordered structure of BSTs for efficient searching.
47
What are the three possible situations for **deleting a node** in a Binary Search Tree?
* Leaf node: Remove it * One child: Replace with child * Two children: Replace with in-order successor/predecessor ## Footnote Each situation requires a different approach to maintain the BST properties.
48
What are the three main ways to **traverse a binary tree**?
* Pre-Order (Root -> Left -> Right) * In-Order (Left -> Root -> Right) * Post-Order (Left -> Right -> Root) ## Footnote Each traversal method serves different purposes, especially in BSTs.
49
In **In-Order Traversal** of a BST, what order do the nodes appear?
Ascending order ## Footnote This traversal method visits the left subtree, the root, and then the right subtree.
50