Assessment 1 Template
1. Algorithms (48 points)
Section titled “1. Algorithms (48 points)”Write out the steps of an algorithm for solving a problem, explaining the logic behind every decision as fully as possible.
Example problems:
- Calculating the sum of the elements in a list;
- Finding the maximum;
- Finding the number of values divisible by 5;
- Pairwise operations on 2 lists;
- Finding an element’s position according to a rule;
- A similar simple problem.
Solution steps:
-
(2 points) Identify the interface. From this point on, assume that all input data is already available (you do not need to request it from the user).
-
(30 points) Analyze the problem. Break the problem down into subproblems. Break each one down further into subproblems or sub-ideas until you reach primitive operations (listed below).
Describe all sub-ideas and subproblems, as well as their logical connections, in as much detail as possible.
An intuitive leap that skips a level of logic is considered an error — the intuition must later be justified by logic for it to count. -
(10 points) Put the primitive operations in the correct order, possibly adding intermediate primitive operations, to obtain the final algorithm.
-
(4 points) Execute the resulting algorithm on several given examples. At each step, indicate the current state of the allocated memory cells (you do not have to write out lists; record them only when their contents change).
-
(2 points) Write the algorithm as a C++ function using a
whileloop.
Primitive operations:
-
Create a memory cell (variable) with a name.
-
Read from a memory cell by name.
-
Read from a list by index. (It can be written as
A[i].) -
Read a parameter (for example, the length of a list).
-
Write a value into a memory cell.
-
Evaluate an expression in order to write its result into a memory cell or use it in a condition. For example: “the value in
a+ 1 is written into the memory cella” or “the value ina+ the value incis written into the memory cellb.”You may write this as
a = a + 1andb = a + c, or asa + 1 --> aanda + c --> b. -
Check a condition and perform actions only when it is true. If there are several actions, create a sublist of steps for them.
For example:
5. If а > b1. a = 52. b = 66. Next step.You may use the notation
if (a > b). -
End the algorithm and output the result (can be written as
return result). -
Go to a specific algorithm step.
-
Signal an error and terminate the algorithm prematurely.
Operations can be combined; for example, “If a > b, read from a, and write into b” includes 3 primitive operations, but this is allowed (within reason).
2. Syntax (24 points)
Section titled “2. Syntax (24 points)”-
A randomly selected basic comprehension question from lab 1 on the following subtopics: variables, pointers, and pointer arithmetic.
Grading (18 points):
- 1 point for each correct answer;
- 5 points for the reasoning behind each one.
-
A randomly selected basic comprehension question from the structures lab. (It will not be about functions.)
Grading (6 points):
- 1 point for a correct answer;
- 5 points for the reasoning.