Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, actually I'm confused how to use algorithm to a programming language? this is really make me confused. is that really important to learn algorithm for programming? and is that really useful?
Posted
Comments
[no name] 11-Oct-15 9:00am    
Maybe reading this may help: https://en.wikipedia.org/wiki/Algorithm[^]

To answer your last two questions first:
Yes.
And Yes.

The trouble is that this is a complicated area, and it's difficult to explain why algorithms are important in a small text box.

There is a relationship between algorithms and programming, but it's not always obvious because an algorithm is code independent - it doesn't resemble your "program code" necessarily that closely.
An algorithm is "a procedure or formula for solving a problem." (whatis.com, via Google) but it's more of a process than something that is obviously code, and while you can look at code and see the algorithm behind it sometimes, it's not always that easy.

Let's back up and think of what an algorithm is in the real world.
Suppose you are driving along, and you get a puncture. The obvious thing to do is to swap the punctured tyre for the spare. So the algorithm for solving your problem "I can't get from here to point B because my tyre is flat" could be:
Remove spare wheel from car.
Remove jack and wheel brace from car.
Use the jack and wheel brace to remove the wheel that has the flat tyre.
Use the wheel brace to fit the spare tire.
Put the jack, wheel brace, and punctured tyre in back in the car.

But to implement that in instructions that someone who has never tried to change a tyre will be able to follow (in the same why that a computer has to "follow" the instructions in your code) is a lot more complex: you will probably have a heck of a lot more steps, several conditional and loop constructs, and a lot more precision.
For example, the first step of the algorithm above will probably start with:
C#
Boot.Open();
if (!Boot.Contains("Spare Tyre") Panic("No spare tyre");
...

The algorithm is the process, the programming is the implementation, which is specific to your coding language, environment, and how the rest of your app works.

Are they important? Yes. If you don't understand the fundamental stuff, you will make a lot of wrong decisions. For example, if you don't know about Quick Sort you're going to have real problems if you need to implement a sort for a couple of million records and can only think of a Bubble Sort! :laugh:
 
Share this answer
 
Comments
[no name] 11-Oct-15 10:09am    
at least my 5.
Afzaal Ahmad Zeeshan 11-Oct-15 10:36am    
5ed; but it could deserve a 5 if you wrote it half of its current size. ;-)
Patrice T 11-Oct-15 10:38am    
+5
CPallini 15-Nov-20 10:57am    
5.
OriginalGriff 15-Nov-20 11:29am    
2015? Are you revisiting "Best of OriginalGriff" today? :laugh:
An algorithm is like a receipt to solve a problem.
To do a program that solve the problem, you translate the algorithm in that language.
GitHub - The-Art-of-Computer-Programming-Books: "Everyday life is like programming, I guess. If you love something you can put beauty into it." ? Donald E. Knuth[^]
 
Share this answer
 
v2
Comments
CPallini 15-Nov-20 10:57am    
Knuth reference always deserves a 5.
Patrice T 15-Nov-20 12:46pm    
Thank you.
I thought it is a good idea to add the reference as the question poped on top of list tonight. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900