{ "q1": { "type": "multiple", "question": "\n

Given the following C code:

\n\n
`\nint numbers[5];\n`
\n\n

Which of the following statements regarding arrays are true\n(select all that apply)?

\n", "responses": { "initial_zero": "numbers[0] is guaranteed to be 0.", "initial_garbage": "numbers[0] is probably garbage.", "sizeof_array_5": "sizeof(numbers) is 5.", "sizeof_array_20": "sizeof(numbers) is 20.", "accessing_1": "Accessing any element in numbers is O(1).", "accessing_n": "Accessing any element in numbers is O(n).", "searching_1": "Searching for any element in numbers is O(1).", "searching_n": "Searching for any element in numbers is O(n).", "inserting_1": "Inserting an element in the middle of numbers is O(1).", "inserting_n": "Inserting an element in the middle of numbers is O(n).", "deleting_1": "Deleting an element from the end of numbers is O(1).", "deleting_n": "Deleting an element from the end of numbers is O(n)." } }, "q2": { "type": "multiple", "question": "\n

Which of the following statements regarding dynamic arrays are\ntrue (select all that apply)?

\n", "responses": { "resizing": "Dynamic arrays are arrays that automatically resize when necessary.", "appending_worst_1": "Appending an element to a dynamic array is O(1) in the worst case.", "appending_worst_n": "Appending an element to a dynamic array is O(n) in the worst case.", "appending_average_1": "Appending an element to a dynamic array is O(1) in the average case.", "appending_average_n": "Appending an element to a dynamic array is O(n) in the average case.", "size_elements": "Dynamic arrays have a size attribute to track the number of elements stored in the internal array.", "capacity_elements": "Dynamic arrays have a capacity attribute to track the number of elements stored in the internal array.", "size_allocation": "Dynamic arrays have a size attribute to track the maximum number of elements allocated for the internal array.", "capacity_allocation": "Dynamic arrays have a capacity attribute to track the maximum number of elements allocated for the internal array." } }, "q3": { "type": "blank", "question": "\n

Given the following C code involving a stack:

\n\n
`\n// Assume we have the operations:\n//  push(int *stack, int value) -> Adds value to the top of stack\n//  pop(int *stack)             -> Removes value at the top of stack and returns it\n//  peek(int *stack)            -> Returns value at the top of stack\n//  empty(int *stack)           -> Returns whether or not the stack is empty\n\nint stack[5] = {1, 2, 3};\n\nprintf(\"%d\\n\", peek(stack));  // 1. ____\n\npush(stack, 4);\nprintf(\"%d\\n\", peek(stack));  // 2. ____\n\nprintf(\"%d\\n\", pop(stack));   // 3. ____\nprintf(\"%d\\n\", peek(stack));  // 4. ____\n\npop(stack);\nprintf(\"%d\\n\", pop(stack));   // 5. ____\n`
\n\n

Fill in the blanks corresponding to trace the output of the\nprintf statements.

\n" }, "q4": { "type": "order", "question": "\n

Given the following C code involving a stack:

\n\n
`\n// Assume we have the operations:\n//  push(int *stack, int value) -> Adds value to the top of stack\n//  pop(int *stack)             -> Removes value at the top of stack and returns it\n//  peek(int *stack)            -> Returns value at the top of stack\n//  empty(int *stack)           -> Returns whether or not the stack is empty\n\nvoid reverse_array(int *array, size_t n) {\n    int stack[n];\n\n    for (size_t i = 0; !empty(stack); i++)\n    for (size_t i = 0; i < n; i++)\n    memset(stack, 0, sizeof(int)*n);\n\n      push(stack, array[i]);\n      array[i] = pop(stack);\n}\n`
\n\n

The code is suppose to reverse all the elements in array (ie.\n{1, 2, 3} becomes {3, 2, 1}. Unfortunately, the lines of\ncode are scrambled.

\n\n

Unscramble the following lines of code to implement the\nreverse_array function:

\n", "responses": { "a": "int stack[n];", "b": "for (size_t i = 0; !empty(stack); i++)", "c": "for (size_t i = 0; i < n; i++)", "d": "memset(stack, 0, sizeof(int)*n);", "e": "push(stack, array[i]);", "f": "array[i] = pop(stack);" } } }