📓
Algorithms
  • Introduction to Data Structures & Algorithms with Leetcode
  • Strings
    • Dutch Flags Problem
      • List Partitoning
    • Counters
      • Majority Vote
      • Removing Parentheses
      • Remove Duplicates from Sorted Array
    • Maths
      • Lone Integer
      • Pigeonhole
      • Check If N and Its Double Exist
      • Find Numbers with Even Number of Digits
    • Two Pointers
      • Remove Element
      • Replace Elements with Greatest Element on Right Side
      • Valid Mountain Array
      • Sort Array by Parity
      • Squares of a Sorted Array
      • Max Consecutive Ones
    • Sliding Window
      • Max Consecutive Ones 3
    • Stacks
      • Balanced Brackets
    • General Strings & Arrays
      • Move Zeros
      • Unique Elements
      • Merge Sorted Array
    • Matrices
      • Valid Square
      • Matrix Search Sequel
  • Trees
    • Untitled
  • Recursion
    • Introduction
    • Backtracking
      • Permutations
  • Dynamic Programming
    • Introduction
    • Minimum (Maximum) Path to Reach a Target
      • Min Cost Climbing Stairs
      • Coin Change
      • Minimum Path Sum
      • Triangle
      • Minimum Cost to Move Chips to The Same Position
      • Consecutive Characters
      • Perfect Squares
    • Distinct Ways
      • Climbing Stairs
      • Unique Paths
      • Number of Dice Rolls with Target Sum
    • Merging Intervals
      • Minimum Cost Tree From Leaf Values
    • DP on Strings
      • Levenshtein Distance
      • Longest Common Subsequence
  • Binary Search
    • Introduction
      • First Bad Version
      • Sqrt(x)
      • Search Insert Position
    • Advanced
      • KoKo Eating Banana
      • Capacity to Ship Packages within D Days
      • Minimum Number of Days to Make m Bouquets
      • Split array largest sum
      • Minimum Number of Days to Make m Bouquets
      • Koko Eating Bananas
      • Find K-th Smallest Pair Distance
      • Ugly Number 3
      • Find the Smallest Divisor Given a Threshold
      • Kth smallest number in multiplication table
  • Graphs
    • Binary Trees
      • Merging Binary Trees
      • Binary Tree Preorder Traversal
      • Binary Tree Postorder Traversal
      • Binary Tree Level Order Traversal
      • Binary Tree Inorder Traversal
      • Symmetric Tree
      • Populating Next Right Pointers in Each Node
      • Populating Next Right Pointers in Each Node II
      • 106. Construct Binary Tree from Inorder and Postorder Traversal
      • Serialise and Deserialise a Linked List
      • Maximum Depth of Binary Tree
      • Lowest Common Ancestor of a Binary Tree
    • n-ary Trees
      • Untitled
      • Minimum Height Trees
    • Binary Search Trees
      • Counting Maximal Value Roots in Binary Tree
      • Count BST nodes in a range
      • Invert a Binary Tree
      • Maximum Difference Between Node and Ancestor
      • Binary Tree Tilt
  • Practice
  • Linked Lists
    • What is a Linked List?
    • Add Two Numbers
      • Add Two Numbers 2
    • Reverse a Linked List
    • Tortoise & Hare Algorithm
      • Middle of the Linked List
  • Bitshifting
    • Introduction
  • Not Done Yet
    • Uncompleted
    • Minimum Cost For Tickets
    • Minimum Falling Path Sum
Powered by GitBook
On this page
  • Binary Tree vs Binary Search Tree
  • Balanced vs Unbalanced
  • Complete Binary Tree
  • Full Binary Trees
  • Perfect Binary Trees

Was this helpful?

  1. Graphs

Binary Search Trees

A binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child

Binary Tree vs Binary Search Tree

A binary search tree is a binary tree in which every node fits a specific ordering property.

All left descendants ≤ n < all right descendants

This must be true for each node, n.

Basically, the entire left side must always be smaller than the right on the same level.

This definition can change slightly. Under some conditions, the tree cannot have duplicate values. Or the duplicate values will be on the right side, or on the left. All are valid, so check with your interviewer.

When given a question, many candidates assume the interviewer means a binary search tree.

Be sure to ask!

A binary search tree implies that for each node, its left descendants are less than or equal to the current node, which is less then the right descendants.

Balanced vs Unbalanced

Ask your interviewer whether the tree is balanced or unbalanced

Note: balancing a tree does not mean left and right subtrees are exactly the same size.

One way of thinking about this is that a balanced tream means "not terribly unbalanced". It's balanced enough to ensure O(log n) insert and find, but it's not necessarily as balanced as it could be.

Complete Binary Tree

Every level of the tree is fully filled, except for perhaps the last level. The last level is filled left to right.

Full Binary Trees

Every node has either zero or two children. No nodes have only one child.

Perfect Binary Trees

Both full and complete. All leaf nodes will be at the same level, and this level has the maximum number of nodes.

Perfect trees are rare in interviews and in real life. Do not assume a binary tree is perfect in an interview.

PreviousMinimum Height TreesNextCounting Maximal Value Roots in Binary Tree

Last updated 4 years ago

Was this helpful?