Computer Science – 11.3 Structured Programming | e-Consult
11.3 Structured Programming (1 questions)
Login to see all questions.
Click on a question to view the answer
Pseudo-code:
- Define a function
FindBooks(books, searchTerm)that takes a list ofbooksand asearchTermas input. - Create an empty list called
searchResults. - For each
bookinbooks: - If the
searchTermis found in thebook.titleorbook.author: - Add the
booktosearchResults. - Return
searchResults.
Efficiency Considerations: The efficiency of this approach depends on the string searching algorithm used. A simple string search might have a time complexity of O(m*n), where n is the number of books and m is the average length of the title/author. More efficient string searching algorithms (e.g., Knuth-Morris-Pratt, Boyer-Moore) could improve this. For very large lists, consider using a data structure like a Trie to speed up the search.