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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bento.julio/find-min-array

v1.0.2

Published

Find the minimum number in an array using multiple algorithms

Readme

find-min-array

Find the minimum number in an array using multiple algorithms.

Installation

npm install find-min-array

Usage

findMin(arr, algorithm?)

The main entry point. Accepts an array and an optional algorithm name (defaults to "linear").

const { findMin } = require("find-min-array");

findMin([3, 1, 4, 1, 5]);                        // 1
findMin([3, 1, 4, 1, 5], "divide-and-conquer");  // 1
findMin([3, 1, 4, 1, 5], "tournament");          // 1
findMin([3, 1, 4, 1, 5], "heap");                // 1

Importing algorithms directly

const { linearMin }           = require("find-min-array");
const { divideAndConquerMin } = require("find-min-array");
const { tournamentMin }       = require("find-min-array");
const { heapMin, MinHeap }    = require("find-min-array");

Algorithms

Linear — "linear"

Iterates through the array once, tracking the current minimum.

  • Time: O(n)
  • Space: O(1)
  • Best for: General use. Simple and memory-efficient.
linearMin([8, 3, 7, 1, 5]); // 1

Divide and Conquer — "divide-and-conquer"

Splits the array in half recursively, comparing the minimum from each half until a single value remains.

  • Time: O(n)
  • Space: O(log n) — call stack depth
  • Best for: Demonstrating recursive decomposition on large arrays.
divideAndConquerMin([8, 3, 7, 1, 5]); // 1

Tournament — "tournament"

Pairs elements and compares them in elimination rounds, like a tournament bracket, until one winner (the minimum) remains.

  • Time: O(n)
  • Space: O(n)
  • Best for: Scenarios that require finding both minimum and second minimum, or multiple ranked results.
tournamentMin([8, 3, 7, 1, 5]); // 1

Min-Heap — "heap"

Builds a min-heap from the array in O(n). The root of the heap is always the minimum, accessible in O(1).

  • Time: O(n) to build, O(1) to query
  • Space: O(n)
  • Best for: Repeated minimum queries on the same dataset.
heapMin([8, 3, 7, 1, 5]); // 1

// Use MinHeap directly for repeated queries
const { MinHeap } = require("find-min-array");
const heap = new MinHeap([8, 3, 7, 1, 5]);
heap.min(); // 1

Algorithm Comparison

| Algorithm | Time | Space | Best Use Case | |--------------------|-------|----------|----------------------------------------| | Linear | O(n) | O(1) | General use, memory-constrained | | Divide and Conquer | O(n) | O(log n) | Large arrays, recursive approach | | Tournament | O(n) | O(n) | Multiple ranked results needed | | Min-Heap | O(n)* | O(n) | Repeated minimum queries on same data |

*O(n) to build, O(1) per query thereafter.

Error Handling

All functions throw an Error if the input is not a non-empty array:

findMin([]);          // Error: Input must be a non-empty array
findMin("invalid");   // Error: Input must be a non-empty array
findMin([1], "sort"); // Error: Unknown algorithm "sort". Available: linear, divide-and-conquer, tournament, heap

Running Tests

npm test

35 tests covering: typical arrays, single elements, negative numbers, identical values, odd/even lengths, empty arrays, and invalid inputs.

License

MIT