2023-dsa-exam2
2023-dsa-exam2
900295SCIY
EXAM 2
18 December 2023, 09:00-10:30
Duration of the exam is 90 minutes
Student name
On the following page, you will find important information about the
examination. Before starting with the examination you should read
this information.
Instructions
1. This exam consists of three parts: multiple choice questions, open questions,
and C code questions.
2. You are allowed to use a blue or black pen, but nothing else.
3. Please write your name on the front page before you answer the questions.
4. Please do not remove the staple from the exam and keep all sheets connected!
5. Write your answers on this exam, in the empty space after the question.
6. You are not allowed to leave the examination room during the first 15 minutes
of the examination and during the final half hour of the exam.
7. Please switch off any electronic devices and put them in your bag. Your bag
needs to be closed.
8. Any violation of AUC’s rules on fraud may lead to sanctions, ultimately to the
exclusion of all examinations for one year (AS&P appendix 2, Regulations
governing fraud and plagiarism).
9. The number of points per question is specified in the table below.
10. Your exam grade will be (10 + points received) / 10.
2. draw tries 10
3. draw heaps 11
Total 90
Data Structure and Algorithms page 3 of 12 2023 Exam 2
6. Recall that an Euler path is a path in which every edge occurs exactly once.
Consider the graph below.
C
A B D
E
Which of the following is true?
⃝ This graph has an Euler cycle.
⃝ If we add a second edge between A and B then the graph has an Euler cycle.
⃝ There is an edge such that if we delete it then the graph has an Euler cycle.
⃝ If we add an edge between A and D, then the graph has an Euler cycle.
7. Suppose we need to represent a graph with n nodes and m edges. Which of the following is true?
⃝ The amount of memory needed by the two-dimensional array representation is in O(n).
⃝ The amount of memory needed by the two-dimensional array representation is in O(n2 ).
⃝ The amount of memory needed by the adjacency list representation is in O(n).
⃝ The amount of memory needed by the adjacency list representation is in O(1).
8. Which of the following statements about search algorithms and spanning trees is true?
⃝ The spanning tree obtained with Depth-First Search is always a line.
⃝ The spanning tree obtained with Depth-First Search can contain cycles.
⃝ The spanning tree obtained with Breadth-First Search is never a line.
⃝ The spanning tree obtained with Breadth-First Search can be a line.
9. Let n be the number of nodes and m the number of edges in a graph. Which of the following
statements about the worst-case time-complexity of search algorithms is true?
⃝ The complexity of Depth-First Search is in O(n).
⃝ The complexity of Breadth-First Search is in O(n).
⃝ The complexity of Breadth-First Search is in O(m + n).
⃝ The complexity of Dijkstra’s algorithm is in O(m + n).
10. Suppose we execute Dijkstra’s algorithm on the graph shown below, starting at node 1.
5 2
1 2 3
1 5 1
1 7
4 5 6
3 3 7 2 3
3. 11 points Consider a max-heap represented by an array. Recall that we do not use the 0th entry of
the array and store the root of the heap in array position 1. Suppose the heap contains four elements
and the contents of the array are [0, 6, 2, 5, 2, 0, 0, 0].
(a) Draw the heap as a tree.
(b) Execute enqueue(9), then removeMax(), then enqueue(7) on the heap from (a) and draw
the resulting heap as a tree. (You do not have to provide intermediate steps here — please use
the scratch paper for that.)
Data Structure and Algorithms page 8 of 12 2023 Exam 2
There are three mistakes in this function. Find them and say how they should be corrected.
Data Structure and Algorithms page 9 of 12 2023 Exam 2
2. 20 points Consider the following typedef to represent a directed unweighted graph. For each node
we use a linked list to store its outgoing edges.
typedef struct ListGraph {
int N; // number of nodes
List* links; // array of adjacency lists
} ListGraph;
0 1
(a) Write C code to represent the graph using this typedef.
You may use all functions from the linked list library.
(b) Write a C function int edgeCount(ListGraph g) that given a graph returns its number
of edges.
Data Structure and Algorithms page 10 of 12 2023 Exam 2