Hello, Can anyone review my algorithm lab, first semester in college and i'm in beginning courses for computer science. Still trying to get the hang of things. This is an online course which i should have taken in class. I can't focus enough time on my most important class while juggling a full time job and 19 other units.
thanks. I attached my answers in a word document.
New to this forum so if this is to much just delete my post
thanks in advance.
7. Algorithms Lab*
Pseudocode for algorithm design
The following exercises focus upon pseudocode, a simple English-like language used to
design algorithms.
The following program does not represent an algorithm in the strict sense. Why not?
assign count the value 0
while (count is not equal to 5) do
assign count the value count + 2
1. Is not an algorithm because:
Write down all the values output by the following algorithm:
assign count the value 2
while (count < 7) do
(print the value assigned to count
assign count the value count + 1)
2. output:
3. now rewrite the algorithm to produce the same output, using a repeat loop:
Write down all the values output by the following algorithm:
assign count the value 1
repeat
(print value of count
assign count the value count + 1)
until (count is equal to 5)
4.
5. now rewrite the algorithm to produce the same output, using a while loop:
The following algorithm generates the Fibonacci series. Work through the algorithm,
writing down all the values of last, temp and current until the algorithm terminates.
assign last the value 0
assign current the value 1
while (current < 20) do
(print the value assigned to current
assign temp the value of last
assign last the value of current
assign current the value last + temp)
6. last current temp
Write down all the values output by the following algorithm:
assign count the value 1
while (count not equal to 7) do
(print the value of count
assign count the value count + 3)
7. output:
8. Explain briefly what would happen if the statement "assign count the value count +
3" was deleted:
The procedure find_largest() takes a list of numbers and prints the largest. Work
through the call to find_largest(), writing down all the values of largest and next until
the procedure ends.
procedure find_largest (List)
assign largest the value of the first number in List
while (there is another number in List) do
(assign next the value of next number in List
if (next > largest) then
assign largest the value of next)
print the value of largest
example_list is: 3 1 4 4 5 0
apply procedure find_largest to example_list
9
Explain briefly the problem that might arise if the following algorithm is implemented.
(Hint: remember the problem of rounding error with floating point numbers)
assign n the value 0.1
while (n is not equal to 1.0)
(print the value of n
assign n the value n + 0.00001)
10. potential problem:
The following pseudocode is not correct for all possible values of X and Y
if (X > Y) then
print "X is greater than Y"
else
print "Y is greater than X"
11. For what values will an incorrect message be printed?
108 Lab 7 (1).doc