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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@snoopylion/algorithms

v1.0.0

Published

本仓库包含了多种基于 JavaScript 的算法与数据结构。

Downloads

1

Readme

JavaScript 算法与数据结构

本仓库包含了多种基于 JavaScript 的算法与数据结构。

注意:这个项目仅用于学习和研究,不是用于生产环境。

数据结构

数据结构是在计算机中组织和存储数据的一种特殊方式,使得数据可以高效地被访问和修改。更确切地说,数据结构是数据值的集合,表示数据之间的关系,也包括了作用在数据上的函数或操作。

B - 初学者, A - 进阶

算法

算法是如何解决一类问题的明确规范。算法是一组精确定义操作序列的规则。

B - 初学者, A - 进阶

算法主题

算法范式

算法范式是一种通用方法,基于一类算法的设计。这是比算法更高的抽象,就像算法是比计算机程序更高的抽象。

如何使用本仓库

安装依赖

npm install

运行 ESLint

检查代码质量

npm run lint

执行测试

npm test

按照名称执行测试

npm test -- 'LinkedList'

有用的信息

引用

▶ YouTube

大O符号

大O符号中指定的算法的增长顺序。

Big O graphs

源: Big O Cheat Sheet.

以下是一些最常用的 大O标记法 列表以及它们与不同大小输入数据的性能比较。

| 大O标记法 | 计算10个元素 | 计算100个元素 | 计算1000个元素 | | -------------- | ---------------------------- | ----------------------------- | ------------------------------- | | O(1) | 1 | 1 | 1 | | O(log N) | 3 | 6 | 9 | | O(N) | 10 | 100 | 1000 | | O(N log N) | 30 | 600 | 9000 | | O(N^2) | 100 | 10000 | 1000000 | | O(2^N) | 1024 | 1.26e+29 | 1.07e+301 | | O(N!) | 3628800 | 9.3e+157 | 4.02e+2567 |

数据结构操作的复杂性

| 数据结构 | 连接 | 查找 | 插入 | 删除 | 备注 | | -------------- | :----: | :----: | :----: | :----: | ---- | | 数组 | 1 | n | n | n | | | | n | n | 1 | 1 | | | 队列 | n | n | 1 | 1 | | | 链表 | n | n | 1 | 1 | | | 哈希表 | - | n | n | n | 在完全哈希函数情况下,复杂度是 O(1) | | 二分查找树 | n | n | n | n | 在平衡树情况下,复杂度是 O(log(n)) | | B 树 | log(n) | log(n) | log(n) | log(n) | | | 红黑树 | log(n) | log(n) | log(n) | log(n) | | | AVL 树 | log(n) | log(n) | log(n) | log(n) | | | 布隆过滤器 | - | 1 | 1 | - | 存在一定概率的判断错误(误判成存在) |

数组排序算法的复杂性

| 名称 | 最优 | 平均 | 最坏 | 内存 | 稳定 | 备注 | | --------------------- | :-------: | :-------: | :-----------: | :-------: | :-------: | --------------------- | | 冒泡排序 | n | n^2 | n^2 | 1 | Yes | | | 插入排序 | n | n^2 | n^2 | 1 | Yes | | | 选择排序 | n^2 | n^2 | n^2 | 1 | No | | | 堆排序 | n log(n) | n log(n) | n log(n) | 1 | No | | | 归并排序 | n log(n) | n log(n) | n log(n) | n | Yes | | | 快速排序 | n log(n) | n log(n) | n^2 | log(n) | No | 在 in-place 版本下,内存复杂度通常是 O(log(n)) | | 希尔排序 | n log(n) | 取决于差距序列 | n (log(n))^2 | 1 | No | | | 计数排序 | n + r | n + r | n + r | n + r | Yes | r - 数组里最大的数 | | 基数排序 | n * k | n * k | n * k | n + k | Yes | k - 最长 key 的升序 |