{ "q1": { "type": "blank", "question": "\n
Given the following function, odds, which converts a\nlist of strings into a list of only odd\nintegers:\n\n
\ndef odds(strings: list[str]) -> list[int]:\n numbers = []\n for string in strings:\n number = int(string)\n if number % 2:\n numbers.append(number)\n return numbers\n\n\n
Write a new function odds_lc that accomplishes the same task\nusing a list comprehension:
\n\n\ndef odds_lc(strings: list[str]) -> list[int]:\n return [____ for string in ____ if ____]\n\n" }, "q2": { "type": "blank", "question": "\n
Given the following function, odds, above, write a new function\nodds_gr that accomplishes the same task as a generator\nfunction:
\n\n\ndef odds_gr(strings: list[str]) -> ____[int]: # 1.\n for string in ____: # 2.\n number = ____ # 3.\n if ____: # 4.\n ____ number # 5.\n\n" }, "q3": { "type": "multiple", "question": "\n
Which of the following statements regarding the different odds\nfunctions are true (select all that apply)?
\n", "responses": { "odds_more_memory_gr": "When strings is large, odds will use a lot more memory than odds_gr.", "odds_lc_more_memory_gr": "When strings is large, odds_lc will use a lot more memory than odds_gr.", "odds_more_memory_lc": "When strings is large, odds will use a lot more memory than odds_lc.", "odds_gr_more_memory_lc": "When strings is large, odds_gr will use more memory than odds_lc." } }, "q4": { "type": "multiple", "question": "\nWhich of the following statements regarding binary heaps are true\n(select all that apply)?
\n", "responses": { "array": "Binary heaps are usually represented using an array.", "nodes": "Binary heaps are usually represented using linked nodes.", "full": "Binary heaps must be full trees.", "complete": "Binary heaps must be complete trees.", "root": "The root of a binary heap is always the smallest or largest value in the tree.", "middle": "The root of a binary heap is always the middle value in the tree.", "avg_add_logn": "In the average case, adding a new value to a binary heap is an O(logn) operation.", "avg_add_n": "In the average case, adding a new value to a binary heap is an O(n) operation.", "worst_add_logn": "In the worst case, adding a new value to a binary heap is an O(logn) operation.", "worst_add_n": "In the worst case, adding a new value to a binary heap is an O(n) operation." } }, "q5": { "type": "multiple", "question": "\nWhich of the following binary trees are binary heaps\n(select all that apply)?
\n\nSuppose we use the following binary heap to implement a\npriority queue and then perform a pop() operation to remove\nthe largest value. Which of the following statements are true\n(select all that apply)?
\n\nSuppose we use the following binary heap to implement a\npriority queue and then perform a push(6) to add a new\nvalue. Which of the following statements are true (select all that\napply)?
\n\nUsing Python's heapq library, complete the following implementation of heap_sort:
\n\n\nimport heapq\n\ndef heap_sort(sequence):\n heap = ____\n for item in ____:\n ____(heap, item)\n return [____(heap) for _ in range(len(heap))]\n\n" } }