tags:

views:

379

answers:

9
+3  Q: 

Algorithms in C

Hi, Can anyone please suggest to me the best place or link to learn algorithms in C? How do you know when and where to use the implementation of algorithms by just looking into the problems.

Thanks and regards, Maddy

+3  A: 

Algorithms in C by Sedgewick is a great place to start the investigation. Once you are familiar with what algorithms are available and what the performance characteristics of each are, you'll be able to see where to use each of them.

Steve Rowe
Steve,Any online documents which could be better and more understandable
+4  A: 

For a reasonable (though far from perfect) book on implementing commonly used algorithms in C, try Sedgewick's Algorithms in C. Note that as for any technical subject,a paper book is likely to be far superior to any Web resources.

As to how to know when to use a specific algorithm, I'm afraid that is down to experience.

anon
What do u mean by paper book Neil??
I'll clarify in my answer. He means having an actual book is usually better than just reading online.
GMan
Sure .Thanks a lot to GMan and Neil.I just want to make it thorough for my interview purposes.
+6  A: 

Algorithms aren't necessarily tied to a specific language, just to clarify, so any algorithms book will work great as long as you can understand the concept being the data structure/algorithm.

That said, this seems like a good choice: Algorithms in C. I have the C++ equivalent on my shelf.

There is also a book that seems language agnostic (correct me if I'm wrong) called Data Structures & Algorithm's, though I hear it's a bit dated, so you'll miss out on more recent structures.

Don't forget the internet has a plethora of information available to you. However, books are usually better for these sorts of things. This is because internet resources tend to focus on one thing at a time. For example, you need to understand what Big-O notation is before you can understand what it means when we say a List has O(1) [constant time] removal.

A book will cover these things in the correct order, but an internet resource will focus on either Big-O notation or data structures, but often won't easily connect the two.


When it comes to using it, you'll mostly make the connection when it comes to what you'll be doing with the data.

For example, you might want a vector (array) if you just need ordered elements, but if you need ordered elements and removal from any place (but can sacrifice random access), then a list would be more appropriate, due to it's constant-time removal.

GMan
GMan,Thanks a lot
Anytime. If you found either mine or someone else answer useful, be sure to up-vote the answer, and possibly mark one as correct.
GMan
A: 

How do u know when and where to use the implementation of algorithms by just looking into the problems

It's called "pattern matching", once you've seen and solved lots of problems you start to recognize common things and you can reuse your previous knowledge.

By the way, I would recommend you before a good book just on algorithms before starting with algorithms in C, which are more difficult to implement and more error prone than in higher level language, and once you are very confident with the general procedures you can start to tweak and optimize them in C.

fortran
+1  A: 

The Wikipedia List of Algorithms is also very handy reference.
And, if you want to get deeper -- The Art of Computer Programming (wikipedia ref).
Preferably after the Robert Sedgewick book already referred in multiple answers.

nik
+3  A: 

This is my collection of mostly math-related algorithms:

List of algorithms

FXT (math related)

Numerical Methods

Numerical Recipes in C

Josip
A: 

The Algorithm Design Manual is worth a look.

Martin
Yep, It's really worth a look but I think it's not the better place to look for algorithms in C. It will definitely help you to get the big picture of algorithms and it's applications in real-world situations
nairdaen
+4  A: 

For an algortihms text, Cormen, Leiserson and Rivest's 'Introduction to Algorithms' is a good start. The pseudocode implementations are easy to translate to C. Two web resources with many links to documentation about algorithms and sample implementations are:

ConcernedOfTunbridgeWells
+1  A: 

Many good resources have already been named, so I won't repeat them here.

As for how do you know what algorithm to use when?

  • You need to have a big enough tool box, which you will obtain by sitting down and slogging through a long list of basic (and them more esoteric) data structures and algorithms. You should try to get all the basics, but really only need a sample from the more specialized ones.

  • You need to understand what trade offs are available to you (time, code complexity, memory, single versus multiple passes, in-place versus copy, stable versus unstable sorts, etc. ad nauseum), and how the algorithms you study do on each of these. Again, this is just a case of much studying. Big-O is a place to start, but is not the end all and be all of this.

  • You need to get a feel for understanding what are the real limits you face when presented with a problem, and how to express these in terms of the algorithm trade offs mentioned above. This requires a degree of intuition, and is generally learned by practice over time.

  • It is worth implementing some things more then one way as you go along, to learn in your gut, what works and what doesn't.

  • It is worth reading code written by folks more experienced than yourself, to see how they think.

Good luck.

dmckee