avatarDarshna Rekha

Summary

The provided web content discusses the concept of data structures in JavaScript, emphasizing their importance in organizing and retrieving data efficiently, similar to how physical containers organize items in real life.

Abstract

The article "Data Structure With JavaScript" draws an analogy between physical storage containers and data structures, illustrating how each serves to organize and facilitate the retrieval of specific items or data. It introduces the reader to the fundamental role of data structures in programming, explaining that they are collections of values with defined relationships and operations. The article underscores the significance of understanding data structures and algorithms for writing effective programs, as they are universal tools in software development, independent of the programming language used. It delves into the computer's storage mechanisms, particularly Random Access Memory (RAM), and how data structures optimize memory usage for faster program execution. The article also outlines common operations performed on data structures, such as insertion, deletion, traversal, searching, sorting, and access, and previews an upcoming series covering various data structures implemented in JavaScript, including arrays, hash tables, linked lists, stacks, queues, trees, and graphs.

Opinions

  • The author suggests that knowledge of data structures is crucial for writing efficient programs, as they directly influence the performance of a computer's operations.
  • It is implied that pre-built data structures are commonly used by programmers, highlighting the importance of knowing how to select and apply the appropriate data structure for a given task.
  • The article conveys that understanding how computers store data, particularly in RAM, is integral to appreciating the impact of data structures on computational efficiency.
  • The author emphasizes the timeless nature of data structures and algorithms, indicating their enduring relevance in the ever-evolving field of programming.
  • There is an opinion that optimizing memory access by using data structures that store information in a CPU-friendly manner can significantly improve program performance.
  • The article hints at the practical utility of data structures by previewing a series that will explore their implementation in JavaScript, suggesting that readers will benefit from learning about the strengths and weaknesses of each data structure type.

Data Structure With JavaScript

Different Containers to Hold Different Things — Cupboard for clothes, Cabinet for Files, Book Case, Suitcase for packing items while travelling, and Fridge for Clothes.

In real life, we have containers for food (refrigerator), files (folders/file cabinets), toys (packing boxes), or clothes (cupboard). Each container is specific for a thing. We will not put files in packing boxes as they will crumble. It is a way for us to organize our things so we can go back and retrieve them easily.

Similarly, we put data in data structures and retrieve them from the data structures — that is all it is.

Just like in real life, there are tons of data structures in programming as well.

Introduction to Data Structure

A data structure is a collection of values, these values can have relationships among them and they can have functions applied to them.

Each one is different in what it can do and what it is best used for.

A person who knows how data structures and algorithms work and how to use them can write great programs.

Data Structure + Algorithms = Programs

These are timeless. No matter what programming language you use underneath it’s all data structures and algorithms.

Understanding Data Structure

There are two parts to understanding Data Structure

  1. How to Build One?
  2. How to Use One?

The second point is more important than the first point because data structures are usually just tools and most of the time they’re already pre-built for us. Based on our requirement we identify the one we want to use.

How Computers Store Data

For running the code the computer needs to keep track of things like variables, numbers, strings, or array. These variables are stored in Random Access Memory (RAM).

We also have storage where we store things like video, music, and documents. This storage can be a disk drive, a flash drive, or a solid-state drive.

The computer is run by its CPU (the little worker) which does all the calculations. It needs access to the RAM and storage but access to RAM and its information faster than compared to storage.

Random Access Memory

For active learning checkout Registers and RAM: Crash Course Computer Science #6. You can skip the following explanation if you have watched the video.

RAM in the computer is a massive storage area (like data structure). This massive storage area has shelves that are numbered. They are called address or addresses.

Random Access Memory

Each shelf holds eight bits (1 and 0s). A bit is a tiny electrical switch that can be turned on or off. 8 bits is called a byte. Each shelf has one byte of storage.

The CPU is connected to a memory controller which does the reading/writing of RAM. The memory controller has direct connections to each shelf. Hence accessing shelf 0, or 7, or 10781 doesn’t mean it has to climb or step the shelves. That’s what the name random access memory means.

We can access memory really fast because we have these connections. We need to know which shelf we’re looking for we can access the bits at any random address in memory, right away!

Even though this memory controller can jump between far apart memory addresses really fast, programs tend to access memory that is nearby. The closer the information is to the CPU and the less it has to travel, the faster a program can run. For example, accessing memory at 0 and 1 is still faster than accessing 0 and 1000 position.

For further optimization, the CPU has cache memory that stores recently used data.

How is the Knowledge of Storing Data related to Data Structure?

The data structure is an arrangement of data. Our goal is to minimize the operations done by the CPU to get the information. And that is why data structures are so powerful.

We have a way now to think about how data structures actually affect the process of our computers and how we can use what we know about computers to write great code.

Operations on Data Structure

Before getting into the data structures let us see the operations that can be performed on different Data Structures.

Operations on Data Structure (Made using Excalidraw)
  • Insertion — add data in a given collection of items.
  • Deletion — delete data from our list.
  • Traversal — access each data item exactly once so that it can be processed
  • Searching — find out the location of the data item if it exists in a given collection.
  • Sorting — based on given information arrange the data.
  • Access — fetch data with some given information.

Data Structures Using JavaScript

Beginning of Data Structure with JavaScript

In Data Structures we will be covering:

  1. Arrays
  2. Hash Tables
  3. Linked Lists
  4. Stacks & Queues
  5. Trees
  6. Graphs

We will cover a short introduction, complexities, implementation in JavaScript, and the pros & cons of each one of them in the upcoming series.

JavaScript
Data Structures
Beginners Guide
Recommended from ReadMedium