Hangarau

hātepe

algorithm

tūingoa

WHAKAMĀRAMA

Ko te āta raupapa i ngā takahanga e oti ai tētahi tātaitanga, e tutuki ai tētahi whāinga whāiti rānei. He mea ka whakaurua i te tīmatanga, ā, he hua, he otinga rānei ka puta i te mutunga o ngā takahanga. He āhua rite te hātepe ki te tohutaka.

The precise sequence of steps needed to complete a calculation or achieve a specific objective. Something is inputted at the beginning, and an output or solution is produced at the end of the steps. An algorithm can be compared to a recipe.

Tauira KŌrero

Nāna i tuhi tētahi koromeke urupare ki te hātepe kia pai ai tā te rorohiko kimi i te kupu e hiahiatia ana.

Me pēhea te whakamāmā i te hātepe nei?

Tuhia te hātepe nei hei waehere rorohiko, ka whakamātau ai.

WhakamĀrama Āpitihanga

Hei tauira tēnei o tētahi hātepe rorohiko māmā. Ko te whāinga o te hātepe nei, he kimi i te tau nui rawa atu (arā te mōrahi) o roto i tētahi huinga tau:

TakahangaWhakamāramaWaehere
1Ka tohua ko te kore (0) te mōrahi (m) i te tīmatanga. Arā, m = 0max = 0
2

Tirohia ia tau (x) o roto i te huinga tau (H).

Mēnā he nui ake te tau (x) i te mōrahi (m), tohua ko taua tau (x) te mōrahi hou.

for x in H:

if x > max:

max = x

3

Kua riro ināianei ko te mōrahi (m) te tau nui rawa atu o roto i te huinga tau.

return max

Tauira KŌrero

Nāna i tuhi tētahi koromeke urupare ki te hātepe kia pai ai tā te rorohiko kimi i te kupu e hiahiatia ana.

Me pēhea te whakamāmā i te hātepe nei?

Tuhia te hātepe nei hei waehere rorohiko, ka whakamātau ai.

WhakamĀrama Āpitihanga