Book Image

Hands-On Data Structures and Algorithms with JavaScript

By : Kashyap Mukkamala
Book Image

Hands-On Data Structures and Algorithms with JavaScript

By: Kashyap Mukkamala

Overview of this book

Data structures and algorithms are the fundamental building blocks of computer programming. They are critical to any problem, provide a complete solution, and act like reusable code. Using appropriate data structures and having a good understanding of algorithm analysis are key in JavaScript to solving crises and ensuring your application is less prone to errors. Do you want to build applications that are high-performing and fast? Are you looking for complete solutions to implement complex data structures and algorithms in a practical way? If either of these questions rings a bell, then this book is for you! You'll start by building stacks and understanding performance and memory implications. You will learn how to pick the right type of queue for the application. You will then use sets, maps, trees, and graphs to simplify complex applications. You will learn to implement different types of sorting algorithm before gradually calculating and analyzing space and time complexity. Finally, you'll increase the performance of your application using micro optimizations and memory management. By the end of the book you will have gained the skills and expertise necessary to create and employ various data structures in a way that is demanded by your project or use case.
Table of Contents (16 chapters)
Title Page
Copyright and Credits
PacktPub.com
Contributors
Preface
5
Simplify Complex Applications Using Graphs
Index

Chapter 7. Sorting and Its Applications

Sorting is a very common algorithm that we use to rearrange a list of numbers or objects in an ascending or descending order. A more technical definition of sorting is as follows:

In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order.

Now, let's assume that you have a list of n items, and you want to sort them. You take all the n items and determine all the possible sequences in which you can place these items, which, in this case, would be n! in total. We now need to determine which of these n! series does not have any inverted pairs to find out the sorted list. An inverted pair is defined as a pair of elements whose position in the list is represented by i, j where i < j, but the values xi > xj.

Of course, the preceding method is tedious and requires some heavy computation. In this chapter we will be discussing the following topics:

  • Types of sorting algorithms
  • Creating an API for a book management...