{ "q1": { "type": "blank", "question": "\n\nHow many subsets of {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} are divisible by\n3 sum?\n\nWrite a program that computes this and enter in the number below.\n\n____\n\nNote: As shown in the book, order does not matter when defining a subset. Therefore,\n{0, 1, 2} and {1, 0, 2} counts as one set.\n\n" }, "q3": { "type": "blank", "question": "\n\n\nComplete the Python code below so that the program prints all permutations\nof \"ABC\": ABC, ACB, BAC, BCA, CAB, CBA.\n\n\n\n
\nimport ____\n\ns = \"ABC\"\nfor p in ____(s):\n print ''.____(p)\n\n\n" }, "q2": { "type": "blank", "question": "\n\n\nComplete the C++ code below so that the program prints all permutations of\n\"ABC\": ABC, ACB, BAC, BCA, CAB, CBA.\n\n\n\n
\nint main(int argc, char *argv[]) {\n string s = \"ABC\";\n ____(s.begin(), s.end());\n do {\n cout << s << endl;\n } while (____(s.begin(), s.end()))\n\n return 0;\n}\n\n" }, "q5": { "type": "multiple", "question": "\n\n\nIn regards to greedy algorithms, which of the following statements are true\n(select all that apply)?\n\n\n", "responses": { "efficiency": "A greedy algorithm tends to be very efficient.", "backtrack": "A greedy algorithm will backtrack when it finds a suboptimal solution.", "approach": "A greedy algorithm constructs a solution by choosing the best option at the moment.", "guarantee": "A greedy algorithm is guaranteed to find the optimal solution." } }, "q4": { "type": "blank", "question": "\n\n\nA ____ algorithm starts with an empty solution and extends the solution\nstep by step by ____ searching through all the different ways a solution\ncan be constructed. Because this can be quite exhaustive, we may wish to\nadd \"intelligence\" to our search by ____ the search tree, which mean to\neliminate a candidate solution if we can determine that it is a dead-end.\n\n\n" }, "q7": { "type": "multiple", "question": "\n\n\nIn regards to data compression, which of the following statements are true\n(select all that apply)?\n\n\n", "responses": { "variable": "Variable-length codes are suboptimal because they utilize longer codewords.", "prefix": "Codewords can have the same prefix if they are variable length.", "compress": "To compress a string, we use binary code to replace each character with a corresponding codeword.", "codeword": "In a constant-length code, the length of each binary code is the same." } }, "q6": { "type": "single", "question": "\n\n\nGiven n events with their starting and ending times, which of the following\ngreedy strategies is considered optimal?\n\n\n", "responses": { "osclass": "I am not in operating systems.", "begin": "Always choose the event with the earliest start time first.", "end": "Always choose the event with the earliest end time first.", "shortest": "Always choose the event with the shortest time first." } }, "q8": { "type": "multiple", "question": "\n\nGiven the string DACABAD which of the following are valid Huffman\ncodes (select all that apply)?\n\n", "responses": { "a": "A = 1, B = 001, C = 000, D = 01", "c": "A = 1, B = 000, C = 001, D = 01", "b": "A = 0, B = 110, C = 111, D = 10", "e": "A = 1, B = 111, C = 110, D = 10", "d": "A = 0, B = 010, C = 111, D = 10" } } }