{ "q1": { "type": "blank", "question": "\n
Given the following linked list code:
\n\n\n/* Structures */\n\ntypedef struct Node Node;\nstruct Node {\n int data;\n Node *next;\n};\n\n/* Functions */\n\nNode *node_create(int data, Node *next) {\n Node *n = malloc(sizeof(Node)); \n if (n) {\n n->data = data;\n n->next = next;\n } \n return n;\n}\n\n\n
Complete the following node_search function, which performs an\niterative version of linear search:
\n\n\nNode *node_search(Node *head, int value) {\n for (Node *curr = ____; ____; curr = ____) { // 1. 2. 3.\n if (____ == value) { // 4.\n return ____; // 5.\n } \n } \n return ____; // 6.\n}\n\n" }, "q2": { "type": "blank", "question": "\n
Given the linked list code above, complete the following\nnode_search_r function, which performs a recursive version\nof linear search:
\n\n\nNode *node_search_r(Node *n, int value) {\n // Base case: invalid node\n if (____) { // 1.\n return ____; // 2.\n }\n\n // Base case: found value\n if (____) { // 3.\n return ____; // 4.\n }\n\n // Recursive: keep searching\n return ____; // 5.\n}\n\n" }, "q3": { "type": "multiple", "question": "\n
Which of the following statements about the time and space\ncomplexities of the node_search and node_search_r\nfunctions are true (select all that apply)?
\n", "responses": { "ns_time_1": "The average time complexity of node_search is O(1).", "ns_time_n": "The average time complexity of node_search is O(n).", "ns_space_1": "The average space complexity of node_search is O(1).", "ns_space_n": "The average space complexity of node_search is O(n).", "nsr_time_1": "The average time complexity of node_search_r is O(1).", "nsr_time_n": "The average time complexity of node_search_r is O(n).", "nsr_space_1": "The average space complexity of node_search_r is O(1).", "nsr_space_n": "The average space complexity of node_search_r is O(n)." } }, "q4": { "type": "order", "question": "\nThe following binary_search function implements binary\nsearch recursively given an array of data, a target,\na start index, and an end index:
\n\n\nbool binary_search(int *data, int target, int start, int end) {\n if (start > end)\n if (midpoint == target)\n if (midpoint > target)\n else\n\n int middle = (start + end) / 2;\n int midpoint = data[middle];\n\n return binary_search(data, target, start, middle - 1); \n return binary_search(data, target, middle + 1, end);\n return false;\n return true;\n}\n\n\n
Unfortunately, the code for binary_searchis scrambled.\nReorder the following lines of code to properly implement binary_search:
\n", "responses": { "a": "if (start > end)", "b": "if (midpoint == target)", "c": "if (midpoint > target)", "d": "else", "e": "int middle = (start + end) / 2;", "f": "int midpoint = data[middle];", "g": "return binary_search(data, target, start, middle - 1);", "h": "return binary_search(data, target, middle + 1, end);", "i": "return false;", "j": "return true;" } }, "q5": { "type": "multiple", "question": "\nWhich of the following statements about sets are true (select all that apply)?
\n", "responses": { "sets_unique": "A set only contains unique values.", "sets_duplicate": "A set may contain duplicate values.", "sets_ordered": "A set stores an ordered sequence of values.", "sets_unordered": "A set stores an unordered collection of values.", "sets_membership": "A set is often used to test a value for membership.", "sets_retrieval": "A set is often used to retrieve a specific value." } } }