[Fundamental Information Technology Engineer Examination] I wrote an algorithm for the maximum value of an array in Python.

Overview

--There is an algorithm in the afternoon exam of the Fundamental Information Technology Engineer Examination. I can't understand even if I solve the past questions ... I would like to actually write the algorithm in Python to deepen my understanding.

--Last time, I wrote the algorithm of Euclidean algorithm. --This time, I will write from the algorithm of ** maximum array value **.

Maximum value of the array

algorithm

--Set the first element of the array as the temporary maximum value. The remaining elements of the array are compared in order with the tentative maximum, and if a larger value is found, the tentative maximum is updated.

code

#Max function to find the maximum value of an array
def Max(A,Length):
    Ans = A[0]
    #Iterative processing
    i = 1 #Set the initial value of the loop counter to 1.
    while i < Length:
        print("Ans=",Ans,"i=",i,"A[i]=",A[i])
        #Branch processing
        if A[i] > Ans: #If the newly extracted element is larger than the maximum value
            Ans = A[i] #Update the tentative maximum
        i+=1
    return Ans

print("Execution result:",Max([12,56,78,34,90],5))

Execution result

Ans= 12 i= 1 A[i]= 56
Ans= 56 i= 2 A[i]= 78
Ans= 78 i= 3 A[i]= 34
Ans= 78 i= 4 A[i]= 90
Execution result: 90

Summary

--The maximum value of the array is unexpectedly difficult ――Next time, let's write an algorithm for ** linear search **

reference

--I quoted or referred to the maximum value of the Chapter 3 03 array in this book. Information processing textbook, book that can solve algorithm problems of the Fundamental Information Technology Engineer Examination, 2nd edition

Recommended Posts

[Fundamental Information Technology Engineer Examination] I wrote an algorithm for the maximum value of an array in Python.
[Fundamental Information Technology Engineer Examination] I wrote the algorithm of Euclidean algorithm in Python.
[Fundamental Information Technology Engineer Examination] I wrote an algorithm for determining leap years in Python.
[Fundamental Information Technology Engineer Examination] I wrote a linear search algorithm in Python.
A story about downloading the past question PDF of the Fundamental Information Technology Engineer Examination in Python at once
python Basic sorting algorithm summary (Basic Information Technology Engineer Examination)
[Golang] Specify an array in the value of map
Experience of taking the Applied Information Technology Engineer Examination
I wrote the queue in Python
I wrote the stack in Python
I wrote the code to write the code of Brainf * ck in python
Fundamental Information Technology Engineer Examination (FE) Afternoon Exam Python Sample Question Explanation
Note that I understand the algorithm of the machine learning naive Bayes classifier. And I wrote it in Python.
You will be an engineer in 100 days --Day 29 --Python --Basics of the Python language 5
[Python] Summary of functions that return the index that takes the closest value in the array
You will be an engineer in 100 days --Day 33 --Python --Basics of the Python language 8
You will be an engineer in 100 days --Day 26 --Python --Basics of the Python language 3
Part 1 I wrote an example of the answer to the reference problem of how to write offline in real time in Python
Note that I understand the least squares algorithm. And I wrote it in Python.
Find the divisor of the value entered in python
You will be an engineer in 100 days --Day 32 --Python --Basics of the Python language 7
I searched for the skills needed to become a web engineer in Python
Output in the form of a python array
You will be an engineer in 100 days --Day 28 --Python --Basics of the Python language 4
Fundamental Information Technology Engineer Examination Implemented Python sample questions without using external libraries
The concept of reference in Python collapsed for a moment, so I experimented a little.
Basic information Write the 2018 fall algorithm problem in Python
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Heapsort)
[For beginners] I want to explain the number of learning times in an easy-to-understand manner.
I tried to create a Python script to get the value of a cell in Microsoft Excel
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
I tried the accuracy of three Stirling's approximations in python
Check the operation of Python for .NET in each environment
I wrote the basic grammar of Python with Jupyter Lab
I wrote the basic operation of Seaborn in Jupyter Lab
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Bubble Sort)
Find the index of the maximum value (minimum value) of a multidimensional array
I wrote an empty directory automatic creation script in Python
I just wrote the original material for the python sample code
I wrote the basic operation of Numpy in Jupyter Lab.
Google search for the last line of the file in Python
Turn an array of strings with a for statement (Python3)
Implemented the algorithm of "Algorithm Picture Book" in Python3 (selection sort)
Quicksort an array in Python 3
I wrote AWS Lambda, and I was a little addicted to the default value of Python arguments
Part 1 I wrote the answer to the reference problem of how to write offline in real time in Python
I compared the calculation time of the moving average written in Python
Wrap (part of) the AtCoder Library in Cython for use in Python
How to know the internal structure of an object in Python
[Python] I wrote the route of the typhoon on the map using folium
I got an AttributeError when mocking the open method in python
Various ways to create an array of numbers from 1 to 10 in Python.
[Algorithm x Python] Calculation of basic statistics (total value, maximum value, minimum value)
[High School Curriculum Guidelines Information I] Teaching materials for teacher training: Implementation of Huffman method in python
Develop an investment algorithm in Python 2
I wrote Fizz Buzz in Python
[Python] I tried to summarize the set type (set) in an easy-to-understand manner.
Comparing the basic grammar of Python and Go in an easy-to-understand manner
python> array> Determine the number and initialize> mylist = [idx for idx in range (10)] / mylist = [0 for idx in range (10)] >> mylist = [0] * 10
You will be an engineer in 100 days ――Day 24 ―― Python ―― Basics of Python language 1
I measured 6 methods to get the index of the maximum value (minimum value) of the list