Learning JavaScript Data Structures and Algorithms - Fourth Edition

Book description

Solidify your computer science fundamentals and choose the right data structures and algorithms for your programs – with new TypeScript focus and exercises. Purchase of the print or Kindle book includes a free eBook in PDF format.

Key Features

  • 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

Book 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.

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

Who this book is 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.

Table of contents

  1. Learning JavaScript Data Structures and Algorithms, Fourth Edition: Enhance your problem-solving skills in JavaScript and TypeScript
  2. 1 Introducing Data Structures and Algorithms in JavaScript
    1. The importance of data structures
    2. Why algorithms matter
    3. Why companies ask for these concepts during interviews
    4. Why choose JavaScript to learn data structures and algorithms?
    5. Setting up the environment
      1. Installing a code editor or IDE
    6. JavaScript Fundamentals
      1. Hello World
      2. Variables and data types
      3. Control structures
      4. Functions
      5. Object-oriented programming in JavaScript
      6. Modern Techniques
    7. TypeScript fundamentals
      1. Type inference
      2. Interfaces
      3. Generics
      4. Enums
      5. Type aliases
      6. TypeScript compile-time checking in JavaScript files
      7. Other TypeScript functionalities
    8. Summary
  3. 2 Big O notation
    1. Understanding Big O notation
    2. Big O time complexities
      1. O(1): constant time
      2. O(log(n)): logarithmic time
      3. O(n): linear time
      4. O(nˆ2): quadratic time
      5. O(2^n): exponential time complexity
      6. O(n!): factorial time
      7. Comparing complexities
    3. Space complexity
    4. Calculating the complexity of an algorithm
    5. Big O notation and tech interviews
    6. Exercises
    7. Summary
  4. 3 Arrays
    1. Why should we use arrays?
    2. Creating and initializing arrays
    3. Accessing elements and iterating an array
      1. Using the for..in loop
      2. Using the for…of loop
    4. Adding elements
      1. Inserting an element at the end of the array
      2. Inserting an element in the first position
    5. Removing elements
      1. Removing an element from the end of the array
      2. Removing an element from the first position
    6. Adding and removing elements from a specific position
    7. Iterator methods
      1. Iterating using the forEach method
      2. Iterating using the every method
      3. Iterating using the some method
    8. Searching an array
      1. Searching with indexOf, lastIndexOf and includes methods
      2. Searching with find, findIndex and findLastIndex methods
      3. Filtering elements
    9. Sorting elements
      1. Custom sorting
      2. Sorting Strings
    10. Transforming an array
      1. Mapping values of an array
      2. Splitting into an array and joining into a string
      3. Using the reduce method for calculations
    11. References for other JavaScript array methods
      1. Using the isArray method
      2. Using the from method
      3. Using the Array.of method
      4. Using the fill method
      5. Joining multiple arrays
    12. Two-dimensional arrays
      1. Iterating the elements of two-dimensional arrays
    13. Multi-dimensional arrays
    14. The TypedArray class
    15. Arrays in TypeScript
    16. Creating a simple TODO list using arrays
    17. Exercises
      1. Reversing an array
      2. Array left rotation
    18. Summary
  5. 4 Stacks
    1. The stack data structure
    2. Creating an array-based Stack class
      1. Pushing elements to the top of the stack
      2. Popping elements from the stack
      3. Peeking the element from the top of the stack
      4. Verifying whether the stack is empty and its size
      5. Clearing the elements of the stack
      6. Exporting the Stack data structure as a library class
      7. Using the Stack class
      8. Reviewing the efficiency of our Stack class
    3. Creating a JavaScript object-based Stack class
      1. Pushing elements to the stack
      2. Verifying whether the stack is empty and its size
      3. Popping elements from the stack
      4. Peeking the top of the stack and clearing it
      5. Creating the toString method
      6. Comparing object-based approach with array-based stack
    4. Creating the Stack class using TypeScript
    5. Solving problems using stacks
      1. Converting decimal numbers to binary
      2. The base converter algorithm
    6. Exercises
      1. Valid Parentheses
      2. Min Stack
    7. Summary
  6. 5 Queues and Deques
    1. The queue data structure
    2. Creating the Queue class
      1. Enqueueing elements to end of the queue
      2. Dequeuing elements from beginning of the queue
      3. Peeking the element from the front of the queue
      4. Verifying if it is empty, the size and clearing the queue
      5. Exporting the Queue data structure as a library class
      6. Using the Queue class
      7. Reviewing the efficiency of our Queue class
    3. The deque data structure
    4. Creating the Deque class
      1. Adding elements to the deque
      2. Removing elements from the deque
      3. Peeking elements of the deque
      4. Using the Deque class
    5. Creating the Queue and Deque classes in TypeScript
    6. Solving problems using queues and deques
      1. The circular queue: the Hot Potato game
      2. Palindrome checker
    7. Exercises
      1. Number of Students Unable to Eat Lunch
    8. Summary
  7. 6 Linked Lists
    1. The linked list data structure
    2. Creating the LinkedList class
      1. Appending elements to the end of the linked list
      2. Prepending a new element to the linked list
      3. Inserting a new element at a specific position
      4. Returning the position of an element
      5. Removing an element from a specific position
      6. Searching and removing an element from the linked list
      7. Checking if it is empty, clearing and getting the current size
      8. Transforming the linked list into a string
    3. Doubly linked lists
      1. Appending a new element
      2. Prepending a new element to the doubly linked list
      3. Inserting a new element at any position
      4. Removing an element from a specific position
    4. Circular linked lists
      1. Appending a new element
      2. Prepending a new element
      3. Removing an element from a specific position
    5. Creating a media player using a linked list
      1. Adding new songs by title order (sorted insertion)
      2. Playing a song
      3. Playing the next or previous song
      4. Using our media player
    6. Reviewing the efficiency of the linked lists
    7. Exercises
      1. Reverse Linked List
    8. Summary
  8. 7 Sets
    1. The set data structure
    2. Creating the MySet class
      1. Finding a value in the set
      2. Adding values to the set
      3. Removing and clearing all values
      4. Retrieving the size and checking if it is empty
      5. Retrieving all the values
      6. Using the MySet class
    3. Performing mathematical operations with a set
      1. Union: combining two sets
      2. Intersection: identifying common values in two sets
      3. Difference between two sets
      4. Subset: checking if a set contains all the values
    4. The JavaScript Set class
    5. Reviewing the efficiency of sets
    6. Exercises
      1. Remove duplicates from sorted array
    7. Summary
  9. 8 Dictionaries and Hashes
    1. The dictionary data structure
    2. Creating the Dictionary class
      1. Verifying whether a key exists in the dictionary
      2. Setting a key and value in the dictionary
      3. Removing and clearing all values from the dictionary
      4. Retrieving the size and checking if it is empty
      5. Retrieving a value from the dictionary
      6. Retrieving all the values and all the keys from the dictionary
      7. Iterating each value-pair of the dictionary with forEach
      8. Using the Dictionary class
    3. The JavaScript Map class
      1. The JavaScript WeakMap and WeakSet classes
    4. The hash table data structure
    5. Creating the HashTable class
      1. Creating the lose-lose hash function
      2. Putting a key and a value in the hash table
      3. Retrieving a value from the hash table
      4. Removing a value from the hash table
      5. Using the HashTable class
      6. Collisions between keys in a hash table
      7. Handling collisions with separate chaining technique
      8. Handling collisions with the linear probing technique
      9. Creating better hash functions
    6. The hash set data structure
    7. Maps and TypeScript
    8. Reviewing the efficiency of maps and hash maps
    9. Exercises
      1. Integer to Roman
    10. Summary

Product information

  • Title: Learning JavaScript Data Structures and Algorithms - Fourth Edition
  • Author(s): Loiane Groner
  • Release date: December 2024
  • Publisher(s): Packt Publishing
  • ISBN: 9781836205395