Skip to main content

Algorithm



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

Popular posts from this blog

Fibonacci Sequence Flowchart

Fibonacci Sequence Flowchart In the previous video of Fibonacci sequence ,we learned about the Fibonacci series and how to write an algorithm. In this video we will learn how to draw a flowchart for it. First let us write an algorithm for it again. 0,1,1,2,3,5,8,13,21,34,55,89,… Step1: Input the number(n) till which the Fibonacci series will run Step2: Assign the variables a equal to -1 and b equal to 1 Step3: Add the variables a & b and assign it to variable x Step4: Display the value of x Step5: Assign the value of b to variable a Step6: Assign the value of x to variable b Step7: Subtract one from n and store it to variable n Step8: If the value of n is not zero, go back to the Step3 Step9: Fibonacci numbers displayed till n numbers. To see the working of above flowchart,  Click here to Watch on YouTube To write the program in C,   Click here to Watch on YouTube To make the Fibonacci Sequence  And...

Decimal Number to Binary Number

A Binary Number consists of  0 s & 1 s only (Two Digits)   whereas a  Decimal Number Consists of 0,1,2,3,4,5,6,7,8,9 (ten digits) .                   For Example ( 111 )2 is binary number equivalent to decimal number ( 7 )10.  A bit is a single Binary Digit. The binary number above has three bits. Algorithm Divide the dividend(number) by divisor 2 and get the remainder & the quotient. If the quotient is not zero, then quotient becomes dividend and follow above step. As quotient has now become zero, the binary number is all the remainders from bottom or from right side which consists of 0 & 1. Flowchart To see the working of above Flowchart Click here to watch it on YouTube

Prime Numbers

Prime Number is a natural number greater than 1 that has exactly two distinct natural number divisors: 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number. For example, 13 can only be divided by 1 and  by 13 itself. Here is a list of all the prime numbers up to 100: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47, 53,59,61,67,71,73,79,83,89,97,.. 1 is not a prime number as in definition “For a number to be prime it must have two  d istinct (different) factors. Algorithm Step1: Input the number(n) to check for prime number Step2: If n is below or equal to 1  then go to step 12 Step3: if n is equal to 2 then go to step 11 Step4: Assign variable count =n / 2 Step5: Assign variable a=1 Step6: Add 1 to a and store it to variable a Step7: remainder = n % a Step8: if remainder=0 then go to step 12 Step9: subtract one from count and store it to variable count Step10: if count is not equal to 0 then go to s...