هياكل البيانات والخوارزميات (DSA27) · الأسبوع 8

Searching (Lecture 08)

هذه اختبارات للتدريب الذاتي، تُحفظ إجاباتك على هذا الجهاز فقط ولا تُرسل إلى أحد. الأسئلة والشرح بالإنجليزية لغة المقرر.

النتيجة: 0 / 22 · أُجيب: 0

  1. W8-M01 تذكّر

    Which search works on an unsorted list?

  2. W8-M02 تطبيق

    The largest number of comparisons binary search makes on a sorted list of 1,000 elements is:

  3. W8-M03 تطبيق

    …and on 1,000,000 elements:

  4. W8-M04 تعليل

    Binary search is called on a list that is not sorted. It:

  5. W8-M05 تطبيق

    binary_search(V, 20): the index of the first element compared is:

  6. W8-M06 تطبيق

    …and the index of the second:

  7. W8-M07 تذكّر

    The loop invariant of binary search is:

  8. W8-M08 تعليل

    A binary search with an inclusive hi loops while lo < hi. Searching [42] for 42, it returns:

  9. W8-M09 تعليل

    In Java, mid = (lo + hi) / 2 is a bug because:

  10. W8-M10 تعليل

    A recursive binary search calls itself on values[:mid] or values[mid + 1:]. Its total time on n elements is:

  11. W8-M11 تذكّر

    The extra space of binary_search_recursive (passing lo and hi, no slices) is:

  12. W8-M12 تطبيق

    lower_bound([1, 2, 2, 2, 5, 7], 2) is:

  13. W8-M13 تطبيق

    upper_bound([1, 2, 2, 2, 5, 7], 2) is:

  14. W8-M14 تطبيق

    lower_bound([1, 2, 2, 2, 5, 7], 8) is:

  15. W8-M15 تطبيق

    How many times does 3 occur in [1, 3, 3, 3, 3, 9], computed as upper_bound(v, 3) - lower_bound(v, 3)?

  16. W8-M16 تذكّر

    Python's bisect.bisect_left(values, x) is the same as:

  17. W8-M17 تطبيق

    Jump search on 100 sorted elements jumps by:

  18. W8-M18 تعليل

    Jump search uses blocks of size √n because:

  19. W8-M19 تطبيق

    Exponential search for a target at index 11 of a 32-element list checks the bounds:

  20. W8-M20 تعليل

    Exponential search is most useful when:

  21. W8-M21 تعليل

    The worst case of interpolation search is:

  22. W8-M22 تطبيق

    Interpolation search on [10, 20, 30, …, 100] (10 values) for 70: the first index it probes is:

18 درجات

أسئلة المقال

5 أسئلة مقالية (18 درجة). اكتب إجابتك أولًا، ثم اعرض الإجابة النموذجية ونقاط التصحيح، وقدّر درجتك بأمانة: كل نقطة تساوي درجة تقريبًا.

مجموع درجات المقال: 0 / 18

  1. W8-E1 تعليل 4 درجات

    Describe binary search. State its loop invariant and use it to explain why the algorithm is correct, and show that it makes at most ⌊ log2 n ⌋ + 1 comparisons. What must the caller guarantee?

  2. W8-E2 تطبيق 4 درجات

    Give four classic bugs in binary search. For each, give an input on which it fails, what happens, and the fix.

  3. W8-E3 تعليل 4 درجات

    Define lower_bound and upper_bound. Give three uses of them, and explain why they never return −1.

  4. W8-E4 تعليل 3 درجات

    Compare jump search, exponential search and interpolation search: cost, and a situation in which each is the right choice.

  5. W8-E5 تعليل 3 درجات

    A program searches an unsorted list of n values k times. When is it worth sorting the list first? Compare the costs, and give a concrete example with n = 1,000,000.