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

Stacks (Lecture 06)

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

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

  1. W6-M01 تذكّر

    "LIFO" means:

  2. W6-M02 تطبيق

    push(1), push(2), push(3), pop(), push(4), pop(). What does the next pop() return?

  3. W6-M03 تعليل

    A stack built on a dynamic array should keep its top at:

  4. W6-M04 تعليل

    A stack built on a singly linked list should keep its top at:

  5. W6-M05 تذكّر

    Stack().pop() on an empty stack:

  6. W6-M06 تعليل

    A stack on an array with its top at index 0. push costs:

  7. W6-M07 تطبيق

    Why is "([)]" not balanced?

  8. W6-M08 تطبيق

    Which check makes is_balanced(")") return False?

  9. W6-M09 تطبيق

    The postfix form of 3 + 4 * 2 is:

  10. W6-M10 تطبيق

    The postfix form of ( 3 + 4 ) * 2 is:

  11. W6-M11 تطبيق

    Evaluating the postfix 8 3 - gives:

  12. W6-M12 تطبيق

    Evaluating the postfix 2 3 4 * + gives:

  13. W6-M13 تذكّر

    In the shunting-yard algorithm, when an operator arrives, it first pops to the output every stacked operator with:

  14. W6-M14 تعليل

    Why does an operator of equal precedence also leave the stack?

  15. W6-M15 تطبيق

    The postfix form of 8 - 3 - 2 is:

  16. W6-M16 تطبيق

    The worst-case extra space of is_balanced on a text of length n is:

  17. W6-M17 تعليل

    To turn a recursive algorithm into a loop, in general you need:

  18. W6-M18 تذكّر

    In an undo/redo system with two stacks, what happens to the redo stack when the user performs a new action?

  19. W6-M19 تطبيق

    n pushes onto the Stack of dsa/stack.py (built on a DynamicArray) cost in total:

  20. W6-M20 تذكّر

    Which of these is not a natural stack application?

  21. W6-M21 تطبيق

    While is_balanced("(((())))") runs, the largest number of items on the stack at once is:

  22. W6-M22 تذكّر

    peek() differs from pop() in that it:

  23. W6-M23 تطبيق

    The shunting-yard algorithm converts 2 * 3 + 4 to:

  24. W6-M24 تطبيق

    The shunting-yard algorithm converts ( 1 + 2 ) * ( 3 - 4 ) / 5 to:

  25. W6-M25 تعليل

    A student's infix_to_postfix pops an operator only when the stacked one has strictly higher precedence (> instead of >=). Their calculator, evaluate_postfix(infix_to_postfix(...)), now gives 8 - 3 - 2 as:

  26. W6-M26 تعليل

    With the same > bug, which of these inputs is still converted correctly?

  27. W6-M27 تطبيق

    evaluate_postfix(["6", "2", "/", "3", "*"]) returns:

  28. W6-M28 تعليل

    A buggy evaluate_postfix computes (first value popped) op (second value popped): the operands the wrong way round. On which input does it still give the right answer?

  29. W6-M29 تطبيق

    evaluate_postfix(["3", "4"]):

  30. W6-M30 تذكّر

    evaluate_postfix(["1", "0", "/"]):

  31. W6-M31 تعليل

    A version of is_balanced ends with return True instead of return openers.is_empty(). Which input does it get wrong?

  32. W6-M32 تذكّر

    A version of is_balanced pops for every closer without first checking that the stack is non-empty. On "())" it:

  33. W6-M33 تطبيق

    is_balanced("a(b)c)d(") returns False. Which check fails first?

  34. W6-M34 تعليل

    is_balanced("print('(')"), a line of valid Python, returns:

  35. W6-M35 تعليل

    Most pushes onto the Stack of dsa/stack.py are instant, but now and then one push takes much longer. Why?

  36. W6-M36 تذكّر

    Which stack gives worst-case O(1) for every push, not just amortised O(1)?

  37. W6-M37 تذكّر

    s = Stack([1, 2, 3]). What does s.pop() return?

  38. W6-M38 تعليل

    Two peek() calls in a row, with nothing in between, return two different values. The most likely bug is that peek:

  39. W6-M39 تطبيق

    An editor with an undo stack and a redo stack. The user types A, types B, types C, then: undo, undo, redo, types D. What is on the two stacks (bottom → top)?

  40. W6-M40 تعليل

    nested_sum with your own Stack instead of recursion. Its real advantage in Python is that:

32 درجات

أسئلة المقال

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

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

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

    State the Stack ADT with the cost of each operation. Describe two honest implementations, compare them, and describe one design that passes every test but is not honest.

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

    Describe the stack algorithm for balanced brackets. Give an example of each of the three ways a text can be unbalanced, and the check that catches it.

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

    Explain how a stack evaluates a postfix expression. Why does the order in which the two operands are popped matter, and for which operators?

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

    Explain the shunting-yard algorithm, and trace it on 2 * ( 3 + 4 ) - 5. Why must an operator of equal precedence be popped?

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

    "Recursion is a stack." Explain, and describe how you would rewrite a recursive algorithm without recursion. When is that worth doing in Python?

  6. W6-E6 تعليل 4 درجات

    A student's infix_to_postfix pops an operator only on strictly higher precedence (> instead of >=). Give one input that it still converts correctly and one that it gets wrong, with both postfix results and their values. Explain why the tests can miss this bug, and name an operator for which > is the right rule.

  7. W6-E7 تطبيق 3 درجات

    Run the whole calculator on ( 8 - 2 ) / ( 1 + 2 ) * 4: convert it to postfix with the shunting-yard algorithm, then evaluate the postfix with a stack, showing the stack after each operator. Why is the answer a float?

  8. W6-E8 تعليل 4 درجات

    Compare a stack on a dynamic array (top at the end) with a stack on a singly linked list (top at the head): the cost of push in the worst case and amortised, the memory per item, and memory locality. The lecture's timings found the linked stack faster in this course. Why, and would that still hold for Python's own list? Which would you choose for a program that must never pause?

  9. W6-E9 تطبيق 3 درجات

    Design undo and redo for a text editor with two stacks. Say what each of action, Undo and Redo does to the two stacks, and show both stacks after: type A, type B, type C, undo, undo, redo, type D. What would go wrong if a new action did not clear the redo stack?