Data Structures & Algorithms in Python

Author: Dr. John Canning, Alan Broder and Robert Lafore
Publisher: Addison-Wesley
Date: October 2022
Pages: 928
ISBN:978-0134855684
Print: 013485568X
Kindle: B0B1WJF1K9
Audience: Python developers
Rating: 4
Reviewer: Mike James
Data structures in Python - a good idea!

Data structure books are classical computer science - every CS lecturer plans on writing one at some point because the subject is so closed and neat. You don't have to worry about what to put in the book because it is so obvious and, of course, the arrogance to think that you could do it better than what already exists is in abundance. About the only excuse for another data structures book is if you can find a language that needs such a book. Python is popular enough to warrant more than one such book and so we have Data Structures & Algorithms in Python which is a full color and very attractively presented book.

The problem with a book that targets a specific language is how much of the language does it take on board. After all, data structures and their associated algorithms are ideas that are language-independent. I can describe bubble sort without resorting to any programming language - compare next door neighbors and swap if they are in the wrong order and repeat. On the other hand, an expression in terms of a language the reader knows is a concise way of getting the ideas across. The question is how much should the language feature? Should the book use idiomatic code that makes use of the language - personally I think it should - and this book doesn't, but there are arguments for its approach.

 

Banner

The first chapter is an overview of Python and it's so short that it would probably be better left out. This isn't a summary of Python that does the language justice. It presents it as if it was Java or any old standard, object-oriented, language.

The problem becomes apparent with Chapter 2 when the array is introduced - Python doesn't really have classical arrays. It has the list which is more like a linked list in that it doesn't have a fixed size and it is dynamic. There is an array module which introduces a true array, but the book doesn't make use of this. The chapter goes through the usual array ideas - mainly searching. The basic operation of scanning through the array is done using an index, even though Python programmers generally think in terms of ennumerations. This makes the code look more like the sort of thing you would encounter in Java or, dare I say it, Fortran. Ennumerations are covered, but they take a backseat.

 

 

Chapter 3 moves on to sorting and we cover the usual suspects - bubble, selection and insertion sort. We get to consider their runtime behavior, but we have to wait till Chapter 7 for the more advanced sorting methods - Shellsort, Quicksort, Radix sort and even Timsort, which is Python's internal sorting algorithm.

Chapter 4 is on stacks and queues and implements these as general objects rather than making  use of the Python standard objects.  From here we move on to linked lists and here we have to make do with Python references rather than the raw pointers of a language like C. Is this better? In practice yes, but for learning probably not.

Chapter 6 is on recursion which really should be associated with recursive data structures, but it isn't. Its not a bad explanation and it has the advantage of showing that to every recursive algorithm a non-recursive stack algorithm exists.

Chapter 7, on advanced sorting, has already been discussed. Then Chapter 8 introduces the recursive data structures that are naturals for recursion trees. More advanced trees are introduced in Chapter 9 and Chapter 10 including 2-3-4, AVL and Red Black trees - there was a time when these were exotic, but today they are standard fare. Chapter 11 deals with hashing, the use of which is one of the reasons that Python is such a great language - the dict is a hash table.

The next four chapters are on less commonly encountered data structures - spatial data structures, heaps, graphs and weighted graphs. The final chapter is a round-up of problems in selecting data structures and algorithms and using them in practice.

The book comes with some visualization software that helps with seeing the algorithms in action and this adds to the book's overall quality. The book is also full of examples of how data structures and algorithms can be useful - Huffman coding, parsing etc. The explanations are fairly basic and the reader isn't expected to know anything additional. It's a slow 900 plus page introduction.

Overall this is a good book. Its approach to Python isn't deep and if you want to know about Python's approach to data you need something different. However, if this doesn't bother you then it's a good introduction to data structures and algorithms and its coverage of some of the less common data structures is also a plus point.

 

  • Mike James is the author of  Programmer's Python: Something Completely Different series of books. The second of which, Programmer's Python: Everything is Data looks at Python's unique approach to data structures.

 

 

To keep up with our coverage of books for programmers, follow @bookwatchiprog on Twitter or subscribe to I Programmer's Books RSS feed for each day's new addition to Book Watch and for new reviews.

Banner


The C# Workshop (Packt)

Author: Jason Hales, Almantas Karpavicius and Mateus Viegas
Publisher: Packt
Date: September 2022
Pages: 780
ISBN: 978-1800566491
Print: 1800566492
Kindle: ‎ B0BGRBDJLS
Audience: C# developers
Rating:  4
Reviewer: Mike James
C# is not the language it once was - time for a revival?



Software Architecture In Practice

Author: Len Bass, Dr. Paul Clements and Rick Kazman
Publisher: Addison-Wesley Professional
Pages: 464
ISBN: 978-0136886099
Print: 0136886094
Kindle: B094CPJ96B
Audience: Software architects
Rating: 4.5
Reviewer: Kay Ewbank

This is the fourth edition of a book widely regarded as a classic since its firs [ ... ]


More Reviews

 

<ASIN:1871962595>

<ASIN:1871962765>

Last Updated ( Wednesday, 15 November 2023 )