Data Structures in Javascript — Introduction

Tanvi Bhatia
3 min readOct 16, 2019

--

In this section, we will start with an introduction to the data structure and its types. I have created a part 5 series of various data structures and their implementation in javascript. In the following sections, we will go through each data structure and its implementation in detail. Let's begin

Introduction

A journey from a bad programmer to a good programmer starts with understanding the fundamentals. Good programmers understand the need for organizing the application data in the best way possible. Learning data structures is a very important step towards being a better programmer.

Smart data structure and dumb code work a lot better than the other way round.

- Eric. S Raymond

A data structure is a way to organize data for efficient access and modification. Data should be structured in such a way that it reduces the complexity and increases the efficiency.

According to Wikipedia

A data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.

There are various types of data structures. The choice of a particular one can be considered based on the following points:

  1. It should process the data efficiently when necessary.
  2. It should represent the inherent relationship of the data in the real world.

Why learn Data Structures?

“Bad programmers worry about the code. Good programmers worry about data structures and their relationships.”

Linus Torvalds

To understand the importance of structuring data, let’s take an example from the real world. Imagine a language dictionary. How easy it is for us to search for a word since its organized in an alphabetical sequence. Had the words been stored in any random manner, how much time and effort it will take to look for a word.

Same is true for software applications. Both time and effort are required to process any instruction. Every CPU cycle that is saved will affect both the time and energy consumed and can be put to better use in processing other instructions.

A program built using improper data structures will be inefficient or unnecessarily complex. It is, therefore, necessary to have a good knowledge of data structures and understand where to use the best one.

Types of Data structures

Data structures can be broadly categorized into 2 categories :

1. Linear — Linear data structures store elements in sequential order. Every element in linear ds contains an element before or after it. eg Array, LinkedList, stack, queue, etc.

2- Non- linear — Non-linear structures does not store elements in a certain manner or order. It could be hierarchial. Elements which are stored in a non- linear data structure have certain relationship among them while being stored or retrieved. eg Trees, Graphs, etc.

Conclusion

In the programming world, data dominates. How we store, access and manage data matters as it directly affects speed, scalability, and maintainability of the software application. My motto in this series is to make you understand the usage and implementation of different data structures from a front-end perspective. I will be using Javascript language for implementation. Stay tuned!

Next sections

Part 1 — Stack data structure in Javascript

Part 2 — Queue data structure in Javascript

Part 3 — Linked list data structure in Javascript

--

--