Trees Flashcards
(49 cards)
What is a tree in data structures?
A hierarchical data structure consisting of nodes, with one root node and subtrees of children.
What is a binary tree?
A tree where each node has at most two children.
What is a binary search tree (BST)?
A binary tree where left child < parent < right child for all nodes.
What is a root node?
The topmost node in a tree.
What is a leaf node?
A node with no children.
What is an internal node?
A node with at least one child.
What is the depth of a node?
The number of edges from the root to the node.
What is the height of a node?
The number of edges on the longest downward path to a leaf.
What is the height of a tree?
The height of the root node.
What is a balanced binary tree?
A tree where the height difference between left and right subtrees is no more than 1.
What is a complete binary tree?
All levels are fully filled except possibly the last, which is filled left to right.
What is a full binary tree?
A binary tree where every node has either 0 or 2 children.
What is a perfect binary tree?
A complete binary tree in which all leaf nodes are at the same level.
What are the types of tree traversal?
Preorder, inorder, postorder, and level order.
What is preorder traversal?
Visit the root, then left subtree, then right subtree.
What is inorder traversal?
Visit the left subtree, then root, then right subtree.
What is postorder traversal?
Visit the left subtree, then right subtree, then root.
What is level order traversal?
Visit nodes level by level from top to bottom.
What is the time complexity of traversing a tree?
O(n), where n is the number of nodes.
What is a degenerate (or pathological) tree?
A tree where each parent has only one child, like a linked list.
What is the average time complexity for search in a BST?
O(log n) for balanced trees.
What is the worst-case time complexity for search in a BST?
O(n), when the tree is unbalanced.
What is a self-balancing binary search tree?
A BST that maintains a balanced structure automatically (e.g., AVL, Red-Black Tree).
What is an AVL tree?
A self-balancing BST where the balance factor of any node is -1, 0, or 1.