Algorithms

The snow unfortunately has caused problems within the school and lessons have been distrupted but we must get cracking on.

An algorithm is an effective method for solving a problem using a finite sequence of instructions. Algorithms are used for calculation, data processing, and many other fields. The first few examples of a standard algorithm used unconditional loops;

1) Set found flag to false  

 2) Enter item to be found  

3) FOR each item in the list  

4)  IF current item = item to be found THEN

 5)  set Found flag to true

6)  display item and its location

7)  END IF

8.) NEXT item

9) If Found flag = false display “not found” message

This is already in the powerpoint but for those that will not look at it, this is used to find an item on a list. How it works is that it searches through all the list and finds the object that the user was looking for.  The next one we looked at was “COUNTING OCCURENCES”. This algorithm is used to count how many times the value appears on the list which is given.

1) Set the number of times item found (hits) to zero

2) Ask user for item to be found

3) Enter item to be found

4) FOR each item in the list

5)  IF current item = item to be found THEN

6)  add 1 to number of occurrences

7)  END IF 8.NEXT item

8.) Display number of occurrences

Now this is very useful when looking for an object and how many times it appears. The last two ones we looked at were the “MAXIMUM” & “MINIMUM” This is it;

1) Set maximum value to be equal to the first item in list

2) FOR each item in the list

3)  IF current item > maximum value THEN

4)  set maximum value to current item

5)  END IF

6) Next item

7) Display maximum value

This is useful when looking for the largest value. The minimum algorithm is the exact same but MINIMUM is put in place instead of the MAXIMUM. We then went on the computer and used these. Remember and post comments on blogs and look on glow for the helpful information!

P.S I would add photo’s but I have no clue what photo’s I would add to this.

One thought on “Algorithms”

Comments are closed.