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

Use cases


Implementing a graph is similar to that of trees; there is no set way of creating one. However, based on your use case, you can structure your graphs as directed, cyclic, or any other form as explained earlier. Doing this can make their traversal easier, which would, in turn, make data retrieval easier and faster.

Let's take a look at some examples for which we will be needing a base application first.

Creating a Node.js web server

Let's first create a web server using Node.js, which we will use to create endpoints later on to access our graph-based applications:

  1. The first step is to create your application's project folder; to do so, run the following command from the Terminal:
      mkdir <project-name>
  1. Then, to initialize a Node.js project, run the init command in the root folder of your project. This will prompt a series of questions to generate the package.json file. You can fill out the answers you want or just click on return to accept default values for the prompts:
   ...