Searching is at the heart of many everyday programs. Real applications rarely use plain linear search on large data; they choose a data structure that makes searching fast. This page looks at the examples in the study material and the structures behind them.
Spell checkers
A spell checker looks up each word of a document in a dictionary; a word not found is flagged. A dictionary has hundreds of thousands of words and a document many thousands, so the look-up must be fast.
Search engines
A web search engine uses programs called crawlers (robots, spiders) that follow links from page to page and download documents. The words of every page are put into an inverted index: for each word, a list of the pages that contain it. A query is answered by looking up the query words in this index (with hashing or search trees) and combining their page lists, never by scanning the web page by page.
String pattern matching
Finding all occurrences of a word in a text (the “Find” command, grep, DNA analysis) is string matching. The naive method tries every starting position and costs O(nm) for a text of length n and a pattern of length m; algorithms such as Knuth–Morris–Pratt work in O(n+m). To search many strings at once, tries and suffix trees store all strings so that a look-up takes time proportional to the length of the word, not to the number of words.
Databases
A database query such as “find the customer with ID 41725” uses an index, usually a B-tree (Unit 7) or a hash table, so it reads only a few disk blocks instead of scanning the whole table.
Key takeaways
Spell checkers look words up with hashing, tries or binary search, not linear search.
Search engines answer queries from an inverted index built by crawlers.
String matching finds patterns in text; tries and suffix trees speed up multi-string search.
Databases use B-tree or hash indexes.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Explain how searching is used in a spell checker and in a search engine, and name the data structures that make each fast.
Show worked answer
A spell checker reads the document word by word and looks each word up in a dictionary of valid words; words not found are flagged as misspelt. To be fast, the dictionary is stored in a hash table (about one probe per word), a trie (time proportional to the word’s length) or a sorted array searched with binary search (about log2n probes). A search engine uses crawlers to collect web pages and builds an inverted index that maps each word to the list of pages containing it; a query looks up its words in this index (using hashing or search trees) and combines the lists, so the engine never scans the pages themselves at query time.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-208/searching-and-sorting-techniques/applications-of-searching/ to read this page.