+ 3
What is an algorithm?with example
3 Respostas
+ 20
It's the process made to solve a problem.
Example:
I want a cake but i have no money, i think about possible solutions.
1. Steal Money
2. Sell my house
3. Work and earn money
So... i'll choose one of these solutions to solve my issue.
Basically, that's it.
Real algorithms can be more complex but you make at least one/two algorithms per day to solve quotidian problems and you can show your algorithms through a tree graphic with all possible solutions. :)
+ 4
An algorithms is a step by step process to carry out a task, in other words, exactly HOW you go about doing something. In programming it's the set of instructions you give the computer so that is can carry out a task in the most effective way possible.
Ex: if you wanted to find a name in a list, say, to see if Janet was invited to your party. In real life you would look at the list, name by name, until you either come across the name Janet or reach the end of the list.
in programming (in this case javascript) it would look something like this:
var names = [
"Mark",
"Joe",
"Lauren",
"Martha",
"Janet"
];
function checkName(x) {
for (var i = 0; i < names.length; i++) {
if (names[i] === x){
return true;
}
}
return false;
}
console.log(checkName("Janet"));
--------------------------------------------------------------
This example would print true to the console because Janet is present in the names array. Otherwise it would print false.
--------------------------------------------------------------
The example above is a 'linear' approach (checking if a condition is true one at a time), but there are many other ways, even much faster ways, of doing this which I hope you learn all about because good algorithms make the world a better place :)
Anyhow I hope this helps. Have a wonderful day and Happy Coding!
- 4
you have a facebook..if you have facebook..wat's is your name profil