You are on page 1of 4

M3- Explain the stages of a recursive algorithm showing how the termination condition is reached

December 11, 2013

Introduction1 Part 1..1 Part 2..2 Conclusion3 Reference.4

Introduction
In this document I will talk about algorithms types and I will also talk about recursive algorithm and its termination condition. I will also be assessing a real li e scenario in which I am being asked to e!plain one algorithm type choosing rom these two "bubble algorithm and sorting algorithm#I will be doing bubble algorithm. $his document will be divided in two parts starting with %art1 and inishing with %art 2.

Part 1
1. &hat is an algorithm' $o make a computer do something that can help you ,you have to make a program to make a program to make a program you need to give the computer a step by step instruction o what to do this is called an algorithm. &hen you get to tell the computer what to do you also get to tell him how to do it .(lgorithms can take di erent )shapes and )colours ,making an algorithm is much like teaching you can have a di erent style o teaching than someone else . ( real li e algorithm would look like this. a# *tep orward with right leg. b# *tep orward with le t leg. c# *top when you hit a red light. "$erminating condition# 2. &hat is meant by recursive algorithm' ( recursive algorithm is a type o algorithm its an algorithm that repeats certain steps in order to get to a given result .( good e!ample would be baking a cake when you only want to make one cake you use a recipe "algorithm#but when you want to make more than one its called repeating the recipe "recursive algorithm#

M3- Explain the stages of a recursive algorithm showing how the termination condition is reached

December 11, 2013 ( recursive algorithm is an algorithm which calls itsel with +smaller "or simpler#+ input values, and which obtains the result or the current input by applying simple operations to the returned value or the smaller "or simpler# input. ,ore generally i a problem can be solved utili-ing solutions to smaller versions o the same problem, and the smaller versions reduce to easily solvable cases, then one can use a recursive algorithm to solve that problem. .or e!ample, the elements o a recursively de ined set, or the value o a recursively de ined unction can be obtained by a recursive algorithm. 3. &hat is meant by termination condition' (n algorithm cannot run orever it has to stop at some point/ the point that it stops it is o ten called a termination condition. 0ut what does termination condition mean' It means that when you cakes and you want to stop at 10 cakes you tell the computer to stop at 10 cakes. In computing, 1ecursion termination is when certain conditions are met and the recursive algorithm ceases calling itsel and begins to return values. $his happens only i with every recursive call the recursive algorithm changes its state and moves towards the base case. 2ases that satis y the de inition without being de ined in terms o the de inition itsel are called base cases. $hey are small enough to solve directly.

Part 2
(lgorithms are o di erent types I have chosen to e!plain the sorting algorithm. ( sorting algorithm is a algorithm that sorts a group o numbers3letters in the order programed to ascending3descending. 0ut why do you need it' &ell a computer only understands bits and bytes hence 031 and i say you are looking or an item in a long list you need to irst sort it then search or it using another algorithm. 0ut why so many steps' *ome o you might be thinking why do we have to run so many algorithms when we could say 4ust run a binary code or the word3number that we are looking or .&ell as my teacher e!plained to me, she said i you were to 4ust look or the binary code you would overrun the computer with millions o bits and bytes and there ore not only it is hard or the computer to per orm that but it is not e icient either. *ay we want to ind the ascending order o the ollowing list o numbers5 6, 2, 7, 89, 2, 6 &ell irst we compare the irst two numbers 6:2 ;iven that they need to be in ascending order 6 bigger than two so no swaps, only then we take the second number "2#. 2<7 *o then we swap again we continue until we get to the end o the list. 2<89 2

M3- Explain the stages of a recursive algorithm showing how the termination condition is reached

December 11, 2013 2=2 2<6 *o then our list will look like this5 6, 7, 89, 2, 6, 2 &ith 3 swaps. &ith the smallest number at the end in red.">ote this number does not needs to be changed when the algorithm is runed again#. $he process repeats, until no swaps are le t. 6:7 7<89 7:2 2<6 $he list will look like this5 6, 89, 7, 6, 2, 2 &ith 7 swaps. ?ur second smallest number is 2. &e run another algorithm. 6<89 6:7 7<6 $he list is as ollows5 89, 6, 6, 7, 2, 2 &ith 3 swaps. ?ur list is in descending order we can see it but the computer doesnt so it runs another algorithm in which it does no swaps so there ore stops the process. 89, 6, 6, 7, 2, 2 &ith 0 swaps. >ow lets talk about how would you trans er this to pseudo code. &ell its simple all you need to understand is that the computer knows absolutely nothing about nothing outside o the bo! in which it has all the codes the unit. &e start by assigning a value ! a value o 0 and we add 1 with every run we take .(nd so there ore i our values are smaller or bigger depending on how the list must be ascending3descending. @ence our algorithm is inished. Conclusion I have e!plained in two parts what an algorithm is ,what does recursion mean where and when is termination condition is used and I have also gave an e!ample o a bubble algorithm in which the termination condition has been used. Reference http533www.howstu works.com3Auestion818.htm "accessed on 123December32013 B539# http533en.wikipedia.org3wiki31ecursionC"computerCscience# "accessed on 123December32013 B538#

M3- Explain the stages of a recursive algorithm showing how the termination condition is reached

December 11, 2013

You might also like