npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

sorting_alltype_sorting

v1.1.1

Published

Bubble_sor Selection_sort insertion_sort Heap_sort Radix_sort Counting_sort

Readme

Binary Search and Sorting Algorithms Package

This package provides a collection of common algorithms implemented in JavaScript, including:

  • Binary Search
  • Kadane's Algorithm
  • Sorting Algorithms:
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
    • Merge Sort
    • Quick Sort
    • Heap Sort
    • Radix Sort
    • Counting Sort

Installation

You can install this package via npm:

npm install sorting_alltype_sorting

## How It Works

# Usage
# 1. Binary Search
Binary search finds the index of a target value within a sorted array. It works by repeatedly dividing the search interval in half. If the value of the target is less than the value in the middle of the interval, the search continues on the left half, otherwise, it continues on the right half. The algorithm has a time complexity of O(log n).

const { binarySearch } = require('sorting_alltype_sorting');

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const target = 5;
const index = binarySearch(arr, target);

console.log('Index of 5:', index); // Output: Index of 5: 4


# 2. Kadane's Algorithm
Kadane's Algorithm is used to find the maximum sum of a contiguous subarray in an array of integers. It works by iterating through the array, maintaining two values: currentMax, which is the maximum sum of the subarray that ends at the current index, and globalMax, which stores the maximum sum found so far. If currentMax becomes negative, it's reset to 0. The time complexity is O(n).


const { kadane } = require('sorting_alltype_sorting');

const arr = [1, -2, 3, 4, -1, 2, 1, -5, 4];
const maxSum = kadane(arr);

console.log('Maximum sum of subarray:', maxSum); // Output: Maximum sum of subarray: 9

# 3. Sorting Algorithms

#Bubble Sort
Bubble sort works by repeatedly stepping through the list to be sorted, comparing adjacent elements and swapping them if they are in the wrong order. The process is repeated until the list is sorted. The time complexity is O(n^2).

const { bubbleSort } = require('sorting_alltype_sorting');

const arr = [10, 5, 2, 8, 3, 1];
console.log('Bubble Sort:', bubbleSort(arr)); // Output: [1, 2, 3, 5, 8, 10]

#Selection Sort
Selection sort works by repeatedly finding the minimum element from the unsorted part of the list and swapping it with the first unsorted element. The time complexity is O(n^2).

const { selectionSort } = require('sorting_alltype_sorting');

const arr = [10, 5, 2, 8, 3, 1];
console.log('Selection Sort:', selectionSort(arr)); // Output: [1, 2, 3, 5, 8, 10]

#Insertion Sort
Insertion sort works by building a sorted list one element at a time. It iterates through the list and inserts each element into its correct position in the already sorted part of the list. The time complexity is O(n^2).

const { insertionSort } = require('sorting_alltype_sorting');

const arr = [10, 5, 2, 8, 3, 1];
console.log('Insertion Sort:', insertionSort(arr)); // Output: [1, 2, 3, 5, 8, 10]

#Heap Sort
Heap sort works by first building a max heap from the input data and then repeatedly extracting the maximum element from the heap and rebuilding the heap. The time complexity is O(n log n).

const { heapSort } = require('sorting_alltype_sorting');

const arr = [10, 5, 2, 8, 3, 1];
console.log('Heap Sort:', heapSort(arr)); // Output: [1, 2, 3, 5, 8, 10]

#Radix Sort
Radix sort works by sorting the input numbers digit by digit, starting from the least significant digit. It uses a stable sub-sorting algorithm (like counting sort) to sort the numbers by each digit. The time complexity is O(nk), where n is the number of elements and k is the number of digits.


const { radixSort } = require('sorting_alltype_sorting');

const arr = [10, 5, 2, 8, 3, 1];
console.log('Radix Sort:', radixSort(arr)); // Output: [1, 2, 3, 5, 8, 10]

#Counting Sort
Counting sort works by counting the occurrences of each element in the input list and using this information to place the elements in the correct sorted position. It is efficient when the range of numbers is known and not too large. The time complexity is O(n + k), where n is the number of elements and k is the range of input.

const { countingSort } = require('sorting_alltype_sorting');

const arr = [10, 5, 2, 8, 3, 1];
console.log('Counting Sort:', countingSort(arr)); // Output: [1, 2, 3, 5, 8, 10]

## 4. Example Usage with All Algorithms

const { bubbleSort, selectionSort, insertionSort, heapSort, radixSort, countingSort } = require('sorting_alltype_sorting');

const arr = [10, 5, 2, 8, 3, 1];

console.log('Bubble Sort:', bubbleSort(arr));
console.log('Selection Sort:', selectionSort(arr));
console.log('Insertion Sort:', insertionSort(arr));
console.log('Heap Sort:', heapSort(arr));
console.log('Radix Sort:', radixSort(arr));
console.log('Counting Sort:', countingSort(arr));



### Instructions:

1. **Create the `README.md` file** in the root of your project folder.
2. **Copy and paste the content** from the above markdown into the file.
3. **Customize the content** if needed, such as adjusting the package name or adding more detailed instructions.

This README file covers all the sorting algorithms, binary search, and Kadane's Algorithm, providing clear usage examples.