数据结构与算法代写 | COMPUTER SCIENCE Algorithms and Data Structures I

PART A

Candidates should answer ALL of Question 1 in Part A.

Question 1 If instructed to choose only one option, do not choose multiple
options. If you select multiple options, your answer will be marked as 0. If
otherwise instructed to select all options that apply, there will be multiple correct
options, but you can lose marks for selecting incorrect options.

(a) Consider the following problem:

Given a non-negative integer n, is n2 odd?

Which of the following is the type of the expected output for this problem?
Choose only one option. [3]

i. Integer
ii. A fraction
iii. Boolean
iv. None of the above.

(b) Which of the following statements describes what an algorithm is? There
is only one correct answer. [2]

i. An algorithm is only a method for checking if computer programs are
correct.
ii. An algorithm is only a method for ﬁnding if a number is an integer.
iii. An algorithm is a method of step-by-step basic instructions which, if
followed, solves a problem.
iv. An algorithm is a set of problems that can be solved by a computer.

(c) Consider the following piece of pseudocode:

1: x 2
2: x x + 2
3: function CHECK(n)
4: if n=2 then
5: n n + 1
6: end if
7: return n ” 1
8: end function
9: x CHECK(x)
10: x CHECK(x)

i. What is the value of x at the end of line 1? [1]
ii. What is the value of x at the end of line 2? [1]
iii. What is returned by CHECK(2)? [1]
iv. What is the value of x at the end of line 9? [1]
v. What is the value of x at the end of line 10? [1]

E-mail: itcsdx@outlook.com  微信:itcsdx