Trees (OCR A-Level Computer Science): Flashcards
📚Flashcards
Practise the cards
15 cards from this deck
ShowHide
Practise the cards
15 cards from this deck
Tree data structure
Tree data structure
Hierarchical structure consisting of nodes
Root node
Root node
Topmost node in tree
Leaf node
Leaf node
Node with no children
Binary tree
Binary tree
Each node has at most two children (left and right)
Binary Search Tree (BST) property
Binary Search Tree (BST) property
Left child < parent, right child > parent
BST time complexity (balanced)
BST time complexity (balanced)
Array tree: left child of index
Array tree: left child of index
Array tree: right child of index
Array tree: right child of index
Post-order traversal order
Post-order traversal order
Left subtree → Right subtree → Root
Breadth-first traversal
Breadth-first traversal
Level by level, left to right
Adding node to BST process
Adding node to BST process
Start at root, traverse left if smaller/right if larger, insert at leaf
Removing BST node with no children
Removing BST node with no children
Remove it directly
Removing BST node with one child
Removing BST node with one child
Replace it with its child
Removing BST node with two children
Removing BST node with two children
Replace with in-order successor (smallest in right subtree)
Unbalanced BST performance
Unbalanced BST performance
Degrades to
