Worksheets › Class 12 › Searching
Class 12 · Computer Science worksheetSearching
CBSE Computer Science. Linear search, binary search with its mid points, comparisons in each, and hashing by the remainder method with collisions. Every sheet has 20 questions in three sections and an answer key, and the questions change every time.
Sample questions
Real questions from this chapter, as the app sets them. Tap Answer to see the answer and working.
Section A · multiple choice
- 1.
Linear search compares the key with:
- only the last item
- the item at key % size
- the middle item first
- each item in turn from the start
Answer
(d) each item in turn from the start
- 2.
Linear search looks for 64 in 78, 81, 73, 55, 75, 72, 95, 64. How many comparisons does it make?
- 1
- 7
- 8
- 9
Answer
(c) 8
64 is item 8 from the left
- 3.
Linear search looks for 42 in 38, 14, 59, 3, 89, 64, 88. How many comparisons does it make before reporting that 42 is not present?
- 7
- 8
- 0
- 6
Answer
(a) 7
a missing key is compared with every item
Section B · short answer
- 4.
What is searching?
Answer
Finding whether a key is present in a collection of items and, if so, where.
- 5.
Binary search looks for 60 in 3, 6, 21, 27, 35, 36, 48, 60, 64, 68, 78, 85 (indices from 0). Write the mid indices it looks at, in order, separated by commas.
Answer
5, 8, 6, 7
found at index 7
Section C · long answer
- 6.
Write a Python function for linear search that returns the position of the key (counting from 1), or None. Explain its best and worst cases.
Answer
def linearSearch(L, key): for i in range(len(L)): if L[i] == key: return i + 1; return None. Best case: the key is first, 1 comparison; worst case: the key is last or absent, n comparisons.
Fresh sheets for your child
In the app, every Searching sheet is new: the app remembers the questions your child has already had and leaves them out. Print the sheet as a PDF, or use notebook mode and write the answers in a notebook.
Coming soon for Android and iPhone.