What is an algorithm?
Algorithm is a set of simple steps written to solve a particular task.
There can be many task from waking up to going to school, logging on to a gmail account or finding prime numbers etc.
For example write an algorithm for logging onto gmail account and checking your mails.
STEP1:Open a browser in your desktop/laptop
STEP2:Write gmail address www.gmail.com on address bar url of browser.
STEP3:Login onto your gmail account with your username and password
STEP4:Check your mails if your username and password is correct
STEP5:After doing your work on gmail account, logout.
Algorithm is a step-by-step list of directions that need to be followed to solve a problem.
A recipe can be considered as a type of algorithm.It tells what ingredients are needed to make the dish and what steps to follow.There can be many different recipes to make a certain dish which looks different but ends up tasting the same when all is said and done. The same is true for algorithms.When we write algorithms, we like our algorithm to take the least amount of time so that we can solve our problem as quickly as possible.
So lets write an algorithm for sorting cards with colors on them into piles of the same color.
STEP1: Pick up all the cards.
STEP2: Pick a card from your hand and look at the color of the card.
STEP3: If there is already a pile of cards of that color, put this card on that pile.
STEP4: If there is no pile of cards of that color, make a new pile of just this card color.
STEP5: If there is still a card in your hand go back to the second step.
STEP6: You are done and all cards sorted.
To view the working of this algorithm watch the video
Click here to Watch on YouTube
Comments
Post a Comment