This content originally appeared on DEV Community and was authored by Chaitanya Prabuddha
What Is An Algorithm? If you find this question on google, you will get “It is a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.” But when I had seen this definition initially, I wasn’t able to understand anything, It emerged as a piece of literature for me. I was drastically surprised by how complexly a simple definition can be presented. Since I know this by now, so let me help you to understand it.
An algorithm is a process of doing some work, Let’s suppose you are given chicken & rice, now it depends on your algorithm(the process of doing something) that whether the output will be chicken masala or will be kabab.
In programming different algorithm is used to obtain different outputs and even for single output different algorithms can be used, its kind of a pathway to reach the destination, you can choose any path. But the less time your path takes the better that algorithm will be called.
How To Solve An Algorithm-
In How to Solve It, George Polya outlines four steps of problem-solving:
Understand the problem.
Make a plan.
Execute the plan.
Evaluate the result.
Understand the Problem
If you’re a good developer, you’ll realize that the best solutions emerge from listening to your customer tell their story. Many algorithms are disguised as story problems, such as the farmer who needs to get duck, corn, and a fox across the river. But! He can only carry one of these at a time. If left alone, the duck will eat the corn and the fox will eat the duck. How does he get everything across?
What you should do is :
AS A < USER OF SOME SORT >
I WANT < TO DO THIS >
SO THAT < MY EXISTENCE IS VALIDATED >
In our farmer example above:
AS A farmer
I WANT to ferry my duck, fox, and corn across the river
SO THAT we all live happily ever after
The format for acceptance criteria is:
GIVEN < APPLICATION >
WHEN < I DO THIS >
THEN < I EXPECT THE APP TO DO THAT >
In our farmer example above:
GIVE three items that will eat each other
WHEN I ferry one item across the river
THEN the other two are safe
Make a Plan
The next step in Polya’s heuristic is to make a plan.
AKA pseudocode.
You write pseudocode, don’t you?
Writing pseudocode is like making a sketch for a design.
It’s your back-of-the-envelope proof-of-concept.
It’s your discovery phase, your user research, your market validation.
It’s your roadmap.
It’s also the comments for your function. Just // each line and walla, there you go.
Execute the Plan
It’s showtime!
After all this problem understanding and plan-making, it’s time to crack your fingers, dust off the keyboard, and write some code! This part will be easy because why? Because you wrote pseudocode! All you need to do now is translate that plain language into JavaScript, Python, or (shudder) Java. Then hit Enter…
Evaluate the Plan
Did your plan work?
If no, back to step 1.
If yes, can you do better?
How to Solve It with Computational Thinking
The steps above are table stakes for problem-solving and can be applied to any domain. If you want to turn pro, you need to assimilate with the Borg and learn how to think like a computer. There are four primary stages of computational thinking:
Decomposition
Generalization
Abstraction
Algorithms
A detailed Information About THESE COULD BE FOUND HERE
Evaluate the result.
If your plan and your execution go well, then you are safe in running in a small run. But if you want You Run a Maraton rather than a race, you have to evaluate this to make your work even better.
How to Solve Any Algorithm
You can solve any algorithm using Polya’s heuristic and computational thinking. Just believe in yourself and execute it, nothing is hard for anyone.
Everything We Use Now Is Made
With the power of the Human Brain.
If Human can make it, then Human can solve it too.
THANKS FOR TUNING IN!
Just for fun, let's also solve the farmer's problem-
The farmer brings duck to side b
Farmer goes back to side a
The farmer brings fox over to side b
The farmer brings duck back to side a
The farmer brings corn to side b
Farmer goes back to side a
The farmer brings duck to side b
This way the Fox is never left alone with the duck and the duck is never left alone with the corn while getting all three to side b. No need for a cage!
— Bye —
This content originally appeared on DEV Community and was authored by Chaitanya Prabuddha
Chaitanya Prabuddha | Sciencx (2021-05-22T21:21:48+00:00) The Art Of Solving An Algorithm. Retrieved from https://www.scien.cx/2021/05/22/the-art-of-solving-an-algorithm/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.