Data Structures in Javascript
Tags: webdev, javascript, beginners, programming
Published: 2023-06-03 11:35:04

For years **[JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript)** was only used in the **[web browser]()**, this all changed with the emergence of platforms such as [Node](https://nodejs.org/) and [Spidermonkey](https://spidermonkey.dev/).

Now that **[JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript)** has begun its shift from only [client side programming](), programmers will find more need for tools provided by conventional languages such as [C++](https://en.wikipedia.org/wiki/C%2B%2B) and [Java](https://www.java.com/).

Among these tools are the classic data structures such as linked lists, stacks, queues, and graphs, as well as classic algorithms for searching and sorting data.

## Why is Data Structures and Algorithms important

From the title of [Nicklaus Writh](https://en.wikipedia.org/wiki/Niklaus_Wirth) programming textbook ["_Algorithms + Data Structures = Programs_ (Prentice-Hall)"](https://www.amazon.com/Algorithms-Structures-Prentice-Hall-Automatic-Computation/dp/0130224189), it show the essence of computer programming.

> Any computer program that goes beyond the trival "Hello world!" will require some type of data structure to manage the type of data the program is written to manipulate, along with some other form of algorithms for translating the data from its input form to its output form.

Most programmers are only familiar with the **Array** data structure, **Arrays** are great for some problems, but for many complex problems, there aren't sophisticated enough.

Most Experienced programmers will admit that for many programming problems, once they come up with the appropraite data structure the algorithms needed are easier to design and implement.

> An example of a data structure that leads to efficient algorithms is the **binary search tree** (BST). A **binary search tree** is designed so that it is easy to find the minimum and maximum values of a set of data, yielding an algorithm that is more efficient than the best search algorithms available. Programmers unfamiliar with BSTs will instead probably use a simpler data structure that ends up being less efficient.

Studying algorithms is important because there is always more than one algorithm that can solve a problem, and knowing the efficient ones is imprtant for a productive programmer.

**Example**

- There are at least six or seven ways to sort a list of data, but knowing that the **Quicksort algorithm** is more efficient than the **selection sort algorithm** will lead to a much more efficient sorting process.
- It’s fairly easy to implement a **sequential or linear search algorithm** for a list of data, but knowing that the **binary sort algorithm** can sometimes be twice as efficient as the se‐ quential search will lead to a better program.

Study of data structures and algorithms not only teaches which data structures and algorithms are most efficient, but you also learn how to decide which data structures and which algorithms are the most appropraite for the problem at hand.

There will always be trade-offs when writing a program, especially in Javascript, knowing the ins and outs of the various data structures and algorithms covered in this book will help you make the proper decisions for any programming problem you are trying to solve.

Credits

> Image made with [Canva]()
>
> Reference from [Data Structures And Algorithms With JavaScript](https://www.amazon.com/Data-Structures-Algorithms-JavaScript-approaches/dp/1449364934) by [[Michael McMillan](https://www.amazon.com/Michael-McMillan/e/B001IU0RIG/ref=aufs_dp_fta_dsk)]