Essential Concepts of Keyword Search and Inverted Index Design Quiz

Test your understanding of building a basic keyword search engine with a hash-map-based inverted index. This quiz covers term-frequency counting, result sorting, pagination, and effective caching strategies for repeated queries.

  1. Purpose of an Inverted Index

    What is the primary role of an inverted index in a keyword search system over documents?

    1. To store the full content of all documents for retrieval
    2. To convert documents into unique hash values for security
    3. To map each keyword to a list of documents containing that keyword
    4. To encrypt keyword queries before processing

    Explanation: An inverted index is designed to map each keyword to the documents in which it appears, enabling quick retrieval for searches. Storing the full content is not the main function; full content is typically stored separately. Converting documents into hash values is used for deduplication or security, not search. Encrypting queries relates to privacy, not inverted index structure.

  2. Efficient Data Structure Choice

    Which data structure is most efficient for implementing an inverted index that allows fast lookup of documents by keyword?

    1. Linked list
    2. Stack
    3. Array
    4. Hash map

    Explanation: A hash map allows for constant-time lookups of each keyword, making it ideal for building an inverted index. Arrays do not support fast keyword-based search unless the array is sorted and scanned. Linked lists and stacks are inefficient for large-scale keyword lookups because they require iteration over elements.

  3. Term Frequency in Ranking

    When ranking documents for a keyword search, why is term frequency useful as a ranking signal?

    1. It encrypts the keyword before searching
    2. It shows how many documents contain the keyword in the entire index
    3. It indicates how often a keyword appears in each document, likely reflecting relevance
    4. It determines the speed of document retrieval

    Explanation: Term frequency shows the number of times a keyword appears in a document, helping identify more relevant results. Counting documents in the index is related to document frequency, not term frequency. Encrypting keywords is unrelated to ranking, and term frequency does not impact retrieval speed directly.

  4. Sorting Search Results

    If you want to display the most relevant documents first in search results, which sorting method should you use when ranking with term frequency?

    1. Sort the documents alphabetically by title
    2. Sort in ascending order by document size
    3. Sort randomly for each query
    4. Sort the documents in descending order based on the term frequency

    Explanation: Sorting in descending order by term frequency displays documents where the keyword is most frequent at the top, providing higher relevance. Alphabetical sorting and sorting by document size do not relate to keyword relevance. Random sorting is not useful for ranking search results.

  5. Purpose of Pagination in Search

    In a search system, what is the primary advantage of implementing pagination for search results?

    1. It encrypts page data for security
    2. It groups keywords by similarity
    3. It divides results into smaller, more manageable chunks for the user
    4. It increases the total number of matching documents

    Explanation: Pagination presents search results in user-friendly sections, making browsing easier and improving performance. Increasing the number of matching documents is not related—pagination just structures the output. Grouping keywords and encrypting page data are unrelated to pagination's main purpose.

  6. Pagination Implementation Example

    A search query returns 80 results, and you want to show 10 results per page. Which result indices will be displayed on the fourth page (using 1-based indexing)?

    1. Results 10 to 19
    2. Results 40 to 49
    3. Results 20 to 30
    4. Results 31 to 40

    Explanation: With 10 results per page, page one shows 1–10, page two 11–20, page three 21–30, and page four 31–40. Results 10–19 are on page two, 40–49 would be page five, and 20–30 is page three. Thus, 31–40 is correct.

  7. Cache-Key Design for Search Queries

    When caching search results for repeated queries, what should the cache key uniquely represent?

    1. The user's browser type
    2. The combination of search keywords and any relevant query parameters
    3. The hash of the inverted index itself
    4. The total number of documents in the database

    Explanation: A cache key should uniquely identify a query by including its keywords and parameters so the correct results are returned for the given input. The total document count and index hash do not distinguish queries, and browser type does not affect search result relevance.

  8. Consistency in Cached Results

    If a user changes the paging parameter of a search (for example, moves from page 2 to page 3), what should happen to the cache key to retrieve the correct results?

    1. The cache key must encrypt the entire results set
    2. The cache key should only store the search keywords
    3. The cache key must include the page number to differentiate cached pages
    4. The cache key should be kept constant for all pages

    Explanation: Including the page number makes each cached page unique, retrieving the correct results for that page. Keeping the key constant or using only keywords would cause incorrect results to be served. Encrypting the results set is unrelated to cache-key correctness.

  9. Hash Collisions in Inverted Index

    What issue might arise if two different keywords are assigned the same hash index in a hash-map-based inverted index?

    1. Their document lists could get mixed up, leading to incorrect search results
    2. It prevents new documents from being added
    3. It speeds up search performance
    4. It automatically removes one of the keywords

    Explanation: Hash collisions risk mixing the document lists of distinct keywords, causing search errors. Collisions do not improve performance; rather, they require resolution. Keywords are not removed, and the index can still grow with proper collision handling.

  10. Optimizing Search with Caching

    How does introducing a cache for search queries optimize keyword search performance in a high-traffic system?

    1. It reduces the need to rebuild the inverted index and sort results for identical queries
    2. It prevents the use of term frequency in ranking
    3. It increases the time needed to retrieve results
    4. It forces all searches to access the slowest storage layer

    Explanation: Caching allows the system to quickly return results for repeated queries without redundant processing. It speeds up, rather than slows down, access. It does not force slow storage use or eliminate ranking signals such as term frequency.