COMP9024 Supplementary Exam (22T0)

The Supplementary Exam paper will be released on the class webpage (at https://webcms3.cse.unsw.edu.au/COMP9024/22T0/) at 2pm on Saturday 12 February 2022 (AEST, that is Sydney time). You need to submit answers by 05pm Saturday 12 February 2022 (AEST), that is after 3 hours. All the times are in Australian Eastern Standard Time (AEST), that is Sydney time zone.


Exam Conditions

Special Consideration

Admin

Marks
Contributes 50% towards your final mark
Submit
See the submission instructions for each question
Date and time
Saturday 12 February 2pm-5pm
Total Marks
50

Structure

This exam consists of two parts:

Notes:

Part 1 (of 2): Short Answer Questions (25 marks)

Question 1 (3 marks)

An algorithm solves a problem of size n recursively by breaking it down into two subproblems of size n / 2 with the same structure, until the size of a subproblem is one or zero. It takes O(1) time to convert a problem of size n into two subproblems and it takes O(1) time to combine the results of two subproblems of size n into the result of the problem. What is the time complexity of this algorithm? Justify your answer.

Write your answer in q1.txt (download using "Save As" or similar).

Submission

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

give cs9024 exam_q1 q1.txt

Question 2 (3 marks)

An algorithm for solving a problem runs in exponential time O(2n). Suppose that your computer, running an implementation of this algorithm, can process an input of size 10 in one day. What is the maximum input size that can be processed in one day by a computer that is 1000 times faster if it uses the same implementation? Justify your answer.

Write your answer in q2.txt (download using "Save As" or similar).

Submission

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

give cs9024 exam_q2 q2.txt

Question 3 (3 marks)

Consider the the following 2-3-4 tree :

(a) What value(s) would be stored in the root node of the above 2-3-4 tree after the insertion of the value 8? What value(s) would be stored in the node that now contains 8? Note: if you need to promote a value, you must promote the smaller value from the available alternatives (if any). Justify your answer.

(b) What value(s) would be stored in the root node of the above 2-3-4 tree after the insertion of the value 50? What value(s) would be stored in the node that now contains 50? Note: if you need to promote a value, you must promote the smaller value from the available alternatives (if any). Justify your answer.

Write your answer in q3.txt (download using "Save As" or similar)..

Submission

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

give cs9024 exam_q3 q3.txt

Question 4 (4 marks)

Suppose that you need to implement a Priority Queue ADT that provides the following operations:

Assuming that all three operations will be frequently used, which one of the following data structures is most suitable? Justify your answer. You must use time complexities as a basis for your justification.

Write your answer in q4.txt (download using "Save As" or similar)..

Submission

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

give cs9024 exam_q4 q4.txt

Question 5 (3 marks)

While constructing the above minimum spanning tree, the edges were added in the following sequence:

  1. A - E
  2. C - D
  3. E - B
  4. E - C
Which one of the following algorithms discussed in the lectures was used to construct the above minimum spanning tree? Justify your answer.

Write your answer in q5.txt (download using "Save As" or similar)..

Submission

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

give cs9024 exam_q5 q5.txt

Question 6 (3 marks)

A binary search tree contains the values 2, 7, 8, 10, 14, 16, 20, 24, 33, and 40. A pre-order traversal produces the sequence: 16, 10, 7, 2, 8, 14, 24, 20, 40, 33. Which one of the following sequences will be produced by a valid post-order traversal of the same tree? Briefly explain your answer.

  1. 2, 7, 8, 14, 10, 20, 33, 40, 24, 16
  2. 2, 8, 7, 14, 10, 20, 33, 40, 24, 16
  3. 2, 7, 8, 14, 10, 20, 33, 24, 40, 16
  4. 2, 7, 8, 10, 14, 20, 24, 33, 40, 16
  5. None of the other choices are correct.

Write your answer in q6.txt (download using "Save As" or similar)..

Submission

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

give cs9024 exam_q6 q6.txt

Question 7 (3 marks)

Which of following statements about tries is not correct? Briefly explain your answer.

Write your answer in q7.txt (download using "Save As" or similar)..

Submission

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

give cs9024 exam_q7 q7.txt

Question 8 (3 marks)

Which of the following statements about the Knuth-Morris-Pratt (KMP) algorithm is not correct?

Write your answer in q8.txt (download using "Save As" or similar)..

Submission

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

give cs9024 exam_q8 q8.txt


Part 2 (of 2): Programming Questions (25 marks)

Notes

Part 2: Q1 (12 Marks)

Your task for this question is to implement the following function in the file nodesNotBalanced.c.

int nodesNotBalanced(BSTree t);

The function nodesNotBalanced(BSTree t) takes one argument: a binary search tree t, and returns the number of nodes that are not height balanced.

For this question, as discussed in the lectures (see here), we say the height of a tree is equal to the maximum path length from the root to a leaf node. A node is not height balanced if the absolute difference between the heights of its left subtree and right subtree is greater than one. The height of an empty tree is -1.

Important:

Download

Click here to download the zip file for this question.

Alternatively, if you are connected to the CSE system (e.g., via VLAB or SSH), you can copy the zip file using the following command:

$ cp /home/cs9024/public_html/22T0/exam/t24aeu67/supp22T0/q1-files.zip .

The Files

BSTree.c Contains the implementation of basic binary search tree functions.
BSTree.h Contains the definition of the binary search tree data structure and function prototypes.
testNodesNotBalanced.c The test driver program. The program reads tree data from stdin, calls nodesNotBalanced, and outputs the answer to stdout. You must carefully study how your function is tested by testNodesNotBalanced.c. You can find out more about the behaviour of the testNodesNotBalanced program by looking at the files testNodesNotBalanced.c, autotest and the files in the tests directory. The files named X.in contain sample inputs for the test program and the corresponding expected outputs are in files named X.exp.
nodesNotBalanced.c Contains nodesNotBalanced, the function you must implement. This is the only file you should modify.
Makefile A Makefile to compile your code
tests/ A directory containing the inputs and expected outputs for some basic test cases
autotest A script that uses the tests in the tests directory to autotest your solution. You should only run this after you have tested your solution manually.

Examples

The following examples show the expected output for some different trees. The nodes that are not height balanced are shown in bold.

Displaying tree (sideways) 
        60
50

 -------  
nodesNotBalanced(t) returns: 0 
 -------  
Displaying tree (sideways) 
        60
50
        30

 -------  
nodesNotBalanced(t) returns: 0 
 -------  
Displaying tree (sideways) 
                                                96
                                        94
                                92
                        90
                80
        70
50
                44
        30
                20

 -------  
nodesNotBalanced(t) returns: 5 
 -------  
Displaying tree (sideways) 
                        80
                70
        60
                55
50
                40
        30
                20
                        10

 -------  
nodesNotBalanced(t) returns: 0 
 -------  
Displaying tree (sideways) 
                        140
                130
        120
100
        90
                80
                        70
                                60
                                        50
                                                40
                                                        30
                                                                20
                                                                        10

 -------  
nodesNotBalanced(t) returns: 9 
 -------  
Displaying tree (sideways) 
45

 -------  
nodesNotBalanced(t) returns: 0 
 -------  

Testing

You can compile and test your function using the following commands:

$ make       # builds the testNodesNotBalanced program
$ ./autotest # applies all the tests in the tests directory to the testNodesNotBalanced program

# applies only one given test case from the tests directory to the testNodesNotBalanced program
$ ./autotest test-number   

You can find out more about the behaviour of the testNodesNotBalanced program by looking at the files testNodesNotBalanced.c, autotest and the files in the tests directory. The files named X.in contain sample inputs for the test program and the corresponding expected outputs are in files named X.exp.

For example, if you want to run test case 2, use the following command:

$ ./autotest 2

If you want to run all the sample test cases provided, use the following command:

$ ./autotest

After you run the tests, additional files will appear in the tests directory. X.out contains the output from running test X.

You can add debugging code to nodesNotBalanced.c or testNodesNotBalanced.c if you want, however, make sure that you remove it before testing and submitting, otherwise your output won't match the expected output and you'll fail all the tests. You can also add any auxiliary functions to nodesNotBalanced.c that you think are necessary.

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

$ give cs9024 exam_q9 nodesNotBalanced.c

Please note that the submission script does not run any tests on your program. Thus, it is important that you test your program on the CSE system before submitting.

Make sure you thoroughly test your program! We will run further tests on your submission after the exam which may test different cases from the tests provided to you.


Part 2: Q2 (13 Marks)

Your task for this question is to implement the following function in the file rankPopularity.c.

void rankPopularity(Graph g, int src, double *mnV);

The function rankPopularity takes three arguments: a directed graph g, a source node src and an array mnV. For each node v that is reachable from src, the function should store its popularity rank in the array mnV at index v. For example, if node 2 is reachable from src, then when the function returns, mnV[2] should contain the popularity rank of vertex 2.

Popularity rank: Calculate a node's popularity rank using the following equation:

popularityRank(v) = (inDegree(v) / outDegree(v))

If outDegree(v) is zero, replace it with 0.5.

Please read the example below for more clarifications.

Important notes:

Download

Click here to download the zip file for this question.

Alternatively, if you are connected to the CSE system (e.g., via VLAB or SSH), you can copy the zip file using the following command:

$ cp /home/cs9024/public_html/22T0/exam/t24aeu67/supp22T0/q2-files.zip .

The Files

Graph.c Contains the implementation of basic Graph ADT functions.
Graph.h Contains the definition of the Graph ADT and function prototypes.
testRankPopularity.c The test driver program. The program reads data, creates a Graph and calls the function rankPopularity, and outputs the answer to stdout. You must carefully study how your function is tested by testRankPopularity.c. You can find out more about the behaviour of the testRankPopularity program by looking at the files testRankPopularity.c, autotest and the files in the tests directory. The files named X.in are input files for the test program testRankPopularity and the corresponding expected outputs are in files named X.exp.
rankPopularity.c Contains rankPopularity, the function you must implement. This is the only file you should modify.
Makefile A Makefile to compile your code
tests/ A directory containing the inputs and expected outputs for some basic test cases
autotest A script that uses the tests in the tests directory to autotest your solution.You should only run this after you have tested your solution manually. Note that this script only tests simple cases. You need to extensively test your program for a wide range of test cases.

Examples

For example, consider the following graph:

Popularity ranks for nodes reachable from node "4" in the above graph are:

Note that node "2" is not reachable from node "4", so it must be ignored.

Testing

You can compile and test your function using the following commands:

$ make       # builds the required testRankPopularity program
$ ./autotest # applies all the tests in the tests directory to the testRankPopularity program
# applies only one given test case from the tests directory to the testRankPopularity program
$ ./autotest test-number

You can find out more about the behaviour of the testRankPopularity program by looking at the files testRankPopularity.c, autotest and the files in the tests directory. The files named X.in contain sample input for the test program and the corresponding expected outputs are in files named X.exp.

For example, if you want to run test case 2, use the following command:

$ ./autotest 2

If you want to run all the sample test cases provided, use the following command:

$ ./autotest

After you run the tests, additional files will appear in the tests directory. X.out contains the output from running test X.

You can add debugging code to rankPopularity.c or testRankPopularity.c if you want, however, make sure that you remove it before testing and submitting, otherwise your output won't match the expected output and you'll fail all the tests. You can also add any auxiliary functions to rankPopularity.c that you think are necessary.

Once you are satisfied with your solution, submit it through the give command or via WebCMS (click here).

The give command is:

$ give cs9024 exam_q10 rankPopularity.c

Please note that the submission script does not run any tests on your program. Thus, it is important that you test your program on the CSE system before submitting.

Make sure you thoroughly test your program! We will run further tests on your submission after the exam which may test different cases from the tests provided to you.



End