What is an algorithm with example?
Hello my dear readers and visitors , In today's blog, we will learn about What is an algorithm with example? So let's start -
What is an algorithm with example?
An algorithm is a set of instructions for solving a problem or accomplishing a task or An algorithm is a representation of a solution of a problem. We solve many problems everyday without even thinking about it. For example, making breakfast, travelling to the workplace etc. Computer is a part of the means of solving problems, a procedure, explicitly state the steps required to the solutions, must be transmitted to the computer. The concept of problem solution and communication makes the study of algorithms important to computer science. The algorithm can be described on many levels because the algorithm is just the procedure of steps to take and get the result. The language used to describe an algorithm to other people will be quite different from that is used by the computer. An example of an algorithm people use would be method to make tea.
steps in the procedure and understand all the terms. A procedure is a finite sequence of well defined instructions each of which can be mechanically carried out in a finite interval
of time. The procedure must break up the problem solution into parts that the recipient party can understand and execute.
In the case of a computer, the problem solution is usually in the form of a program that encompasses the algorithm and
explains to the computer a clearly defined procedure for achieving the solution. The procedure must consist of smaller steps each of which the computer understand.
DEFINITION
ADVANTAGES
OF AN ALGORITHM
There are the following advantages of an algorithm :
·
Algorithms are machine independent.
·
Algorithms are easy to understand.
· Algorithms are easy to implement.
· Algorithms can easily be converted into flow charts.
· Algorithms help in detecting and
eliminating errors from the program.
· Algorithm are not dependent on any particular computer language.
DISADVANTAGES OF AN ALGORITHM
The big issue with algorithmic trading is that it relies on computers. Without power (electricity) or the Internet, algorithm don’t work. Computer crashes can also hamper algorithmic trading. Also, while an algorithm-based strategy may perform well on paper or in simulations, there’s no guarantee it’ll actually work in actual trading. Traders may create a seemingly perfect model that works for past market conditions but fails in the current market.
RULES FOR WRITING ALGORITHMS
There are some rules (or guidelines) for writing and algorithm. These rules makes algorithms understand by different people easily. Follow the rules as mentioned below while writing an algorithm :
·
Assign statement numbers to each line such as
Step 1, Step 2, Step 3 etc.
·
Always begin an algorithm with Start.
·
Write each instruction in a separate line.
·
Write Stop at the end of the
algorithm.
Let us take some example to
understand
the algorithm :
Example:1- Algorithm to dial a telephone number.
Step-1: Start
Step-2:Open the phone diary.
Step-3: Check the number you want to dial.
Step-4: Now take the phone receiver in your hand.
Step-5: Dial the phone number by pressing the numbers.
Step-6: Start the conversation.
Step-7: When the conversation is finished then put the receiver down.
Step-8: Put the receiver back.
Step-9: Stop
Example-2: An algorithm to get ready for school.
Step-1: Start
Step-2: Wake up
Step-3: Brush your teeth
Step-4: Do some exercise
Step-5: Take bath
Step-6: Wear your school uniform
Step-7: Take your breakfast
Step-8: Take your school bag
Step-9: Take your ID card
Step-10: Catch your school van
Step-11: Stop
Example-3: An algorithm to find sum of two numbers.
Step-1: Start
Step-2: Take first number
Step-3: Take second number
Step-4: Add the two numbers
Step-5: Write the sum
Step-1: Start
Step-2: Take first number
Step-3: Take second number
Step-4: Take third number
Step-5: Multiplication of the three numbers
Step-6: Write the multiplication
Types of Algorithms
Algorithms are classified based on the concepts that they use to accomplish a task. While there are many types of algorithms, the most fundamental types of computer science algorithms are:Divide and conquer algorithms:
Divide the problem into smaller subproblems of the same type; solve those smaller problems, and combine those solutions to solve the original problem.
Brute force algorithms:
Try all possible solutions until a satisfactory solution is found.
Randomized algorithms:
Use a random number at least once during the computation to find a solution to the problem.
Greedy algorithms:
Find an optimal solution at the local level with the intent of finding an optimal solution for the whole problem.
Recursive algorithms:
Solve the lowest and simplest version of a problem to then solve increasingly larger versions of the problem until the solution to the original problem is found.
Backtracking algorithms:
Divide the problem into subproblems, each which can be attempted to be solved; however, if the desired solution is not reached, move backwards in the problem until a path is found that moves it forward.
Dynamic programming algorithms:
Break a complex problem into a collection of simpler subproblems, then solve each of those subproblems only once, storing their solution for future use instead of re-computing their solutions.
I hope you have got a good understanding of What is an algorithm with example? If you have any doubts in this blog, then you can write for it in the comment box given below. There is one more request from you that you must tell your friends about this blog and share it on as many social media accounts 👪 as Facebook, What's app or others.