Worksheets › Class 12 › Searching

Class 12 · Computer Science worksheet

Searching

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.

Open a printable sample sheet

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. 1.

    Linear search compares the key with:

    1. only the last item
    2. the item at key % size
    3. the middle item first
    4. each item in turn from the start
    Answer

    (d) each item in turn from the start

  2. 2.

    Linear search looks for 64 in 78, 81, 73, 55, 75, 72, 95, 64. How many comparisons does it make?

    1. 1
    2. 7
    3. 8
    4. 9
    Answer

    (c) 8

    64 is item 8 from the left

  3. 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?

    1. 7
    2. 8
    3. 0
    4. 6
    Answer

    (a) 7

    a missing key is compared with every item

Section B · short answer

  1. 4.

    What is searching?

    Answer

    Finding whether a key is present in a collection of items and, if so, where.

  2. 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

  1. 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.

More Class 12 Computer Science