Damian Durruty

Problem 4.

Get the price "p" for item A
Get the quantity purchased "q" for item A Set "cost" to p * q
Set "cost with tax" to (cost * 1.06)
Print out the value "cost with tax"
Stop

Problem 5.

Get the value of "x"
Get the value of "y"
If ("y" equals 0) then
Print 'Unable to perform division'
Else
"z" = "x"/"y"
Print "z"
End conditional
Stop

Get the radius "r" of the circle
"circum" = 2pi"r"
Print out the value of "circum"
If (r >= 1.0) then
"area" = pi*r*r
Print out the value of "area"
End conditional
Stop

Problem 9.

Get "n", the size of the list of items
Get values "i(1)", "i(2)", ..., "i(n)", the list of items Set "cost with tax" to 0
Set "i" to 1
While ("cost with tax" <= 1000 and "i" <= "n") Get the price "p" for item "i(i)"
Get the quantity purchased "q" for item "i(i)" Set "cost" to p * q
Set "cost with tax" to "cost with tax" + ("cost" * 1.06) Set "i" to "i" + 1
End loop
Stop

Problem 14.

# Basically using the selection sort algorithm # (which uses a modified Find Largest algorithm) to order the list numerically in # order to obtain the median.

Get a value for "n", the size of the list Get values "A(1)", "A(2)", ..., "A(n)", the list to be searched Set the value of "median" to "A(1)"
Set the value of "position of median" to 1 Set the value of "j" to 1

While (j <= n) do
Set "i" to "j"
Set "smallest so far" to "A(i)"
Set "position of smallest" to "i"
While (i+1 <= n) do

     If "A(i+1)" < "smallest so far" then
        Set "smallest so far" to "A(i+1)"
        Set "position of smallest" to "i+1"
     End conditional
     Add 1 to the value of "i"

End loop
Swap "A(j)" with "A("position of smallest")" Add 1 to the value of "j"
End loop

If ("n" is odd) then
Set "position of median" to n/2 + (1/2) Else
Set "position of median" to n/2
End conditional

Set "median" to "A("position of median")" Print out the values "median" and "position of median" Stop

Problem 17.

  1. This change will not affect the output of the algorithm, though it is a completely unnecessary change.
  2. This change will result in the algorithm finding the smallest rather than largest number in the list.

Using the correct operator is critical as using the wrong may cause the algorithm to computer something entirely different than intended.