Q1. What is a database index and how does it work?
A database index is a separate data structure (usually a B-tree) that stores a sorted copy of one or more columns plus pointers back to the full row. When you query an indexed column, the database walks the tree in O(log n) time instead of scanning every row sequentially. It is the database equivalent of the index at the back of a textbook.