Question 1 (0.8 Mark)

Which of the following code will cause an error (More than one answer may be selected)?

A. int mark[4] = {19, 10, 8, 17, 9};

B. int mark[] = {19, 10, 8, 17, 9};

C. int[4] mark;

D. int mark[] = new int[4];


Question 2 (0.8 Mark)

Which statement is/are NOT true about the following code (More than one answer may be selected)?

    int x = 1;

    int* p1 = &x;

    int** p2 = &p1;

A. p1 is a pointer to the memory address of x.

B. *p1 holds the address of x.

C. p2 is a pointer to the memory address of *p1.

D. p2 holds the address of p1.


Question 3 (0.8 Mark)

Which of the following is/are TRUE about Linked List (More than one answer may be selected)?

A. You can change the size of a linked list after creating it.

B. A linked list requires no more space than an array to store the same number of ints.

C. It is easier to insert an element in the middle of a linked list than in the middle of an array.

D. Linked list naturally supports accessing elements by their positions/indices.


Question 4 (0.8 Mark)

What is the most accurate time complexity of the following code?

    bool recur(int n){

if (n == 0) return false;

if (n == 1) return true;

if (n%2 == 0) return 2*recur(n/2);

return recur(n/2);

    }

A. O(logn)

B. O(n)

C. O(nlogn)

D. O(n2)


Question 5 (0.8 Mark)

Which of the following code is/are NOT written correctly (More than one answer may be selected)? Suppose the running environment, #include, namespace are all well configured. The incorrect code cannot compile successfully or terminate by itself during execution.

A. vector<int>::iterator i;

B. vector<int> v = { 1, 2, 3 };

    for (auto i = v.begin(); i != v.end(); i++) {

cout << &i << " ";

    }

C. vector<char> v = { 'a', 'b', 'c' };

    if (vector<char>::iterator i != v.end()) {

cout << *i << " ";

    }

D. vector<string> v = { "a", "b", "c" };

    auto i = v.end();

    auto it1 = i - 5;


Question 6 (0.8 Mark)

Which of the following (sub)graphs will definitely appear during the process of generating the minimum spanning tree from the graph below using Kruskal's Algorithm (More than one answer may be selected)?


Question 7 (0.8 Mark)

What is the height of the Binary Search Tree built by inserting these elements in a sequence: 9, 6,3, 7, 4, ? The height of a binary tree is the number of edges between the tree’s root and its furthest leaf.

A. 3

B. 4

C. 5

D. 6


Question 8 (0.8 Mark)

Which of the following techniques can be used by a string-matching algorithm (More than one answer may be selected)?

A. Sliding window

B. Hash function

C. Linear probing

D. Dynamic programming


Question 9 (3 Marks)

Can you briefly describe what the function below does in plain English (word limit: 100)? 

    int func (std::vector<int>& v) {

int n = 0;

for (auto iter = v.begin(); iter != v.end(); ++iter) {

    if (*iter > 0)

n += *iter;

}

    }


Question 10 (3 Marks)

Suppose we have a binary search tree, and we wish to find the path from any vertex to the root. The path is a sequence of vertices, including the source and destination.

Please briefly describe your method in plain English, pseudo-code, or C++ code (word limit: 200).