0
0
DSA Goprogramming~3 mins

Why BST Find Minimum Element in DSA Go?

Choose your learning style9 modes available
The Big Idea

What if you could find the smallest item instantly without checking every single one?

The Scenario

Imagine you have a messy pile of books on your desk, and you want to find the book with the smallest page number. You start picking up each book one by one, checking the page number, and remembering the smallest so far. This takes a lot of time and effort.

The Problem

Manually checking each book is slow and tiring. You might forget which book had the smallest page number or miss some books. This makes finding the smallest item error-prone and frustrating.

The Solution

A Binary Search Tree (BST) organizes books so that smaller page numbers are always to the left. To find the smallest book, you just keep going left until you can't go further. This is quick and simple, saving time and effort.

Before vs After
Before
minPage := books[0]
for _, book := range books {
    if book.page < minPage.page {
        minPage = book
    }
}
After
current := root
for current.Left != nil {
    current = current.Left
}
minPage := current
What It Enables

This lets you quickly find the smallest item in a sorted structure without checking everything.

Real Life Example

When a library system wants to find the oldest book (smallest ID) quickly, it uses a BST to jump straight to it without scanning all books.

Key Takeaways

Manual search is slow and error-prone.

BST structure keeps smaller items to the left.

Finding minimum means going left until no more left child.