Mapa mental
Binary Search Tree
Conteúdo do mapa
Binary Search Tree
Hierarchical (non-linear) data structure
- Used to optimize data retrieval in ordered sets of numbers
- Node
- Left child (smaller than node)
- Right child (greater than node)
- Basic principle: left child < current node < right child
- General principle: left subtree < root node < right subtree
- Node
- Used to optimize data retrieval in ordered sets of numbers
Basic Concepts
- Root Node - first and uppermost node
- Leaves - Nodes without children Nodes
- Node - Object that contains an element
Inserting Elements
- Are there any elements in the BST?
- No - Create a root node with the new element!
- Yes!
- Is the new element smaller, equal, or greater than the current node?
- Smaller
- Is there a left child of the current node?
- No - Create a node with the new element as the left child of the current node!
- Yes - Compare new element to the left child!
- Is there a left child of the current node?
- Greater
- Is there a right child of the current node?
- No - Create a node with the new element as the right child of the current node!
- Yes - Compare new element to the right child!
- Is there a right child of the current node?
- If it is equal to the node, then you do not need to create a new node!
- Smaller
- Is the new element smaller, equal, or greater than the current node?
- Are there any elements in the BST?
Searching for Elements
- Are there any elements in the BST?
- No - The element cannot exist in the BST.
- Yes!
- Is the element you're search for smaller, equal, or greater than the current node?
- If it is equal to the node, then you have found the element!
- Smaller
- Is there a left child of the current node?
- Yes - Compare element to the left child!
- No - The element does not exist in the BST.
- Is there a left child of the current node?
- Greater
- Is there a right child of the current node?
- Yes - Compare element to the right child!
- No - The element does not exist in the BST.
- Is there a right child of the current node?
- Is the element you're search for smaller, equal, or greater than the current node?
- Are there any elements in the BST?
Informações
- Descrição
- Mapa Mental sobre Binary Search Tree, criado por Catherine P em 02-03-2021.
- Criado por
- Catherine P
- Visualizações
- 1
- Avaliação