Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learning JavaScript Data Structures and Algorithms
Learning JavaScript Data Structures and Algorithms

Learning JavaScript Data Structures and Algorithms: Enhance your problem-solving skills in JavaScript and TypeScript , Fourth Edition

Arrow left icon
Profile Icon Loiane Groner
Arrow right icon
Early Access Early Access Publishing in Sep 2025
$19.99 per month
Paperback Sep 2025 615 pages 4th Edition
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Loiane Groner
Arrow right icon
Early Access Early Access Publishing in Sep 2025
$19.99 per month
Paperback Sep 2025 615 pages 4th Edition
Subscription
Free Trial
Renews at $19.99p/m
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Learning JavaScript Data Structures and Algorithms

1 Introducing Data Structures and Algorithms in JavaScript

Before you begin: Join our book community on Discord

Give your feedback straight to the author himself and chat to other early readers on our Discord server (find the "learning-javascript-dsa-4e" channel under EARLY ACCESS SUBSCRIPTION).

https://packt.link/EarlyAccess/

JavaScript is an immensely powerful language. It is one of the most popular languages in the world and is one of the most prominent languages on the internet. For example, GitHub (the world's largest code host, available at https://github.com) hosts over 300,000 JavaScript repositories at the time of writing (the largest number of active repositories available on GitHub are in JavaScript; refer to http://githut.info). The number of projects in JavaScript on GitHub grows every year.

JavaScript is an essential skill for any web developer. It offers a convenient environment for learning data structures and algorithms, requiring only a text editor...

The importance of data structures

A data structure is a way to organize and store data in a computer's memory, enabling the data to be efficiently accessed and modified.

Think about data structures as containers designed to hold specific types of information, that have their own way of arranging and managing the information. For example, in your home, you cook food in the kitchen, sleep in the bedroom, and take a shower in the bathroom. Each place in a house or apartment is designed with a specific goal for certain tasks so we can keep our home organized.

In the real world, data can often be overly complex, due to factors such as volume, various forms (numbers, dates, text, images, emails), and the speed that data is generated, among other factors. Data structures bring order to this chaos, allowing computers to handle vast amounts of information systematically and efficiently. Think of it like a well-organized library compared to a very large pile of books. Finding a specific book...

Why algorithms matter

Computers are powerful tools, but their intelligence is derived from the instructions we provide. Algorithms are the sets of rules and procedures that guide a computer's actions, enabling it to solve problems, make decisions, and perform complex tasks. In essence, algorithms are the language through which we communicate with computers, transforming them from mere machines into intelligent problem-solvers.

Algorithms can turn tasks into repeatable and automated processes. If you need to generate a report every day at work, this is a task that can be automated using an algorithm.

Algorithms are around us every day, from search engines to social networks, to self-driving cars. Algorithms and data structures are what make them function. Understanding data structures and algorithms unlocks the ability to create and innovate in the technology world.

As software developers, writing algorithms and manipulating data are core aspects of our work. This is precisely why...

Why companies ask for these concepts during interviews

There are many reasons why companies focus on data structures and algorithms concepts during job interviews, even if you are not going to use some of these concepts during daily tasks, including:

  • Problem-solving skills: data structures and algorithms are a great tool to evaluate the candidate's problem-solving abilities. They can be used to evaluate how a person approaches unfamiliar problems, breaks them down into smaller tasks and designs a solution.
  • Coding proficiency: companies can evaluate how candidates translate their solution into clean and efficient code, how candidates choose the appropriate data structure for the problem, design an algorithm with the correct logic, consider edge cases and optimize their code.
  • Software performance: a strong understanding of data structures and algorithms translates directly to successful delivery of every development task, such as designing scalable solutions by choosing the right...

Why choose JavaScript to learn data structures and algorithms?

JavaScript is one of the most popular programming languages in the world, according to various industry surveys, making it an excellent choice if you are already familiar with the basics of programming. The thriving JavaScript community and the abundance of online resources create a supportive and dynamic environment for learning, collaborating, and advancing your career as a JavaScript developer.

JavaScript is also a beginner friendly language and you do not need to worry about complex memory management concepts that exist in other languages such as C++. This is extremely helpful especially when learning data structures like linked lists, trees, and graphs, which are dynamic data structures due to their ability to grow or shrink in size during program execution (runtime), and when using JavaScript, you can focus on the data structure concepts, without mixing with memory management controls.

As JavaScript is used for web development...

Setting up the environment

One of the pros of the JavaScript language compared to other languages is that you do not need to install or configure a complicated environment to get started with it. To follow the examples in this book, you will need to download Node.js from https://nodejs.org so we can execute the source code. On the download page, you will find detailed steps to download and install Node.js in your operating system.

As a rule of thumb, always download the LTS (Long Term Support) version, which is often used by enterprise companies.

While JavaScript can run in both browsers and Node.js, the latter provides a more streamlined and focused environment for studying data structures and algorithms. Node.js eliminates browser-specific complexities, offers powerful debugging tools, and facilitates a more direct approach to learning these core concepts.

The source code for this book is also available in TypeScript, which offers enhanced type safety and structure. To run TypeScript...

JavaScript Fundamentals

Before we start diving into the various data structures and algorithms, let's have a quick overview of the JavaScript language. This section will present the JavaScript fundamental concepts required to implement the algorithms we will create in the subsequent chapters.

Hello World

We will begin with the classic "Hello, World!" example, a simple program that displays the message "Hello, World!".

Let's create our first example together. Follow these steps:

  1. Create a folder named javascript-datastructures-algorithms.
  2. Inside it, create a folder named src (source, where we will create our files for this book).
  3. Inside the src folder, create a folder named 01-intro

We can place all the examples for this chapter inside this directory. Now let's create a Hello, World example. To do so, create a file named 01-hello-variables.js. Inside the file, add the code below:

console.log('Hello, World!');

To run this example, you can...

TypeScript fundamentals

TypeScript is an open source gradually typed superset of JavaScript created and maintained by Microsoft. Gradual typing is a type system that combines elements of both static typing and dynamic typing within the same programming language.

TypeScript allows us to add types to our JavaScript code, improving code readability, improving early error detection as we can catch type-related errors during development and enhanced tooling as code editors and IDEs offer better code autocompletion and navigation.

Regarding the scope of this book, with TypeScript we can use some Object-Oriented concepts that are not available in JavaScript such as interfaces - this can be useful when working with data structures and sorting algorithms. And of course, we can also leverage the typing functionality, which is especially important for some data structures. In algorithms that modify data structures, like searching or sorting, ensuring consistent data types within the collection is...

Summary

In this chapter, we learned the importance of learning data structures and algorithms, and how it can make us better developers and help us pass technical job interviews in technology. We also reviewed reasons why we chose JavaScript to learn and apply these concepts.

You learned how to set up the development environment to be able to create or execute the examples in this book. We also covered the basics of the JavaScript language that are needed prior to getting started with developing the algorithms and data structures we will cover throughout the book.

We also covered a comprehensive introduction to TypeScript, showcasing its ability to enhance JavaScript with static typing and error checking for more reliable code. We explored essential concepts like interfaces, type inference, and generics, empowering us to write more robust and maintainable data structures and algorithms.

In the next chapter, we'll shift our focus to the critical topic of Big O notation, a fundamental...

Left arrow icon Right arrow icon

Key benefits

  • Explore the most common data structures and algorithms you’ll encounter at work and in interviews
  • Connect theory with real-world implementations in JavaScript and TypeScript
  • Walk through solutions to LeetCode and HackerRank problems with the author

Description

Data structures and algorithms are foundational topics for software developers. This easy-to-follow book from experienced developer and trainer Loiane Groner will help you to fill in the gaps in your knowledge – whether you’re a self-taught developer, you’re preparing for technical interviews, or you just want to write better code and improve your problem-solving skills. This fourth edition covers essential data structures, algorithms, and their usage in the context of JavaScript. You’ll follow examples in both JavaScript and TypeScript, in line with the latest standards and best practices, learning how to do complexity analysis along the way. New to this edition are LeetCode and HackerRank exercises at the end of each chapter, which you'll be guided through solving. You’ll also find brand-new chapters on the tries data structure, and string and math algorithms. By the end of the book, you will know how to develop programs using the best data structures and algorithms for the job.

Who is this book for?

This book is for JavaScript developers who want to understand or improve their knowledge of how data structures and classic algorithms work. This includes those preparing for technical interviews, and self-taught or bootcamp developers who may lack formal computer science grounding and want to fill in the gaps. A basic understanding of JavaScript syntax and general programming concepts is needed to get the most out of this book.

What you will learn

  • Declare, initialize, add, and remove items from arrays, stacks, and queues
  • Learn how to think about and use recursion
  • Create and use linked lists, doubly linked lists, and circular linked lists
  • Store unique elements with hash tables, dictionaries, and sets
  • Explore the use of binary trees, binary search trees, and tries
  • Dive into the use of graphs and well-known graph algorithms
  • Sort data structures using algorithms like bubble sort and quick sort
  • Search elements in data structures using sequential sort and binary search

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Last updated date : Sep 19, 2025
Publication date : Jul 31, 2026
Length: 615 pages
Edition : 4th
Language : English
ISBN-13 : 9781836205395
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Last updated date : Sep 19, 2025
Publication date : Jul 31, 2026
Length: 615 pages
Edition : 4th
Language : English
ISBN-13 : 9781836205395
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Table of Contents

9 Chapters
Learning JavaScript Data Structures and Algorithms, Fourth Edition: Enhance your problem-solving skills in JavaScript and TypeScript Chevron down icon Chevron up icon
1 Introducing Data Structures and Algorithms in JavaScript Chevron down icon Chevron up icon
2 Big O notation Chevron down icon Chevron up icon
3 Arrays Chevron down icon Chevron up icon
4 Stacks Chevron down icon Chevron up icon
5 Queues and Deques Chevron down icon Chevron up icon
6 Linked Lists Chevron down icon Chevron up icon
7 Sets Chevron down icon Chevron up icon
8 Dictionaries and Hashes Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.

Modal Close icon
Modal Close icon