Author Topic: Algorithms book  (Read 1754 times)

Nick1911

  • Administrator
  • Senior Member
  • *****
  • Posts: 8,492
Algorithms book
« on: November 27, 2007, 10:05:48 AM »
Can anyone recommend me a good algorithms book?  I have background in programming, but my major has short changed me when it comes to topics other then syntax.  I'm looking for something that has some of the mathematical side, but isn't written for a math major.  I want a lot of real world algorithms that are likely to be useful for me as a professional programmer, but I also want to understand algorithm design.  I'll pay good money for a book that does these things in a clear, easy to follow manner.  I'm not opposed to using a college text, but I don't just want a bunch of exercises with no answer key.

Any recommendations?  I'm considering this book, which is used in the Computer Science department here at Purdue.  Doe anyone have experience with it?

TIA

Len Budney

  • Senior Member
  • **
  • Posts: 1,023
Re: Algorithms book
« Reply #1 on: November 27, 2007, 10:11:50 AM »
I'm considering this book, which is used in the Computer Science department here at Purdue.  Doe anyone have experience with it?

That's the one I used in grad school. It's an awesome reference. However, you might find it a bit math-heavy. It's much nearer the academic end than an algorithm "cook book." The focus throughout is on measuring the complexity of various algorithms.

--Len.
In a cannibal society, vegetarians arouse suspicion.

jefnvk

  • friend
  • Senior Member
  • ***
  • Posts: 1,478
  • I'll sleep away the days and ride the nights...
Re: Algorithms book
« Reply #2 on: November 27, 2007, 10:20:58 AM »
Hmmmmm......


Hmmmmmmmm...........


I may be sitting in Algorithms using that book right now  grin

Not bad at all, I can learn from it by myself (i.e., no needing help from other books or teacher), but I will second what Len said.  Very focused on efficency/complexity.  Also, in parts, it isn't easy to follow if you are just looking for a quick reference, it is more necesary to read the whole chapter.
I still say 'Give Detroit to Canada'

Tallpine

  • friends
  • Senior Member
  • ***
  • Posts: 23,172
  • Grumpy Old Grandpa
Re: Algorithms book
« Reply #3 on: November 27, 2007, 11:23:18 AM »
At some point you need to be able to figure out an algorithm on your own, for the particular purpose at hand.

Though a reference for various search algorithms, etc could be handy.

Do you have a programming job yet, or what ...?
Freedom is a heavy load, a great and strange burden for the spirit to undertake. It is not easy. It is not a gift given, but a choice made, and the choice may be a hard one. The road goes upward toward the light; but the laden traveller may never reach the end of it.  - Ursula Le Guin

Marnoot

  • friend
  • Senior Member
  • ***
  • Posts: 2,965
Re: Algorithms book
« Reply #4 on: November 27, 2007, 12:25:58 PM »
I have some interest in this subject as well. I'm employed as a software engineer, but my major was Information Systems Management. Thus my programming education was pretty lacking as compared to a CS degree. I'm hobbling along well enough, picking things up, but am severely lacking in theory. A good algorithm book like Nick1911 is looking for would be great.

Nick1911

  • Administrator
  • Senior Member
  • *****
  • Posts: 8,492
Re: Algorithms book
« Reply #5 on: November 27, 2007, 02:06:42 PM »
Thanks for the info.  I'm going to pick up a used copy of the book I referenced as a jumping off point.

Quote
Do you have a programming job yet, or what ...?

I am graduating in about three weeks with a degree in Computer Technology from Purdue.  I have accepted a position working for a medical software company after I graduate.  The Purdue CPT department is big on business case systems analysis and design, but severely lacking in programming technique or theory.  For the sake of brevity, I'm going to stop here.  I could write a loooong essay about what is wrong with our department.  angry


jefnvk

  • friend
  • Senior Member
  • ***
  • Posts: 1,478
  • I'll sleep away the days and ride the nights...
Re: Algorithms book
« Reply #6 on: November 27, 2007, 02:22:36 PM »
So I take it that your degree is more along the lines of IT?  As in, admin stuff, not developing stuff?

Another point, one book to avoid is Fundamentals of Algorithmics by Brassard and Bratley.  It is very poorly written, a lot of good information, but hard to understand if you have no previous experience.
I still say 'Give Detroit to Canada'

Nick1911

  • Administrator
  • Senior Member
  • *****
  • Posts: 8,492
Re: Algorithms book
« Reply #7 on: November 27, 2007, 03:14:55 PM »
So I take it that your degree is more along the lines of IT?  As in, admin stuff, not developing stuff?

Ehh... more like MIS.

Tallpine

  • friends
  • Senior Member
  • ***
  • Posts: 23,172
  • Grumpy Old Grandpa
Re: Algorithms book
« Reply #8 on: November 27, 2007, 03:25:02 PM »
FWIW, IMO structure is more important than algorithms - as in, what operations to break out into separate functions (procedures) and/or class structures.  OOP is the way to go now, unless you are writing low level embedded code (ANSI C for instance). 

