Binary Tree Flashcards
What is a binary tree?
A binary tree is a data structure with nodes connected by edges, where each node has at most two children.
How can a binary tree be represented?
A binary tree can be represented either as an array or as a linked structure.
What is the role of a node in a binary tree?
A node is an entity in a binary tree that stores data and maintains the parent-child relationships within the tree.
What is an edge in a binary tree?
An edge in a binary tree is a reference or connection between nodes.
What are the defining characteristics of a binary tree?
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.
What is the purpose of the Node class in Java?
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.
What is the significance of the leftChild and rightChild variables in the Node class?
The leftChild and rightChild variables in the Node class hold references to the left and right child nodes, respectively.
What is the purpose of the constructor in the Node class?
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 can you retrieve the data stored in a Node object?
The data stored in a Node object can be retrieved using the getData() method.
How can you modify the data stored in a Node object?
The data stored in a Node object can be modified using the setData() method.
What is a leaf node in a tree?
A leaf node in a tree is a node that has zero children.
What is an interior node in a tree?
An interior node in a tree is a node that has one or more children.
What is a subtree in a tree?
A subtree is a smaller tree that exists below a specific node in the main tree.
How is the level of a node defined in a tree?
The level of a node in a tree is determined based on its position within the tree hierarchy.
What is the height of a tree?
The height of a tree is defined as the maximum level among all the nodes in the tree.
How is the height of an empty tree defined?
The height of an empty tree is 0.