by codegeek · 9y ago · 0 comments
"Index helps you locate information quicker than usual in a database. If database is similar to a Book, then think of index as a Table Of Contents with page numbers for specific topics. Imaging if I gave you a book with 1000 pages and ask you to find a specific topic but there is no table of contents. You will have to look through many pages before you find it. If it had a table of contents, you could flip to that page much faster.
Will this answer be good enough for you ?
But then, I have no technical knowledge of how index is implemented within various databases and that is where I will say "Sorry I can't tell you the technical details".
EDIT: I will also add that it is difficult to list EVERY possible topic in a book in the table of contents. It will then defeat the purpose of the TOC. So you have to pick and choose the topics that you want to show with page numbers. Same for database index. You cannot index everything.
FWIW, books frequently also have indexes, which are a better analog to DB indexes than tables of contents are.
I think your answer is a great one, but that an important thing to point out (which also fits into the analogy) is that an index is a trade off between lookup efficiency vs. storage size (the more words included in a book's index, the more pages it requires) and write efficiency (every time you write a word that is included in the index, you need to go update that word's entry).
Understanding the point of indexes and their implicit trade-offs seems like fair game to me. This sort of read / write / storage size trade-off is relevant to basically all software. Having a sense for the different kinds of indexes and how they are implemented seems like bonus.
All in all though, I'd personally be pretty happy with that answer (I'm not the OP, though...)
Someone interviewing has no idea which of the two of us they are talking to. That's why the technical interview process is so fraught.
For instance if I were an auto repair shop owner asking a technician candidate "do you know how a small block ford work" I meant how the manifold, heads, rotary etc. fit together rather than how to drive a kick ass street rod (which is cool but not the skill I'm interviewing you for)
My point was really that a major reason interviews are so daunting is that candidates don't know whether they're talking to someone like you or someone like me.
It gives you mappings that don't align with the primary ordering (ToC/page num).