Book Image

Hands-On Data Structures and Algorithms with JavaScript

By : Kashyap Mukkamala
Book Image

Hands-On Data Structures and Algorithms with JavaScript

By: Kashyap Mukkamala

Overview of this book

Data structures and algorithms are the fundamental building blocks of computer programming. They are critical to any problem, provide a complete solution, and act like reusable code. Using appropriate data structures and having a good understanding of algorithm analysis are key in JavaScript to solving crises and ensuring your application is less prone to errors. Do you want to build applications that are high-performing and fast? Are you looking for complete solutions to implement complex data structures and algorithms in a practical way? If either of these questions rings a bell, then this book is for you! You'll start by building stacks and understanding performance and memory implications. You will learn how to pick the right type of queue for the application. You will then use sets, maps, trees, and graphs to simplify complex applications. You will learn to implement different types of sorting algorithm before gradually calculating and analyzing space and time complexity. Finally, you'll increase the performance of your application using micro optimizations and memory management. By the end of the book you will have gained the skills and expertise necessary to create and employ various data structures in a way that is demanded by your project or use case.
Table of Contents (16 chapters)
Title Page
Copyright and Credits
PacktPub.com
Contributors
Preface
5
Simplify Complex Applications Using Graphs
Index

Comparing performance


Earlier, we saw how we can simply swap out a simple queue for a priority queue and not worry about the functional change that it might cause; similarly, we can swap out priority queues for a higher-performant variant of them: circular dequeues.

Before we start working on a comparison, we will need to discuss circular queues and why we need them. 

The difference between a circular queue and a simple queue is that the back of the queue is followed by the front of the queue. That being said, they are not functionally different. They still perform the same operations, and produce the same results; you might be wondering where exactly they differ and what's the point if the end result is the same.

In JavaScript arrays, memory locations are contiguous. So, when creating a queue and performing operations such as remove(), we will need to worry about moving the remaining elements to point to the updated front instead of null, thus increasing the number of operations; it is a memory...