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_ with max: -3<7 (no change)

3. Compare __0_ with max: 0 < 7 (no change)

4. Compare __4_ with max: 4 < 7 (no change)

5. Compare __10_ with max: 10 > 7 (update max = 10)

6. Compare __2_ with max: 2 < 10 (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 will take values 2,3,4,5,6 sequentially
  if (L[i] > max) {
    # compare the current elemtn L[i] with max
     max <- L[i] # Update max if L[i] is greater
  }
  
}

# Return the maximum element
max
## [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.