# @javascript-data-structures/collection

> Collection of Data Structure implementations written in JavaScript

Latest version **1.0.7** (published 2022-10-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install @javascript-data-structures/collection
pnpm add @javascript-data-structures/collection
yarn add @javascript-data-structures/collection
bun add @javascript-data-structures/collection
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2022-10-02 |
| First published | 2022-09-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Omprakash Selvaraj |
| Maintainers | omscse |
| Keywords | heap, priority, queue, data, structures, javascript, trie |

## Links

- npm: https://www.npmjs.com/package/@javascript-data-structures/collection
- Repository: https://github.com/omscse/javascript-data-structures
- Homepage: https://github.com/omscse/javascript-data-structures#readme
- Issues: https://github.com/omscse/javascript-data-structures/issues
- npm.io page: https://npm.io/package/@javascript-data-structures/collection

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 1.0.7 (latest) — 2022-10-02
- 1.0.6 — 2022-10-02
- 1.0.5 — 2022-10-02
- 1.0.4 — 2022-09-24
- 1.0.3 — 2022-09-24
- 1.0.2 — 2022-09-24
- 1.0.1 — 2022-09-24
- 1.0.0 — 2022-09-24

## README

# Collection of Data Structures implemented in JavaScript

[Priority Queue](#priority-queue)

[Trie](#trie)

## Priority Queue

### Complexity

| Heap method            | Time complexity  | Space complexity  | Method |
| -----------------------|:----------------:|:-----------------:|--------|
| Construct a Heap       | O(N)             | O(N)              |heapify |
| Insert an element      | O(logN)          | O(1)              |add     |
| Get the top element    | O(1)             | O(1)              |peak    |
| Delete the top element | O(logN)          | O(1)              |poll    |
| Get the size of a Heap | O(1)             | O(1)              |size    |
		
**N** _is the number of elements in the heap._

### Usage

```
npm install @javascript-data-structures/collection
```

```js

const { PriorityQueue } = require('@javascript-data-structures/collection');

//By Default creates a max heap
let maxHeap = new PriorityQueue();

maxHeap.add(3);
maxHeap.add(5);
maxHeap.add(2);
console.log(maxHeap);


console.log(maxHeap.toString());
console.log(maxHeap.size);

//Min Heap using Comparator Function
let pq = new PriorityQueue((a,b)=>b-a);

pq.heapify([5,4,3,2,1]);
console.log(pq.peak());

//Max Heap using Comparator Function
pq = new PriorityQueue((a,b)=>a-b);

pq.heapify([1,2,3,4,5]);
pq.add(45);
console.log(pq);

//More Ways to prioritize
let priorityQueue = new PriorityQueue((pointA, pointB)=>pointB[2]-pointA[2]);

```

## Trie

### Methods

insert(word) - inserts given word into Trie

search(word) - search for exact word in the Trie. Returns true if exists, false otherwise.

startsWith(prefix) - checks if Trie has words satarting with the given prefix. Returns true if exists, false otherwise.

findAllMatches(prefix) - Retuns all the words matching with the prefix in the Trie.


### Usage

```
npm install @javascript-data-structures/collection
```

```js

const { Trie } = require('@javascript-data-structures/collection');

let trie = new Trie();

trie.insert("apple");

trie.insert("app");

trie.insert("apps");

trie.insert("ball");

trie.insert("b");

console.log(trie.search("ba"));
console.log(trie.startsWith("ball"));
console.log(trie.findAllMatches("app"));

```

---
_Source: https://npm.io/package/@javascript-data-structures/collection · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
