[Book Review] Mastering Algorithms with C


“Mastering Algorithms with C” is an excellent choice for learning many algorithms for C programmers.

It covers many basic and slightly advanced algorithms along with their full generic C implementations. You can see some nuances of the C language covered implicitly like generic arrays where you need the size of a single element to do pointer-arithmetic correctly.

If you need to learn more advanced algorithms, another book may be more suited to this. This book also has some issues with not including space or time-complexity correctly, and some of the implementations have some classic bugs. Space-complexity is rarely mentioned, if ever. So this is more of a C than an algorithms book.

An algorithm book that is more accurate and covers more advanced topics is “Algorithms (4th Edition).”

Strengths & Weaknesses


  1. Proper use of double pointers
  2. A good illustration of generic arrays
  3. Effective use of both `memcpy` and `memset` to simplify the implementation
  4. Implementing simple data-structures and using them for more complex algorithms
  5. Excellent, consistent structure for each chapter
  6. Questions & answers that cover what is hard to cover otherwise
  7. Summary of related topics not explained or only explained briefly
  8. APIs for algorithms and data-structures make memory-management clear and shift the responsibility to the caller, which can help when only using static-memory, for example
  9. Extensive use of generic implementations even where most books with languages that have better generics support don’t
  10. Including linear-time sorting


  1. A classic bug in merge-sort where memory is unnecessarily multiple times
  2. Space-complexity (let alone stack) almost never mentioned
  3. `realloc` used freely without counting toward complexity
  4. Complicated APIs due to gracefully handling cases like out-of-memory without terminating the program
  5. Little to no mention to concurrency or persistent data-structures
  6. Unnecessary nesting of code instead of just using guards
  7. Short and generic names make the code harder to read and follow
  8. Use of macros where functions suffice can lead beginners to do the same and learning the hard way the subtleties of macros
  9. The omission of time-complexity even with computation, for example with `cos`
  10. Reusing variables when introducing new ones would make the code much more readable (C90 may be one contributing factor)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store