Binary Tree Flashcards

1
Q

What is a binary tree?

A

A binary tree is a data structure with nodes connected by edges, 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

How can a binary tree be represented?

A

A binary tree can be represented either as an array or as a linked structure.

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

What is the role of a node in a binary tree?

A

A node is an entity in a binary tree that stores data and maintains the parent-child relationships within the tree.

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

What is an edge in a binary tree?

A

An edge in a binary tree is a reference or connection between nodes.

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

What are the defining characteristics of a binary tree?

A

The defining characteristics of a binary tree are:

A single node, known as the root, serving as the starting point of the tree.
Each node in the tree has exactly one parent.
Each node in the tree can have at most two children: a left child and a right child.

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

What is the purpose of the Node class in Java?

A

The Node class in Java is designed to represent a node in a data structure, such as a binary tree, by storing data and maintaining references to its child nodes.

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

What is the significance of the leftChild and rightChild variables in the Node class?

A

The leftChild and rightChild variables in the Node class hold references to the left and right child nodes, respectively.

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

What is the purpose of the constructor in the Node class?

A

The constructor in the Node class is used to initialize a node with a given value and set the child node references to null.

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

How can you retrieve the data stored in a Node object?

A

The data stored in a Node object can be retrieved using the getData() method.

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

How can you modify the data stored in a Node object?

A

The data stored in a Node object can be modified using the setData() method.

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

What is a leaf node in a tree?

A

A leaf node in a tree is a node that has zero children.

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

What is an interior node in a tree?

A

An interior node in a tree is a node that has one or more children.

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

What is a subtree in a tree?

A

A subtree is a smaller tree that exists below a specific node in the main tree.

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

How is the level of a node defined in a tree?

A

The level of a node in a tree is determined based on its position within the tree hierarchy.

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

What is the height of a tree?

A

The height of a tree is defined as the maximum level among all the nodes in the tree.

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

How is the height of an empty tree defined?

A

The height of an empty tree is 0.

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

How is the height of a non-empty tree determined?

A

The height of a non-empty tree is calculated based on the maximum level among all the nodes in its two subtrees.

18
Q

How can the height and level of a tree be useful?

A

The height and level of a tree provide insights into its structure and can be used for various purposes, such as analyzing tree balance, determining traversal algorithms, and optimizing tree-related operations.

19
Q

What is a full binary tree?

A

A full binary tree is a type of binary tree where every internal node has exactly two children, and all leaves are at the same height.

20
Q

Can a full binary tree have only one node?

A

Yes, a single node can be considered a full binary tree.

21
Q

What are the key characteristics of a full binary tree?

A

The key characteristics of a full binary tree are:

Every internal node has exactly two children.
All the leaves are at the same height or level.

22
Q

How does a full binary tree differ from other binary tree types?

A

A full binary tree differs from other binary tree types in that it strictly adheres to the requirement of every internal node having exactly two children.

23
Q

What are the advantages of using a full binary tree?

A

Some advantages of using a full binary tree include efficient searching and insertion operations, balanced structure for optimal performance, and simplified traversal algorithms.

24
Q

What is a balanced binary tree?

A

A balanced binary tree is a type of binary tree where the heights of its left and right subtrees differ by no more than 1.

25
Q

What is the significance of a balanced binary tree?

A

A balanced binary tree ensures that the height of the tree is minimized, leading to efficient search, insertion, and deletion operations.

26
Q

How is the balance of a binary tree determined?

A

The balance of a binary tree is determined by comparing the heights of its left and right subtrees.

27
Q

What are the benefits of a balanced binary tree?

A

Some benefits of using a balanced binary tree include improved efficiency in search, insert, and delete operations, as well as more predictable performance.

28
Q

Can a binary tree be considered balanced if it has only one node?

A

Yes, a binary tree with only one node is considered balanced.

29
Q

What is a binary search tree (BST)?

A

A binary search tree is a type of binary tree in which the left child of a node is always less than the node, and the right child is always greater than the node.

30
Q

What is the significance of the ordering property in a binary search tree?

A

The ordering property in a binary search tree ensures efficient searching and allows for easy insertion and deletion of elements.

31
Q

How is the ordering property maintained in a binary search tree?

A

The ordering property is maintained through careful placement of nodes during insertion and deletion operations.

32
Q

Can a binary search tree contain duplicate values?

A

It depends on the specific implementation. In some implementations, duplicate values are not allowed, while in others, duplicate values may be permitted.

33
Q

What are the advantages of using a binary search tree?

A

Advantages of using a binary search tree include efficient searching, insertion, and deletion operations, as well as the ability to perform ordered traversals.

34
Q

What is the link representation of a binary tree?

A

The link representation of a binary tree is a commonly used representation where each tree node contains references to its left and right child nodes.

35
Q

What are the components of a tree node in the link representation?

A

In the link representation, a tree node typically consists of two references: one for the left child and one for the right child.

36
Q

What is the advantage of the link representation in a binary tree?

A

The link representation provides a more natural and intuitive way to represent and work with binary tree structures.

37
Q

How does the link representation differ from other representations of a binary tree?

A

The link representation differs from other representations of a binary tree, such as array-based or level-order representations, as it explicitly maintains references to left and right child nodes.

38
Q

What are some scenarios where the link representation of a binary tree is beneficial?

A

The link representation is beneficial in scenarios where efficient tree navigation, modification, or traversal is required. It is commonly used in algorithms related to binary search trees, expression trees, parsing, and other tree-based data structures and algorithms

39
Q

What are the different traversals used to visit nodes in a binary tree?

A

The different traversals used to visit nodes in a binary tree are:

In-order traversal
Pre-order traversal
Post-order traversal

40
Q

What is the in-order traversal of a binary tree?

A

In an in-order traversal, the left subtree is visited first, followed by the root node, and then the right subtree.

41
Q

What is the pre-order traversal of a binary tree?

A

In a pre-order traversal, the root node is visited first, followed by the left subtree, and then the right subtree.