Data Structures and Algorithms with JavaScript

Author:  Michael McMillan
Publisher: O'Reilly
Date: March 24, 2014
Pages: 246
ISBN: 978-1449364939
Print: 1449364934
Kindle: B00IV3J23Y
Audience: Intermediate JavaScript programmers
Rating: 3.5
Reviewer: Ian Elliot

A book explaining the standard data structures in the worlds most popular language sounds like a really good idea. 

Every programmer should know about data structures and the algorithms that relate to them. The reason is simply that they are the foundation of algorithmic thinking. If you can't contemplate a range of data structures that are applicable to a problem you aren't finding the best solution just a solution.

Many programmers are exposed to data structures in a "101" course as part of a computer science degree or other formal qualification, but the language used is most often one with an academic reputation like Pascal, Java or Haskell. JavaScript isn't academically respectable, except in a few enlightened places, and so it generally isn't used to explain data structures. 

This book is essentially a Data Structures 101 course using JavaScript.

Banner

Chapter 1 is an introduction to vanilla JavaScript. It doesn't get very deep, so if you were hoping for a book that makes a clever or even appropriate use of JavaScript this isn't it. This is JavaScript as a simple procedural language. However, this might be the right approach to explain data structures, which are fairly language independent. 

Chapter 2 deals with standard JavaScript arrays - nothing new here if you already know JavaScript. Chapter 3 is about Lists and implementing an abstract data type as a JavaScript object using an internal array. Chapter 4 repeats the procedure for the stack or LIFO stack. An array is used as the data store, but the fact that the JavaScript Array already has push and pop operation isn't mentioned. When it comes to implementing a queue in Chapter 5 then the array shift and push operations are used. The fact that a Queue is a FIFO data structure is mentioned but not that it is also called a FIFO stack. The examples of the use of these elementary data structures are also a little worrying as they contain no word as to how reasonable they are. For example using a stack to perform base conversion might be interesting but it isn't a sensible way to do the job. A similar comment applies to the explanation of radix sort using multiple queues. Finally if you are going to explain the queue why not mention the deque? A double ended queue is a really useful data structure and hardly any more complex than a FIFO and LIFO stack. 

Chapter 6 moves us on to more advanced territory - the linked list. If you want to do almost anything all you need is a linked list. We have a fairly standard implementation of the linked list using properties as pointers to the next item. All of the standard list operations are explained and the typical extension you encounter to make things practical - circular lists and doubly linked lists. 

Next we move on to the Dictionary which is of course at the very heart of JavaScript. Every JavaScript object is a Dictionary with a few extras. However, the implementation uses an Array because of the need to perform a sort - this is OK as an Array is a Dictionary too. 

Chapter 8 deals with hashing and while it introduces the basic ideas it does nothing to convince the reader that creating a hash function is a difficult task - it is. This is a very basic introduction to hashing and I doubt the reader would be in a position to implement a practical hash table after reading it. 

The next chapter deals with sets - not a data structure that is often encountered. The implementation uses an Array and it works but in the real world sets are usually implemented as binary representations for speed. 

The authors then move on to deal with trees and more complex data handling. In Chapter 10 we have a look at binary trees and binary search trees. Chapter 11 moves on to graphs in general and depth first breadth first search.

 

 

Now at last. we get to the second topic promised in the book's title - algorithms. Chapter 12 covers those used to sort arrays: bubble sort, selection sort and insertion sort, Shell sort, merge sort and quick sort. Then Chapter 13 is on Searching algorithms, including binary search on a linear array which would have been better covered before binary search trees.

The final chapter is a short taste of advanced algorithms used for dynamic programming and greedy algorithms. There are examples and some explanation but I doubt that the reader is going to have much luck inventing their own algorithms of either type after reading this chapter.

This is a very standard look at data structures and sorting and searching algorithms such as you might find in any introductory Computer Science course. If you have already done such a course then there is nothing to add because implementing them in JavaScript is straightforward. In other words, you are not going to learn anything specific to JavaScript here. 

There are also lots of typos. Mostly you can see how they have come about - a program pasted from one place to another and not completely modified. If you know JavaScript and know what the implementation of the data type in question is all about then these typos aren't a big problem. 

datastructuresJavascript

The biggest problem is that the book does little to give you an idea of what data structures are all about and what powerful properties particular structures possess. For example, a stack is an amazing machine. It has the ability to reorder data - push ABC and you get back CBA. It is linked to the grammar of arithmetic expressions and can be used to implement their evaluation. According to this book a stack is a data structure with a push and pop operation and a few strange uses.

While this book might be useful to fill in gaps in your knowledge of data structures, there are better books available, admittedly a lot bigger than this one, and having one that uses JavaScript isn't a particular advantage.  

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


Algorithmic Thinking, 2nd Ed (No Starch Press)

Author: Dr. Daniel Zingaro
Publisher: No Starch
Date: January 2024
Pages: 480
ISBN: 978-1718503229
Print: 1718503229
Kindle: B0BZGZHK3B
Audience: C programmers
Rating: 4
Reviewer: Mike James
What exactly is algorithmic thinking?



Oracle PL/SQL By Example, 6th Ed

Author: Elena Rakhimov
Publisher: Oracle Press
Pages: 480
ISBN: 978-0138062835
Print: 0138062838
Audience: Developers interested in Oracle PL/SQL
Rating: 4
Reviewer: Kay Ewbank

This is the sixth edition of a well established title that has been updated for the latest version of PL/SQL (21c).


More Reviews

Last Updated ( Saturday, 02 June 2018 )