– What is an algorithm?

291 views

– What is an algorithm?

In: 8

20 Answers

Anonymous 0 Comments

It is just a structured way of solving problems.

In computer science we usually mention an algorithm in the context of recursion; which means you call the same set of instructions multiple times to achieve an end result.

Say you have algorithm ‘mow lawn’, you might look at your lawn and say:

1 – Retrieve mower
2 – Start mower
3 – Mow row 1
4 – Mow row 2
5 – Mow row 3
6 – …7
7 – Pick up clippings
8 – Wake up neighbors with leaf blower
9 – Store all equipment

You can do that same task with recursion, and you can generalize it against lawns of all shapes and sizes by calling ‘mow row’ repeatedly and using general method to determine how many times you need to call the mow row function. Without recursion I have to program my instructions bespoke to the lawn I intend to mow. With recursion I can measure things and instead of listing out each row I need to mow; I might do something like:

1 – Measure the mower deck
2 – Measure the unmowed lawn
3 – x = width of (unmowed)lawn
4 – y = width of mower deck
5 – While x > y mow row <– I repeatedly mow until x is now longer greater than y, which should leave one strip (you don’t want to say ‘while x >= y’ because then you will never leave the loop)
6 – Mow last row
7 – Pick up clippings
8 …

You are viewing 1 out of 20 answers, click here to view all answers.