Social Question

sumitnxt's avatar

What exactly is an algorithm?

Asked by sumitnxt (108points) October 20th, 2009

i’ve got a programming related problem to solve . first i have to write its algorithm. please introduce me to an algorithm

Observing members: 0 Composing members: 0

11 Answers

jackm's avatar

Its a series of steps designed to complete a task.

gussnarp's avatar

Wow, you have to write an algorithm and no one told you what one is yet? Actually, I find that when the concept of an algorithm is introduced people often have trouble really locking down what it is. Basically an algorithm is just a fixed process to achieve some goal, or if you prefer, a set of steps. You may want to ask whoever wants to see the algorithm how they want it written. You could just use plain English, or you could use pseudocode, which looks a lot like a programming language, but isn’t quite so rigid.

The best algorithm for producing an algorithm is to start general, then get more specific. So start with your start (A) and end (B) points, then as generally as possible describe what you have to do to get from A to B. Then start to fill in steps in more detail.

MrItty's avatar

Here’s an “algorithm” for what you might do online every day.

Turn on computer
Open Web Browser
Check email
for each mail IN new mail
if mail requires reply
reply to: mail
endif
endfor
browse to: fluther.com
ask question
while ! question answered
wait
endwhile

gussnarp's avatar

@MrItty has supplied a great example of an algorithm written in pseudocode for you there.

dpworkin's avatar

Think of an algorithm as being analogous to a recipe. Leave no step out, add no extraneous steps.

Ivan's avatar

What they said ^^

So in a program, the algorithm is essentially the mathematics and procedure that your program will do. So for instance, if you wanted to write a program that added 1 to a number that you input, the algorithm would just be (y = x + 1). You then have to convert this into a language that the computer can understand. For instance, define “input”, output = input +1, display “output”, etc.

mattbrowne's avatar

An algorithm is an abstract concept like natural numbers. The concept refers to an approach to solve a problem or carry out a task.

Natural numbers are represented by symbols like 1,2,5,10 or I, II, V, X.

Algorithms are represented by text in natural language or by computer programs.

So essentially, at first you don’t have to write anything. You need to understand the problem and come up with an approach. There are ways to bridge the gap between abstract concepts in your head and a computer program. Examples are pseudocode or Nassi-Shneiderman diagrams. For more complex problems UML can be useful. Some people prefer to write code right away and see what happens. Trial-error can be a good method of problem solving.

prasad's avatar

Wow, great concepts.

Is algorithm written in plain English or steps or should I have to make it a flow chart out of it? Is so built flow chart then be called as an algorithm? Because I’ve seen many algorithms (I say so) as flow charts, as they are easy to read and/or remember.

gussnarp's avatar

@prasad An algorithm could be in plain English, it could be in a flow chart, it could be in pseudocode, or if it is simple and you are a fairly proficient coder you might just write it in code (although that does sort of take it from algorithm to program). If I was asked for one for a computer science class and not given specific instructions as to format, I would provide something in pseueocode very much like what @MrItty wrote above.

mattbrowne's avatar

@prasad – The flow chart is the representation of the algorithm. Yes, there are many and yes they offer a good way to memorize algorithms. You can’t “touch” or “see” an abstract concept like an algorithm. There are different opinions about the most elegant representation of certain algorithms. Let’s take Quicksort as an example which got a complexity of O(n x log(n)). I love the Lisp version of it, which I found somewhere on the web. The author wrote: “I have discovered the definition of beauty.” Fluther ruins indentation unfortunately.

(defun quicksort (lis) (if (null lis) nil
(let* ((x (car lis)) (r (cdr lis)) (fn (lambda (a) (< a x))))
(append (quicksort (remove-if-not fn r)) (list x)
(quicksort (remove-if fn r))))))

http://swisspig.net/r/post/blog-200603301157

Now can anyone beat this by a shorter and more elegant Java program??

Zuma's avatar

Lather, scrub, rinse, repeat until clean.

Answer this question

Login

or

Join

to answer.
Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther