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

Hash Tables (Lecture 13)

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

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

  1. W13-M01 تذكّر

    A hash table finds the slot of a key by computing:

  2. W13-M02 تطبيق

    In a table of capacity 8, the index of the key 45 is:

  3. W13-M03 تذكّر

    The one rule every hash function must obey is:

  4. W13-M04 تعليل

    python -c "print(hash('abc'))" prints a different number each time you run it because:

  5. W13-M05 تطبيق

    Which of these is the same in every run of Python?

  6. W13-M06 تعليل

    m.put([1, 2], "x") raises TypeError: unhashable type: 'list' because:

  7. W13-M07 تطبيق

    23 keys are placed in 365 slots at random. The probability that at least two share a slot is about:

  8. W13-M08 تذكّر

    The load factor of a hash table is:

  9. W13-M09 تطبيق

    A ChainingHashMap() receives put for 5, 13 and 21. Bucket 5 is:

  10. W13-M10 تطبيق

    In the table of W13-M09, get(29) compares 29 with how many entries before raising KeyError?

  11. W13-M11 تطبيق

    A ChainingHashMap() receives distinct keys one at a time. The first resize happens during the put of the:

  12. W13-M12 تعليل

    _resize cannot copy old[i] into new[i] because:

  13. W13-M13 تطبيق

    An OpenAddressingHashMap() receives put for 6, 14 and 22. Key 22 is in slot:

  14. W13-M14 تطبيق

    In the table of W13-M13, get(30, None) makes how many probes?

  15. W13-M15 تعليل

    In open addressing, delete leaves a tombstone instead of None because:

  16. W13-M16 تطبيق

    get meets a tombstone while probing. It:

  17. W13-M17 تعليل

    put counts tombstones in its load check because:

  18. W13-M18 تذكّر

    Primary clustering is:

  19. W13-M19 تطبيق

    For linear probing with a good hash, Knuth's formula for an unsuccessful search is 1/2(1 + 1/(1-α)2). At α = 0.5 it gives:

  20. W13-M20 تعليل

    The keys 0, 1024, 2048, 3072, … (n of them) are put into a ChainingHashMap, whose capacity is always a power of two. While the capacity is at most 1,024, one get costs:

  21. W13-M21 تذكّر

    Python's dict is:

  22. W13-M22 تعليل

    Which question does a sorted array answer in O(log n) but a hash table cannot answer faster than O(n)?

18 درجات

أسئلة المقال

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

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

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

    Explain how a hash table finds a key in O(1) time on average. State the assumption behind "on average", give the worst case, and name three things that can push a real table towards it.

  2. W13-E2 تعليل 3 درجات

    A student's class defines __hash__ to return 0 for every object. Is a hash table of these objects wrong, or only slow? Answer for chaining and for open addressing, and give the cost of get and of building a table of n keys.

  3. W13-E3 تطبيق 4 درجات

    Compare chaining and open addressing: what a slot holds, the load factors each can tolerate, how each deletes, and one practical advantage of each.

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

    Explain tombstones. Why can an open-addressing delete not simply empty the slot? State how get, put and _resize each treat a tombstone, and why the load check must count them.

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

    Show that a hash table that doubles its capacity when the load factor passes a fixed limit does amortised O(1) work per put on rehashing. What happens if it grows by a fixed 8 slots instead?