A function/procedure should implement a single algorithm (or a repeated piece of an algorithm) and ideally should all fit on one page and/or one screen for simplicity and clarity.  And function/variable names should be understandable and meaningful.

Generally, software costs more to design and maintain than it does to just write up code the first time around.  When a change request comes (and it always does), it's much better if you don't have to edit the code in 99 different places just to effect a simple change.

I went to a lousy school (at the time) that only had a CS minor, but I did have a couple of really good professors that I learned a lot from.  Anyway, from my experience of corporations, they won't expect too much out of you right out of school anyway. rolleyes
Freedom is a heavy load, a great and strange burden for the spirit to undertake. It is not easy. It is not a gift given, but a choice made, and the choice may be a hard one. The road goes upward toward the light; but the laden traveller may never reach the end of it.  - Ursula Le Guin

Antibubba

  • friend
  • Senior Member
  • ***
  • Posts: 3,836
Re: Algorithms book
« Reply #9 on: November 27, 2007, 08:18:01 PM »
Look, I come here to get away from all that global warming, save the planet crap!

What?

Oops, sorry, I thought you said "Al Gore-isms"



Never mind!
If life gives you melons, you may be dyslexic.

jefnvk

  • friend
  • Senior Member
  • ***
  • Posts: 1,478
  • I'll sleep away the days and ride the nights...
Re: Algorithms book
« Reply #10 on: November 28, 2007, 06:30:32 AM »
Quote
FWIW, IMO structure is more important than algorithms - as in, what operations to break out into separate functions (procedures) and/or class structures.  OOP is the way to go now, unless you are writing low level embedded code (ANSI C for instance). 

A big point of algorithms is to figure out what you need to do, and then figure out how to optimize it to best work.

Take sorting, for example.  A heapsort can run in O(n lg n) time, while bubble sort runs in O(n^2) time, where n refers to the number of elements.  For 5 items, ya, not a big time savings.  For 50,000 items, heapsort will have a coefficient of 15.6, while the bubble sort will have a coefficient of 2500000, meaning heapsort will run about 160256410 times faster.

Rearranging how things are called can also lead to time savings, however, it won't lead to the drastic savings that using the correct algorithm will.
I still say 'Give Detroit to Canada'

Tallpine

  • friends
  • Senior Member
  • ***
  • Posts: 23,172
  • Grumpy Old Grandpa
Re: Algorithms book
« Reply #11 on: November 28, 2007, 12:36:52 PM »
Admittedly sort and search algorithms have a great deal of variance in efficiency.  Oher operations, not so much maybe.  But we were heavily into search theory by my second semester of programming.

Just make sure that if you decide to switch to a different algorithm that you don't have to change it in 50,000 places in your code  laugh
Freedom is a heavy load, a great and strange burden for the spirit to undertake. It is not easy. It is not a gift given, but a choice made, and the choice may be a hard one. The road goes upward toward the light; but the laden traveller may never reach the end of it.  - Ursula Le Guin

jefnvk

  • friend
  • Senior Member
  • ***
  • Posts: 1,478
  • I'll sleep away the days and ride the nights...
Re: Algorithms book
« Reply #12 on: November 28, 2007, 12:57:34 PM »
Quote
Just make sure that if you decide to switch to a different algorithm that you don't have to change it in 50,000 places in your code 

Actually, the goal is to make your code as obscure and difficult to maintain as possible.  Job security, ya know Smiley
I still say 'Give Detroit to Canada'

Nightfall

  • friend
  • Senior Member
  • ***
  • Posts: 916
Re: Algorithms book
« Reply #13 on: November 28, 2007, 09:37:20 PM »
*sigh* This thread makes me miss programming.
It is difficult if not impossible to reason a person out of a position they did not reason themselves into. - 230RN

Tallpine

  • friends
  • Senior Member
  • ***
  • Posts: 23,172
  • Grumpy Old Grandpa
Re: Algorithms book
« Reply #14 on: November 29, 2007, 07:13:51 AM »
Quote
Actually, the goal is to make your code as obscure and difficult to maintain as possible.

That is painfully obvious considering the legacy projects I have worked on.  undecided
Freedom is a heavy load, a great and strange burden for the spirit to undertake. It is not easy. It is not a gift given, but a choice made, and the choice may be a hard one. The road goes upward toward the light; but the laden traveller may never reach the end of it.  - Ursula Le Guin

Bogie

  • friend
  • Senior Member
  • ***
  • Posts: 10,207
  • Hunkered in South St. Louis, right by Route 66
    • Third Rate Pundit
