{ "q01": { "type": "order", "question": "\n

Suppose you are about to start a new homework assignment and you wish to\nsync your local repository with the changes on GitHub, create a new\nhomework branch, and then view which branch you are on.

\n\n

Organize the git commands below in the proper order to\naccomplish the tasks above.

\n", "responses": { "branch": "git branch", "checkout": "git checkout -b homework", "switch": "git switch master", "pull": "git pull --rebase" } }, "q02": { "type": "order", "question": "\n

Suppose you create a new file in the homework branch and wish to record\nthis change, send it to GitHub, and then view the history of the\nrepository.

\n\n

Organize the git commands below in the proper order to\naccomplish the tasks above.

\n", "responses": { "log": "git log", "push": "git push -u origin homework", "commit": "git commit -m \"Add file\"", "add": "git add file" } }, "q03": { "type": "blank", "question": "\n

Suppose you had a program.c that you requires a\nlibds.a library to compile. Complete the following\nMakefile such that a program executable is built when the\nuser types in make:

\n\n
\nCC=     gcc\nCFLAGS= -Wall -g -std=gnu99\n\n____:   ____    # 1, 2\n        ____    # 3\n
\n" }, "q04": { "type": "blank", "question": "\n

Given the following implementation of a stack using a dynamic\narray:

\n\n
\n\n
\n\n

How much data is allocated on the stack and heap regions\nof memory by the following line in stack_create:

\n\n
\nStack *s = malloc(sizeof(Stack));\n
\n\n
    \n
  1. Stack: ____
  2. \n
  3. Heap: ____
  4. \n
\n" }, "q05": { "type": "multiple", "question": "\n

Given the Stack implementation above, suppose you had the\nfollowing program:

\n\n
\n\n
\n\n

After compiling and running the program with valgrind, you see\nthe following error message:

\n\n
\n==1181217== Conditional jump or move depends on uninitialised value(s)\n==1181217==    at 0x109240: stack_push (array.c:30)\n==1181217==    by 0x109353: main (array.c:49)\n
\n\n

Which of the following statements are true (select all that\napply)?

\n", "responses": { "s_uninitialized": "s is not initialized.", "data_uninitialized": "s->data is not initialized.", "capacity_uninitialized": "s->capacity is not initialized.", "size_uninitialized": "s->size is not initialized.", "fix_use_calloc": "To fix this problem, you can use calloc instead of malloc in stack_create.", "fix_use_realloc": "To fix this problem, you can use realloc instead of malloc in stack_create.", "fix_set_capacity": "To fix this problem, you can set capacity to 0 in stack_create.", "fix_set_size": "To fix this problem, you can set size to 0 in stack_create.", "memory_leak_yes": "There is also a memory leak in the program.", "memory_leak_no": "There are no memory leaks in the program." } }, "q06": { "type": "single", "question": "\n

Suppose you fix the memory errors in the program above. What is the output of the program?

\n", "responses": { "a": 92867, "b": "92867-1", "c": 76829, "d": -176829 } }, "q07": { "type": "multiple", "question": "\n

Given the following implementation of a priority queue using a\nlinked list:

\n\n
\n\n
\n\n

After compiling and running this program, you see that it\nsegfaults. You decide to use gdb to get a backtrace\nand you see the following:

\n\n
\nProgram received signal SIGSEGV, Segmentation fault.\n0x0000555555555213 in node_format (head=0x0) at pqueue.c:30\n30          printf(\"%d\", head->data);\n
\n\n

Which of the following statements are true (select all that\napply)?

\n", "responses": { "head_null": "The program segfaults because head is NULL.", "data_null": "The program segfaults because head->data is NULL.", "fix_check_head": "Avoid the segfault by checking if head is NULL before printing.", "fix_check_data": "Avoid the segfault by checking if head->data is NULL before printing.", "pq_sentinel": "pq is a sentinel node.", "pq_dummy": "pq is a dummy node.", "memory_leak_yes": "There is also a memory leak in the program.", "memory_leak_no": "There are no memory leaks in the program." } }, "q08": { "type": "blank", "question": "\n

To complete the priority queue above, you need to implement a\nnode_remove function that finds the minimum value in the\npriority queue, removes the associated Node from the\nlinked list, and returns the value. With this in mind, complete the\nfollowing implementation of node_remove:

\n\n
\nint     node_remove(Node *head) {\n    if (!____) return -1;                             # 1\n\n    Node *minimum = ____;                             # 2\n    for (Node *curr = ____; curr; curr = curr->next)  # 3\n        if (curr->data < minimum->data)\n            minimum = curr;\n\n    Node *prev = ____;                                # 4\n    Node *curr = ____;                                # 5\n    while (curr != ____) {                            # 6\n        ____ = ____;                                  # 7, 8\n        ____ = ____;                                  # 9, 10\n    }\n\n    ____ = ____;                                      # 11, 12\n    int value = ____;                                 # 13\n    ____;                                             # 14\n    return value;\n}\n
\n" }, "q09": { "type": "multiple", "question": "\n

Given the completed priority queue above, suppose you implemented\na node_sorted function that uses the queue_remove\nfunction to repeated remove one value from the priority queue at a\ntime:

\n\n
\n\n
\n\n

Which of the following statements are true (select all that\napply)?

\n", "responses": { "bubble": "node_sorted most closely resembles bubble sort.", "selection": "node_sorted most closely resembles selection sort.", "insertion": "node_sorted most closely resembles insertion sort.", "time_n": "node_sorted has an average time complexity of O(n)", "time_nlogn": "node_sorted has an average time complexity of O(nlogn)", "time_n2": "node_sorted has an average time complexity of O(n^2)" } }, "q10": { "type": "multiple", "question": "\n

Suppose you wanted to implement a set that supported\nadd and contains operations.

\n\n

Which of the following statements are true (select all that\napply)?

\n", "responses": { "array": "With a dynamic array, a set would have O(logn) average time complexities for both add and contains.", "list": "With a linked list, a set would have O(n) average time complexities for both add and contains.", "hash": "With a hash table, a set would have O(1) average time complexities for both add and contains." } }, "q11": { "type": "multiple", "question": "\n

Which of the following statements regarding sorting algorithms\nare true (select all that apply)?

\n", "responses": { "bubble_time": "Bubble sort has an worst case time complexity of O(n^2)", "bubble_adaptive": "Bubble sort is an adaptive algorithm.", "bubble_stable": "Bubble sort is an stable algorithm.", "selection_time": "Selection sort has an worst case time complexity of O(n^2)", "selection_adaptive": "Selection sort is an adaptive algorithm.", "selection_stable": "Selection sort is an stable algorithm.", "insertion_time": "Insertion sort has an worst case time complexity of O(n^2)", "insertion_adaptive": "Insertion sort is an adaptive algorithm.", "insertion_stable": "Insertion sort is an stable algorithm.", "merge_time": "Merge sort has an worst case time complexity of O(n^2)", "merge_adaptive": "Merge sort is an adaptive algorithm.", "merge_stable": "Merge sort is an stable algorithm.", "quick_time": "Quick sort has an worst case time complexity of O(n^2)", "quick_adaptive": "Quick sort is an adaptive algorithm.", "quick_stable": "Quick sort is an stable algorithm." } }, "q12": { "type": "blank", "question": "\n

Suppose you had a hash table with four buckets and the\nhash function show below:

\n\n
\n\n
\n\n

Assuming the hash table uses separate chaining to handle\ncollisions, what are the contents of each of the buckets\nafter inserting the numbers: 9, 2, 8, 6, 7.

\n\n
    \n
  1. Bucket 0: ____
  2. \n
  3. Bucket 1: ____
  4. \n
  5. Bucket 2: ____
  6. \n
  7. Bucket 3: ____
  8. \n
\n\n

If a bucket has more than one value, then separate each value\nwith a space.

\n" } }