12 ms·
Ask HN: Looking for a book on algorithms and data structures
I want to learn Algorithms & Data Structures from scratch then move on to doing LeetCode.
But I want a structured guide / textbook that I can follow which also contains exercises.
I have checked the CLRS book, but, it's more of a reference than a book that you can read from cover to cover. For example a basic Stack is explained in a page and a half or two, for me this is not enough, I want a book that can go into the details of each specific DS or Algorirhm.
*TL;DR:* Are there any books better than CLRS for DS & Algos?
- curtainvase 5y agoI read CLRS in the fashion you described, mostly cover to cover, as a textbook with exercises. I found it extremely helpful. It gives both intuitive and mathematical proofs for each of the algorithms and data structures.
- wagslane 5y agoNot a book but I've been working on a project that sounds like it might be what you're looking for. It's algos and data structures courses in code-along style. It's free to audit, so do check it out even if you aren't interested in the certification stuff :) https://qvault.io https://qvault.io
- rajansaini 5y agoI'm only a student, but I personally really liked https://jeffe.cs.illinois.edu/teaching/algorithms/ https://jeffe.cs.illinois.edu/teaching/algorithms/ This is better for more advanced topics, like dynamic programming (well, advanced for me, anyway). I started out taking over an hour to solve the first problem in the problem sets, but they build on each other slowly, so I was soon able to see solutions within minutes. It took me a weekend to go through chapters I was struggling with, and I did really well on my coding interview the next day.
- issirsq3 5y agoIm not good at maths but to get my work done this books helped me a lot: https://www.amazon.de/Problem-Solving-Algorithms-Structures-Python/dp/1590282574/ https://www.amazon.de/Problem-Solving-Algorithms-Structures-... If I remember correctly it is Python 2 https://www.amazon.de/Algorithms-Illuminated-Part-1-Basics/dp/0999282905/ https://www.amazon.de/Algorithms-Illuminated-Part-1-Basics/d... https://www.amazon.de/Algorithms-Illuminated-Part-Graph-Structures/dp/0999282921/ https://www.amazon.de/Algorithms-Illuminated-Part-Graph-Stru... https://www.amazon.de/Algorithms-Illuminated-Part-Dynamic-Programming/dp/0999282948/ https://www.amazon.de/Algorithms-Illuminated-Part-Dynamic-Pr...
- zamkam 5y agoTruth is, if you want to really learn algorithms and data structures, then you are the one who has to "go into the details". CLRS is the bible, I can't think of a better book, and you don't have to read it sequentially because most chapters are independent of each other.
- jventura 5y agoI’m in the initial phase of structuring a book that aims to teach some simple algorithms and data structures using Python. The idea is that the reader should do the (guided) exercises to learn how to build those data structures. It’s basically “learn by doing”. For instance, to teach what a stack is I’ll explain the basic idea of a stack, then provide a base class and the reader must implement each method (init, push, pop, peek, etc) given the requirements and intended results of each functionality. I already have a kind-of “learn by doing” ebook about Python (https://github.com/joaoventura/full-speed-python https://github.com/joaoventura/full-speed-python), so it’s like a follow-up to that one. Don’t know if people are interested in a book like this, though..
- MalayAgr 5y agoFor algorithms, I can't think of a book better than CLRS, honestly, unless you want to read The Art of Computer Programming by Knuth. For data structures, a great book with a huge amount of detail is Data Structures Using C and C++ by Langsam and Tanenbaum.
- zamkam1031 5y agotl;dr: No
- jstx1 5y ago> For example a basic Stack is explained in a page and a half or two, for me this is not enough Why not? It's a simple data structure. What more do you think can be said about it?
- thesuperbigfrog 5y ago"Foundations of Computer Science" by Aho and Ullman is an excellent book and freely available: http://i.stanford.edu/~ullman/focs.html http://i.stanford.edu/~ullman/focs.html
- pjmorris 5y agoCame here to recommend the same. From the book's website: "This book has been taken out of print by W. H. Freeman. You are welcome to use it if you like. We believed in 1992 it was the way to introduce theory in Computer Science, and we believe that today." The book's introduction to stacks is in chapter 6, link: http://infolab.stanford.edu/~ullman/focs/ch06.pdf http://infolab.stanford.edu/~ullman/focs/ch06.pdf
- bXVsbGVy 5y ago> I want a book that can go into the details of each specific DS or Algorirhm. I'm not aware of any book like that. At the uni, the process is repetitive and incremental. First you learn how to implement the algo, then you learn how to count (discrete math) and, finally, you learn how to analyze its complexity. Concurrently, you might see some more details on how those data structure are used in Operating System and learn how to implement them in some lecture about parallel computing. MIT has a great resource online. They have recorded lecture, exercises, lecture notes with reading suggestion, etc. Their intro to algo. https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-spring-2020/ https://ocw.mit.edu/courses/electrical-engineering-and-compu... Also, see what it the reading for similar lectures on other universities.
- linux_devil 5y agoCLRS + ocw mit course should be good in my opinion. Really helped me a lot
- knuthsat 5y ago+1, Erik Demaine is a great lecturer.
- hiyer 5y agoSedgewick's Algorithms [1] is pretty good. I found it way more approachable than CLRS. There's also a free course on Coursera[2] from him. 1. https://www.amazon.com/Algorithms-4th-Robert-Sedgewick/dp/032157351X https://www.amazon.com/Algorithms-4th-Robert-Sedgewick/dp/03... 2. https://www.coursera.org/learn/algorithms-part1#syllabus https://www.coursera.org/learn/algorithms-part1#syllabus
- wly_cdgr 5y agoCame here so say this. The booksite has additional materials and, crucially, solutions to many of the exercises
- kitd 5y agoI learned most of my algorithm knowledge from Sedgewick in the 1990s. There is a series that applies them to various languages (C,C++, Java, etc) that makes them very accessible and easy to experiment with.
- eitland 5y agoI had "walls and mirrors". Recently I met someone who said that was the only book they kept from uni. I can't say if it is good or not, I lost mine well over a decade ago.
- ioli 5y agoThe Algorithm Design Manual by Steven Skiena Amazing book. Very readable. I highly recommend it. The book has a section call "War story" at the end of each chapter in which Skiena shares his real life experience of when the contents from that particular chapter came in handy for him. Go through it. You won't regret https://www.amazon.com/Algorithm-Design-Manual-Steven-Skiena/dp/1849967202 https://www.amazon.com/Algorithm-Design-Manual-Steven-Skiena...
- MarvelousWololo 5y agoNot OP but I’m interested in this subject as well. I took a look at this book and others that are similar and I’ve realized my foundations on math are really lacking to even understand the given examples. Since I only had the opportunity to finish my high school diploma and this was several years ago I wonder if you could have any suggestion to brush my math knowledge up in order to properly understand the examples of these books. The thing for me is that I’m not sure where I should start. Would you know any resource to introduce me to the math foundations in order to understand such texts? Or maybe math concepts that I should study before I dig in. I really appreciate it. Thanks.
- gtirloni 5y agoThis is a good starting point: https://youtube.com/playlist?list=PL7wAPgl1JVvUEb0dIygHzO4698tmcwLk9 https://youtube.com/playlist?list=PL7wAPgl1JVvUEb0dIygHzO469...
- ramesh31 5y ago>Since I only had the opportunity to finish my high school diploma and this was several years ago I wonder if you could have any suggestion to brush my math knowledge up in order to properly understand the examples of these books. You should really consider taking a few community college math courses if you're serious. Math is extremely difficult to learn on your own. Not only because of not knowing what you don't know, but because it requires intense effort and repetition which is very hard to force yourself to do. You can work through the concepts and delude yourself into thinking you understand something when really you're just hand waving it. Taking an actual course and being faced with the gaps of your knowledge by someone else is very humbling and essential to actually learning it.
- b20000 5y agojust move on to leetcode. you just memorize the bullshit questions and their answers. that is what everyone seems to be doing. actual experience makes no difference. you have 2 minutes to produce the exact answer expected.
- usrme 5y ago"A Common-Sense Guide to Data Structures and Algorithms, 2nd Edition" by Jay Wengrow is one I'd recommend every time. It really makes it easy enough to understand things I previously only considered to be the domain of math-oriented people. Not sure if it goes deep enough for you though...
- marcobehler 5y agoYes, wholeheartedly agree. All other classic recommendations from this thread pale in comparison. Jay Wengrow did a fantastic job with this book.
- Someone 5y agoIf you want basics and details, the art of computer programming is a good candidate. Unfortunately, it isn’t done yet (1), and the completed parts have are very basic and have parts that are a bit dated (multi-tape sorting, for example) (1) and likely never will be. Knuth is turning 84 in two months, and isn’t even halfway writing it, after almost 60 years
- HarryHirsch 5y agoIt would be fitting if the work were carried on by a committee, like Bourbaki.
- Someone 5y agoThat would be harder than Bourbaki, I guess. They had the benefit of a blank slate. It would have to be done in Knuth’s spirit, and there would be lots to argue over what to include, before even writing about it How complete are Knuth’s notes? Would he have found Foo important enough to include, even though his notes don’t mention it? Should the completion include stuff discovered after his death? Should earlier volumes be revisited, as Knuth probably would do, if he had an eternity to live?
- iamsb 5y agoThe Art of computer programming by Donald Knuth.
- jll29 5y agoTAOCP is too detailed and too deep as a beginner's book; you first want something lighter that you can worth through end-to-end before taking on a 7-volume book that is still not even finished (volume 4b of 7 in progress at the time of writing). Note I am _not_ saying TAOCP isn't readable, I consider it very well written. But it's terse, hard, too deep and too detailed for a beginner, IMHO.
- e9 5y agoBack when I was in high school I learned all leetcode algorithms from doing programming competitions. One of the books I used was: http://acm.cs.buap.mx/downloads/Programming_Challenges.pdf http://acm.cs.buap.mx/downloads/Programming_Challenges.pdf What really put me to the next level is this amazing free training program which I still recommend anyone who wants to nail the interviews. It teaches each algorithm and data structure and gives you appropriate challenging exercises so you really understand them: https://train.usaco.org/ https://train.usaco.org/
- WillDaSilva 5y agoI would recommend Open Data Structures: https://opendatastructures.org/ https://opendatastructures.org/ It's available for free online, or if you'd like you can buy a physical copy. It's got 14 chapters that take you through a variety of data structures, introduces you to the theory behind them, and teaches you the basics of analyzing them. I've done many of the exercises from this book, and found them useful for learning the topic.
- stickyricky 5y ago"Algorithms Illuminated" by Roughgarden. Very accessible. Reads like a novel not a textbook. Has exercises throughout the chapter to test knowledge. I recommend it over your suggestion that you want a textbook. This book will serve you much better.
- jsonjason 5y agoAnother vote for Tim Roughgarden’s work. As someone who recently became a software engineer without a cs degree, his Stanford Algorithms I & II lectures (similar content to his books) have been the best instruction I’ve had on DS&A. I’ve dabbled with Skiena’s book, Grokking Algorithms, CTCI, and I now also have a copy CLRS that I use for reference or to go deeper on certain things. But I revisit Tim’s work all the time. Can’t recommend him enough.
- bhrgunatha 5y agoI found his courses rigorous and approachable too. I think they were equivalent to the courses he taught while at Stanford. https://timroughgarden.org/videos.html https://timroughgarden.org/videos.html
- 988747 5y agoIs there a way to buy ebooks from the seller other than Amazon (for those of us who hate Jeff Bezos ;) ?
- stickyricky 5y agoUnfortunately no. Possibly email the author? http://www.algorithmsilluminated.org/ http://www.algorithmsilluminated.org/
- deleted 5y ago[deleted]
- chris_l 5y agoShameless plug: you might want to accompany a book with explained animations of Algorithms and Data Structures: https://www.chrislaux.com https://www.chrislaux.com
- MyAnonymousAcc 5y agoIn case you want to go for something aimed at competitive programming have a look at the "Competitive Programmer’s Handbook" https://cses.fi/book/book.pdf https://cses.fi/book/book.pdf
- alanfranz 5y agoMy personal favourite is Sedgewick & Wayne's _Algorithms_. https://algs4.cs.princeton.edu/home/ https://algs4.cs.princeton.edu/home/ You can even find an excellent two-part MOOC on Coursera: https://www.coursera.org/learn/algorithms-part1 https://www.coursera.org/learn/algorithms-part1 https://www.coursera.org/learn/algorithms-part2 https://www.coursera.org/learn/algorithms-part2 Maybe it's not the "purest" class or book, but it's engaging and it lets you understand how algos work AND how to use them in practice.
- cloverich 5y agoSedgewick is a masterpiece but also overkill for interview prep. Interviews are mostly trivia and for that leet codes volume is your friend. Buy sedgewick for your long term growth but it will stand in the way of any near term interview prep, at least it did for me.
- musicale 5y agoThe annoying thing as you note is that in the long run Sedgewick >> Leetcode but in the short run it's probably reversed as whiteboard interviews often present algorithm puzzles that are variants of "have you seen this trick before?" and closer to Leetcode questions. I wonder though if "programming contest" (usually more like "algorithm puzzle contest") books like Skiena's might be useful, though I can't help but think that doing an algorithms course first shouldn't be useless.
- _448 5y agoI usually don't complete online courses(I get bored watching educational videos) except for one. This course is on data structures and is conducted by University of California, San Diego. It is available both on edX[0] and Stepik[1]. The reason this online course is so engaging is because it uses the active-learning way of teaching. I was surprised how well that technique worked! [0] https://www.edx.org/course/data-structures-an-active-learning-approach https://www.edx.org/course/data-structures-an-active-learnin... [1] https://stepik.org/579 https://stepik.org/579
- dhanna 5y agoYes there’s lots of algorithm books! Too many to learn them all. I had an anxiety attack and bought most of the introductory algo books mentioned in CLRS chapter 1. I liked ALGS4 by Sedgewick as my introduction to Algorithms. I still refer to the Coursera course. I actually started with CLRS and doubled back to ALGS4. I wish I did it in reverse order but it was still useful reading CLRS and refreshing my math skills. I would say grab a few and see which ones you like. CLRS, ALGS4, Algorithm Design Manual, and Algorithm Design by Kleinberg and Tardos are a good start. You can look in the bibliography of each books for more suggestions from the experts themselves.
- jypepin 5y agoAlgorithms in a nutshell by George T. Heineman helped me a lot. It's not too dense so it's easy to read, just enough to learn and understand how an algorithm works.
- uptheroots 5y agoCLRS is what I used in college
- dyeje 5y agoIf your goal is to be good at LeetCode, then save yourself the time and just go straight to LeetCode. Nobody cares if you actually understand the stuff. They just want you to come in and do the dance (recognize the problem archetype, talk through your thought process for solving it, and adjust based on whatever twists they've thrown in). If you're interviewing for senior positions, it is worthwhile to read through Designing Data Intensive Systems. This will prepare you for System Design interviews where you do need to actually understand stuff.
- throwaway81523 5y ago> If you're interviewing for senior positions, it is worthwhile to read through Designing Data Intensive Systems. This will prepare you for System Design interviews where you do need to actually understand stuff. Do you mean "Designing Data Intensive Applications" by Martin Kleppmann? That's what most of my search hits found. If something else, do you have a link? Thanks.
- dyeje 5y agoYep, sorry that's the book I'm referring to.
- throwaway81523 5y agoThanks, the table of contents looks promising.
- digianarchist 5y agoThat's a good read regardless of your level.
- aabaker99 5y agoI find the writing style in CLRS to be quite readble. Sure the book is huge but so maybe pick and choose chapters but each chapter can be read "cover to cover". Perhaps some of the stack details you are looking for are left to exercises in CLRS? Most good "textbooks" will do this. Perhaps you don't want a general textbook on data structures but want a deep dive article on stacks. I admit I haven't explored many other books on this topic but CLRS is very good in my opinion.
- aynyc 5y agoSegwick's book is far more useful in self-learning environment than other text books. He has videos and fully functioning code to help you understand.
- lr1970 5y agoA great and quite unconventional book on Algorithms is "INTRODUCTION TO ALGORITHMS - A Creative Approach" by Udi Manber. After leaving academia the author was hired first by Amazon (A9.com) and then by Google. At some point around 2010 he was responsible for all search products at Google [0]. The book not only describes the algorithms per se, but also teaches how to think about the algorithms and the problems they are solving. I enjoyed it very much as a complimentary reading to the classic Knuth volumes. [0] https://en.wikipedia.org/wiki/Udi_Manber https://en.wikipedia.org/wiki/Udi_Manber
- digianarchist 5y agoExcellent book if you can find it. I kick myself for selling my hardback copy.
- fsloth 5y ago"Foundations of Computer Science" by Aho and Ullman is my personal favourite.
- bsuvc 5y agoCLRS is pretty accessible for beginners, at least as far as computer science textbooks go. Perhaps you would benefit from pairing it with a MOOC like MIT's Introduction to Algorithms. https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/ https://ocw.mit.edu/courses/electrical-engineering-and-compu...
- laxmena 5y agoIntroduction to Algorithms -Thomas H. Cormen Grokking Algorithms -Aditya Bhargava Cracking the Coding Interview Book by Gayle Laakmann McDowell
- anuragbiyani 5y agoThe good thing about Algorithm Design & Analysis as a topic is that there is no lack of great resources to learn from! And even better, a large portion of them are freely available online (in forms of lecture notes, or entire books, video lectures, programming challenges with online judging, etc). In addition to what others have mentioned, here are some example resources you might prefer for a beginner-intermediate level intro: 1. (free online) Algorithms by Dasgupta, Papadimitriou, and Vazirani http://algorithmics.lsi.upc.edu/docs/Dasgupta-Papadimitriou-Vazirani.pdf http://algorithmics.lsi.upc.edu/docs/Dasgupta-Papadimitriou-... 2. (free online) Algorithms by Jeff Erickson https://jeffe.cs.illinois.edu/teaching/algorithms/ https://jeffe.cs.illinois.edu/teaching/algorithms/ 3. Algorithm design by Kleinberg & Tardos https://www.amazon.com/Algorithm-Design-Jon-Kleinberg/dp/0321295358 https://www.amazon.com/Algorithm-Design-Jon-Kleinberg/dp/032... 4. Another one specifically for more applied view (esp., how they are used in programming contests such as ICPC) is Skiena & Revilla's "Programming Challenges" book (https://www.amazon.com/Programming-Challenges-Contest-Training-Computer/dp/0387001638 https://www.amazon.com/Programming-Challenges-Contest-Traini...). Note that this is different than Skiena's other popular book (Algorithm Design manual) which is also pretty good and has a "war story" based perspective to design of algorithms. 5. There are also several resources where lecture notes from university Algorithm & DS courses are very useful. Here is an example from my previous Professor, David Kempe: http://david-kempe.com/teaching/DataStructures.pdf http://david-kempe.com/teaching/DataStructures.pdf 6. Several programming competition specific tutorials can be found on Topcoder: https://www.topcoder.com/thrive/tracks?track=Competitive%20Programming https://www.topcoder.com/thrive/tracks?track=Competitive%20P... (individual SRM archives are also good place to try problems first hand and then learn from other's approach). In general, if you search for ACM-ICPC resources, you will find a lot more targeted information/problems which will apply not only for leetcode, but also for detailed understanding of the theory too.
- rudy6912 5y agoI like: algorithms.wtf Algorithms by Jeff Erickson
- stefanos82 5y agoI visited a friend a while ago and she was reading this amazing book on her tablet, "The AgloDaily Book: Core Essentials" https://algodaily.gumroad.com/l/yYEqr https://algodaily.gumroad.com/l/yYEqr I really loved its illustrations; it looks so easy to follow.
- rpac0 5y agoin case you want to code along, Ive been through some of the books mentioned here and solved the algorithms. You can check it out at https://github.com/realpacific/algorithms https://github.com/realpacific/algorithms
- tarsinge 5y agoI recommend to start with "Elements of Programming Interviews (in Java or Python)". It serves as a nice practical overview of the main algorithms and data structures and when to use them. Personally I found it more complete than the usually recommended "Cracking the Coding Interview" while being equally approachable.
- rob_c 5y agoBest I can offer is for data structure think about working backwards if possible. Every time I've been involved in projects using 10TB+ data it's the processing that tends to expose the most bottlenecks. Nothing competes with making a pseudo dataset about 5%-10% of the size and running benchmarks which roughly match your expected workflow. Good luck
- truly 5y agoIt really depends. It is a bit difficult to answer this question without understanding your background first. What CS lectures have you already taken? What related courses (e.g., math) have you done? For example, the Stack data structure that you bring into discussion is quite simple (but interesting and important), so I am not surprised it is treated speedily. Introduction to Algorithms typically has more difficult content. Depending on this, I could recommend for example that you follow the lectures on the excellent MIT OCW YouTube channel (https://www.youtube.com/c/mitocw https://www.youtube.com/c/mitocw). But you could also do one of the numerous algorithms and data structures courses on coursera/edx. It all depends on what you know so far and what your goal is.
- morty_s 5y agoCLRS does about 5 pages on linked lists. If you want more, my advice would be to implement one in your language of choice, then look at the API for the standard lib impl of a linked list in your language of choice (if there is one). Otherwise, for more reading on linked lists, read through adlist.c from redis, by antirez. Next, one of the best books (IMO) on algorithmic thinking is SICP. Get through a few chapters, do the exercises, grok recursion, etc. In no particular order: Algorithm Design Manual, Skiena Algorithm Design, by Kleinberg/Tardos Algorithms, Sedgwick 4th ed. (also Algorithms in C) If you find you need or would like more math: Discrete Mathematics (Epp is an easier read, Rosen seems more verbose) Mathematical Proofs, Charrand For interview prep: Elements of Programming Interviews (EPI) Designing Data Intensive Applications
- zwerdlds 5y agoEPP is a great intro for those without the preexisting math. Almost nothing is taken for granted, even high school math.
- rramadass 5y agoThere are literally hundreds of threads with this topic on the Web. Most of them contain the same standard references which IMO are not always the best for people without much mathematical maturity and wishing to learn from first principles. That said, here are my recommendations for them (pdfs of almost all are available online and they can also be purchased cheaply as used books); * 1) Functions and Graphs and 2) The Method of Coordinates by I.M.Gelfand et. al. - These give you the basics on functions and how to visualize them which is crucial for understanding. * Introductory Logic and Sets for Computer Scientists by Nimal Nissanke - Nice succinct introduction to various required topics for Comp. Sci. * Compared To What?: Introduction to the Analysis of Algorithms by Gregory Rawlins - This is a classic book which takes you by hand and walks you through Algorithm Analysis and the reqd. mathematics. You will find this more approachable than most other text books and well worth a study. * How to Think about Algorithms by Jeff Edmonds - Practical techniques without too much mathematical formalism. * Data Structure Techniques by Thomas Standish - A Classic text; good adjunct to more modern texts. * Advanced Data Structures by Peter Brass - Nice succinct text but not necessarily "advanced". One final point; try to get a Algorithms and Data Structures book with code in the language with which you are most familiar. That way you understand the mapping from "Abstract Algorithm" to "Concrete Language Implementation" which is not always trivial.
- say_it_as_it_is 5y agoAre they any algorithms books that don't use data structures backed by linked lists but rather arrays or vectors? Linked data structures are barely used in practice. It can take a student weeks to go through Linked Lists and data structures using them, just to find that they're hardly ever used in practice. Contiguous data structures are the dominant types used today.
- annoying_code 5y agoI better recommend you to try your hands on code-forces, CP Algorithm etc. If you got stuck in any of the problems just read the discussion and given solution. If you continue this you several months then you quickly learning the data structures and algorithms. Because if you don't apply DSA which you will learn from any book then i guess it doesn't add much value to you. In the beginning problems might not able to solve but after giving time and looking solution you will start getting things. And I guess its just a myth or we can say a phobia that you need to know each and every piece of mathematics. And I think graph is a data structure that you should be work upon. For this you can refer this book Introduction to Graph Theory Subsequent Edition by Douglas Brent West. This book you can just read and practice while solving problems on above coding problem platforms. So, I recommend you first do code-forces DIV3, DIV2 problems, gain some confidence, and then pick any DSA book. Or one thing you can also do just filter out problems related to math,Combinatorics etc.on code-forces and try to solve them. Through this approach you will learn to apply the concepts. I hope this comment add some value to you! Happy coding.