Re: Algorithms book
« Reply #15 on: November 29, 2007, 07:41:50 AM »
I would suggestion An Inconvenient Truth, but Al and Tipper have NO rhythm, as evidenced by their efforts to severely censor pop music (and your average "liberal" won't believe you on that one - sigh...).
 
Oh. That kind of algorithm. Nevermind.
 
Blog under construction

ymike

  • New Member
  • Posts: 1
Re: Algorithms book
« Reply #16 on: November 29, 2007, 02:28:06 PM »
You probably want to look up Donald Knuth's books on Algorithms - they're the classics in computer science, and have been for years. See Wikipedia on Knuth. Problem is, they're likely out of print, and expensive. I haven't seen them in bookstores in years.

GigaBuist

  • friends
  • Senior Member
  • ***
  • Posts: 4,345
    • http://www.justinbuist.org/blog/
Re: Algorithms book
« Reply #17 on: November 29, 2007, 05:04:19 PM »
You probably want to look up Donald Knuth's books on Algorithms - they're the classics in computer science, and have been for years. See Wikipedia on Knuth. Problem is, they're likely out of print, and expensive. I haven't seen them in bookstores in years.

The Art of Computer Programming is still in print.  You can find them on Amazon right now.

Little back story on those books:  Knuth was contacted to write 'The Art of Computer Programming' sometime around 1965.  It might have been later.  Somewhere along the line he found that current typesetting software wasn't up to his standards so he wrote TeX just to make sure his books looked right.  Come '67 or '68 the publisher called him up and asked how things were progressing.  Knuth responded that he was almost done with chapter 1 of the book.  The published asked how big that was.  Knuth checked and informed them that Chapter 1 was almost 400 pages long.

So, they decided to make each chapter its own volume at that point. Smiley

Some more trivia:  Knuth kept patching up TeX and at version 3.0 he considered it complete.  He would only do bugfixes at that point, and decided that he'd add another digit of pi to the version number for each bug fix.  So, that's why TeX is at version 3.141592 (or whatever it actually is right now, too lazy to look it up.)

They're pretty heavy reading if your major was MIS I suppose.  He presents all discussion in an imaginary languaged called MIX which is an assembly like language.  Good stuff, if you can follow it.

Really, if you can get your head around Big-O notation and spot a code section's Big-O fairly quickly you're 80% of the way there.  That'll keep you from doing the vast majority of stupid things that people do when working with any significant amount of data.  Little stuff like knowing with to use a HashMap for lookups instead of bombing through an ArrayList looking for the piece of data you want.

Or, knowing the difference between a mutable and immutable data storage type.  It's really easy to get burned with string concatenation in this area.  Hell, happened to me just a couple of years ago.  I wrote a stupid routine function to take a string and re-encode it into something that could be stored in plain ASCII, then restore it back to proper Unicode when it came out.  It was intended for strings that would be no longer than 255 chars, though that wasn't really in the design spec -- just an unwritten rule I had in my head.  Well, once somebody started mashing 10k of data through it performance fell through the floor but we had no idea where it was.  When it was found to be my little code snippet I wrote some unit tests, found that it'd take 5 minutes to encode 10k of data, optimized it, and got that down to a second.  It's simple to do it the right way, but it's damned simple to do it the wrong way too.

Honestly, working as a programmer that's been doing business application for about 7 years now, efficient algorithms are the least of your worries.  So long as you properly segment your code, as has been mentioned above, you'll be able to fix up any performance problems related to algorithms quickly and painlessly.  If you obsess about speed all the time you just might end up taking more time to develop the software than is necessary.

I've never seen a project crippled because of one stupid simple code segment.  They're easily replaced.  However, bad design is almost impossible to overcome once the project is in full swing.  Let's take my last major project as an example:

Platform:  Java
Design:  Delegate / Facade
Example:

The Web UI portion instantiates a Delegate and makes a call into that delegate which passes the call into the Facade layer, which adheres to the same interface as the Facade Security Bean, which then makes a call into the Business Management layer of the object in question which then passes that call into the Data Access Object for that object.

Yep, if you want to add one (1!) call to the data layer you had to implement the same function signature in five (5!) places.  Most if it boilerplate code, but still, it was wasteful.

Why would anybody use this design?  In case you wanted to distribute the load across multiple business servers and leave your web presentation layer with only a few boxes.  So, in theory you could have 2 machines running the Web UI, 5 running all the business and DAO logic... and they're all hitting the same database server, which is actually where you're going to run into a choke point, but forget that, because well, this design is kinda cool.  I've seen this design tried twice, and both met with the same fate:  Disaster.

And it's damned near impossible to get away from once the project is in full swing.

Come to think of it, if you're gearing up for business application development, the most important thing to brush up on is going to be SQL.  Poor data access code is where the vast majority of performance problems are found in my experience.

Tallpine

  • friends
  • Senior Member
  • ***
  • Posts: 23,172
  • Grumpy Old Grandpa
Re: Algorithms book
« Reply #18 on: November 30, 2007, 06:29:12 AM »
Good post, GigaBuist Smiley
Freedom is a heavy load, a great and strange burden for the spirit to undertake. It is not easy. It is not a gift given, but a choice made, and the choice may be a hard one. The road goes upward toward the light; but the laden traveller may never reach the end of it.  - Ursula Le Guin