ICS_Homeworks/4_Algorithms.md
2022-11-05 01:05:12 +01:00

81 lines
2.1 KiB
Markdown

### In general, an algorithm in which of the following categories is considered more efficient?
Θ(log n)
### Suppose the statement "X is an integer and X < 5" is a loop invariant at the point at which the test for termination is performed in the loop outlined below.
```
repeat ( . . . )
until (X > 3)
```
### At the end of this loop, X equals?
4
### What sequence of numbers would be printed if the following procedure were executed with the value of N being 0?
```
procedure xxx (N)
print the value of N;
if (N < 2) then
(apply the procedure xxx to the value N + 1)
else
(print the value of N)
print the value of N
```
0,1,2,2,2,1,0
### What sequence of numbers would be printed if the procedure named xxx as described below were executed with the value of N being 2?
```
procedure xxx(N)
print the value of N;
if (N<3)
then (apply procedure yyy to the value 4)
procedure yyy(N)
print the value of N;
apply the procedure xxx to the value 5
print the value of N
```
2,4,5,5,4,2
### Which of the following is not a way of representing algorithms?
Stepwise refinement
### Q6 is a table again
![Table](https://media.discordapp.net/attachments/458628210272239626/1038241407078506536/image.png?width=638&height=335)
### Preconditions, postconditions, and loop invariants are examples of which of the following?
Assertions
### The binary search algorithm is an example of an algorithm in which of the following classes?
Θ(log n)
### Under the assumption that N takes on only integer values, which of the following is the termination condition in the following recursive procedure?
```
procedure xxx (N)
if (N < 5) then
(apply the procedure xxx to the value N + 1)
else
(print the value of N)
```
N > 4
### When searching within the list ` Lewis, Maurice, Nathan, Oliver, Pat, Quincy, Roger, Stan, Tom` which of the following entries will be found most quickly using the binary search algorithm?
Pat
### Which of the following set of instructions defines an algorithm in the formal, strict sense?
```
X ← 3;
while (X < 5)do
(X ← X + 1)
```