Problem: Problem Statement

Problem 1: Find the maximum element in the following finite sequence of integers, L={7,−3,0,4,10,2}.

Pseudocode

Algorithm FindMax(L)

## Input: A list L of n integers
## Output: The maximum element in the list

## max = L[1]
## for i = 2 to length(L) do
    ## if L[i] > max then
        ## max = L[i]
## return max

1) Explanation of Pseudocode (Fill what is missing for 10 points)

1. Initialize max with the first element of the list: Assume the first element is the largest for now.

2. Loop through the rest of the elements in the list: Start from the second element and go to the end.

3. Compare each element with max: If the current element is greater than max, update max.

4. Return max: ___________________After the loop ends, the maximum element is the result.__________________________________

2) Example Execution (Completely fill what is missing for 10 points)

Let’s go through the list using our Pseudocode L={7,−3,0,4,10,2} step-by-step:

1. Initialize max with the first element: max = 7

2. Compare __-3 < 7_ with max: (no change)

3. Compare __0 < 7_ with max: (no change)

4. Compare _7 < 10__ with max: (update max = 10)

5. Compare _4 < 10__ with max: (no change)

6. Compare _2 < 10__ with max: (no change)

The final value of max is 10.

write the code for 70 points.

## R code from Pseudocode. Use L={7,−3,0,4,10,2} for this HW assignment 

# Initialize the list
L <- c(7, -3, 0, 4, 10, 2)


# Initialize max with the first element
max <- L[1] # max is now 7


# Loop through the rest of the elements in the list
for (i in 2:length(L)){ 
  # i is the value of the integers sequentially
  if (L[i] > max){
    # Compares the current integer with i with the max
    max <- L[i] #updates max if L[i] is greater
  }
}


# Return the maximum element
max
## [1] 10

[1] 10

Note: Professor reserves the right to decide what answers, code, and step-processs is correct not the student. Once the student submits the assignment, they are not able to resubmit for a higher grade and all grades are final when the professor inserts them in D2L.

Convert to HTML for 10 points and submit both the markdown file (.rmd) and HTML to the assignment folder in D2L.