Zero-Based Indexing

Domain: Data Structures

🎯 Motivation

Most programming languages count from 0, not 1. Understanding this prevents off-by-one errors that cause bugs.

📋 Concrete Example

arr = [10, 20, 30]. arr[0] is 10 (first), arr[1] is 20 (second), arr[2] is 30 (third). Length is 3 but last index is 2.

🔗 Analogy

A ruler starts at 0 cm, not 1 cm. The first centimetre of the ruler covers 0 to 1. Counting from zero is like measuring distance from the start point.