views:

371

answers:

10

I currently work with PHP and Ruby on Rails as a web developer. My question is why would I need to know algorithms and data structures? Do I need to learn C, C++ or Java first? What are the practical benefits of knowing algorithms and data structures? What are algorithms and data structures in layman’s terms? (As you can tell unfortunately I have not done a CS course.)

Please provide as much information as possible and thank you in advance ;-)

+7  A: 

Data structures are ways of storing stuff, just like you can put stuff in stacks, queues, heaps and buckets - you can do the same thing with data.

Algorithms are recipes or instructions, the quick start manual for your coffee maker is an algorithm to make coffee.

Kimvais
+1  A: 

An algorithm is a list of instructions and data structures are ways to represent information. If you're writing computer programs then you're already using algorithms and data structures even if you don't know what the words mean.

I think the biggest advantages in knowing standard algorithms and data structures are:

  • You can communicate with other programmers using a common language.
  • Other people will be able to understand your code once you've left.

You will also learn better methods for solving common problems. You could probably solve these problems eventually anyway even without knowing the standard way to do it, but you will spend a lot of time reinventing the wheel and it's unlikely your solutions will be as good as those that thousands of experts have worked on and improved over the years.

Mark Byers
A: 

An algorithm is a representation of the process involved in a computation.

If you wanted to add two numbers then the algorithm might go:

Get first number; Get second number; Add first number to second number; Return result.

At its simplest, an algorithm is just a structured list of things to do - its use in computing is that it allows people to see the intent behind the code and makes logical (as opposed to syntactical) errors easier to spot.

e.g. if step three above said multiply instead of add then someone would be able to point out the error in the logic without having to debug code.

A data structure is a representation of how a system's data should be referenced. It might match a table structure exactly or may be de-normalised to make data access easier. At its simplest it should show how the entities in a system are related.

It is too large a topic to go into in detail but there are plenty of resources on the web.

melkisadek
A: 

Data structures are critical the second your software has more than a handful of users. Algorithms is a broad topic, and you'll want to study it if a good knowledge of data structures doesn't fix your performance problems.

You probably don't need a new programming language to benefit from data structures knowledge, though PHP (and other high level languages) will make a lot of it invisible to you, unless you know where to look. Java is my personal favorite learning language for stuff like this, but that's pretty subjective.

ojrac
+1  A: 

alt text This book is the bible on algorithms. In general, data structures relate to how to organize your data to access it in memory, and algorithms are methods / small programs to resolve problems (ex: sorting a list).
The reason you should care is first to understand what can go wrong in your code; poorly implemented algorithms can perform very badly compared to "proven" ones. Knowing classic algorithms and what performance to expect from them helps in knowing how good your code can be, and whether you can/should improve it.
Then there is no need to reinvent the wheel, and rewrite a buggy or sub-optimal implementation of a well-known structure or algorithm.

Mathias
+1  A: 

Algorithms are, quite simply, the steps by which you do something. For instance the Coffee Maker Algorithm would run something like

  1. Turn on Coffee Maker
  2. Grind Coffee Beans
  3. Put in filter and place coffee in filter
  4. Add Water
  5. Start brewing process
  6. Drink coffee

A data structure is a means by which we store information in a organized fashion. For further info, check out the Wikipedia Article.

+1  A: 

An algorithm is a sequence of well defined steps leading to the solution of a type of problem.

A data structure is a way to store and organize data to facilitate access and modifications.

The benefit of knowing standard algorithms and data structures is they are mostly better than you yourself could develop. They are the result of months or even years of work by people who are far more intelligent than the majority of programmers. Knowing a range of data structures and algorithms allows you to fit a problem roughly to a data structure or/and algorithm and tweak as required.

Yacoby
+1  A: 

In the classic "cooking/baking equivalent", algorithms are recipes and data structures are your measuring cups, your baking sheets, your cookie cutters, mixing bowls and essentially any other tool you would be using (your cooker is your compiler/interpreter, though).

Vatine
A: 

Watch the SICP video lectures on youtube and find the answer to your question.

Alex
A: 

My question is why would I need to know algorithms and data structures?

If you are doing any non-trivial programming, it is a good idea to understand the class data structures and algorithms and their uses in order to avoid reinventing the wheel. For example, if you need to put an array of things in order, you need to understand the various ways of sorting, so that you can choose the most appropriate one for the task in hand. If you choose the wrong approach, you can end up with a program that is grossly inefficient in some circumstances.

Do I need to learn C, C++ or Java first?

You need to know how to program in some language in order to understand what the algorithms and data structures do.

What are the practical benefits of knowing algorithms and data structures?

The main practical benefits are:

  • to avoid having to reinvent the wheel all of the time,
  • to avoid the problem of square wheels.
Stephen C