首页 > 其他分享 >Know Thy Complexities!

Know Thy Complexities!

时间:2023-08-12 09:22:51浏览次数:44  
标签:Sort log Thy Complexities Big Tree Complexity Algorithms Know

https://www.bigocheatsheet.com/

 

Know Thy Complexities!

Hi there!  This webpage covers the space and time Big-O complexities of common algorithms used in Computer Science.  When preparing for technical interviews in the past, I found myself spending hours crawling the internet putting together the best, average, and worst case complexities for search and sorting algorithms so that I wouldn't be stumped when asked about them.  Over the last few years, I've interviewed at several Silicon Valley startups, and also some bigger companies, like Google, Facebook, Yahoo, LinkedIn, and Uber, and each time that I prepared for an interview, I thought to myself "Why hasn't someone created a nice Big-O cheat sheet?".  So, to save all of you fine folks a ton of time, I went ahead and created one.  Enjoy! - Eric

Automated codebase migrations and upgrades

Big-O Complexity Chart

Horrible Bad Fair Good Excellent
O(log n), O(1)O(n)O(n log n)O(n^2)O(2^n)O(n!)OperationsElements <iframe data-google-container-id="a!2" data-google-query-id="CNPrnNWf04ADFWXg_QUd1O4PEw" data-load-complete="true" frameborder="0" height="90" id="aswift_1" marginheight="0" marginwidth="0" name="aswift_1" scrolling="no" src="https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-8154832549041429&output=html&h=90&slotname=4018097420&adk=556369392&adf=545954419&pi=t.ma~as.4018097420&w=728&lmt=1691710218&format=728x90&url=https%3A%2F%2Fwww.bigocheatsheet.com%2F&wgl=1&uach=WyJXaW5kb3dzIiwiMTAuMC4wIiwieDg2IiwiIiwiMTE1LjAuNTc5MC4xMTAiLFtdLDAsbnVsbCwiNjQiLFtbIk5vdC9BKUJyYW5kIiwiOTkuMC4wLjAiXSxbIkdvb2dsZSBDaHJvbWUiLCIxMTUuMC41NzkwLjExMCJdLFsiQ2hyb21pdW0iLCIxMTUuMC41NzkwLjExMCJdXSwwXQ..&dt=1691710218395&bpp=2&bdt=180&idt=177&shv=r20230808&mjsv=m202308030102&ptt=9&saldr=aa&abxe=1&cookie=ID%3Debd82ab075180d33-221d7ef9f5df006a%3AT%3D1691708843%3ART%3D1691708843%3AS%3DALNI_MbfKh0BC5EA7ndC95Ra6CfjtyZnWQ&gpic=UID%3D000009b2a5d19e3a%3AT%3D1691708843%3ART%3D1691708843%3AS%3DALNI_MY5F4Z6VIC1RuBvN7bb9v_Qzp_9fQ&prev_fmts=728x90&correlator=3742292443170&frm=20&pv=1&ga_vid=1412108353.1691708843&ga_sid=1691708843&ga_hid=1761674058&ga_fc=1&u_tz=-420&u_his=2&u_h=864&u_w=1536&u_ah=824&u_aw=1536&u_cd=24&u_sd=1.25&dmc=8&adx=396&ady=1060&biw=1519&bih=747&scr_x=0&scr_y=1199&eid=44759875%2C44759926%2C44759842%2C31076088%2C31076924&oid=2&pvsid=4082433024244417&tmod=2034147749&uas=0&nvt=3&ref=https%3A%2F%2Fwww.google.com%2F&fc=896&brdim=0%2C0%2C0%2C0%2C1536%2C0%2C1536%2C824%2C1536%2C747&vis=1&rsz=%7C%7CeE%7C&abl=CS&pfx=0&fu=0&bc=31&ifi=2&uci=a!2&fsb=1&xpc=HhRCDBjNfE&p=https%3A//www.bigocheatsheet.com&dtd=183" width="728"></iframe>

Common Data Structure Operations

Data StructureTime ComplexitySpace Complexity
 AverageWorstWorst
 AccessSearchInsertionDeletionAccessSearchInsertionDeletion 
Array Θ(1) Θ(n) Θ(n) Θ(n) O(1) O(n) O(n) O(n) O(n)
Stack Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)
Queue Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)
Singly-Linked List Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)
Doubly-Linked List Θ(n) Θ(n) Θ(1) Θ(1) O(n) O(n) O(1) O(1) O(n)
Skip List Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(n) O(n) O(n) O(n) O(n log(n))
Hash Table N/A Θ(1) Θ(1) Θ(1) N/A O(n) O(n) O(n) O(n)
Binary Search Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(n) O(n) O(n) O(n) O(n)
Cartesian Tree N/A Θ(log(n)) Θ(log(n)) Θ(log(n)) N/A O(n) O(n) O(n) O(n)
B-Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
Red-Black Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
Splay Tree N/A Θ(log(n)) Θ(log(n)) Θ(log(n)) N/A O(log(n)) O(log(n)) O(log(n)) O(n)
AVL Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(log(n)) O(log(n)) O(log(n)) O(log(n)) O(n)
KD Tree Θ(log(n)) Θ(log(n)) Θ(log(n)) Θ(log(n)) O(n) O(n) O(n) O(n) O(n)

Array Sorting Algorithms

AlgorithmTime ComplexitySpace Complexity
 BestAverageWorstWorst
Quicksort Ω(n log(n)) Θ(n log(n)) O(n^2) O(log(n))
Mergesort Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(n)
Timsort Ω(n) Θ(n log(n)) O(n log(n)) O(n)
Heapsort Ω(n log(n)) Θ(n log(n)) O(n log(n)) O(1)
Bubble Sort Ω(n) Θ(n^2) O(n^2) O(1)
Insertion Sort Ω(n) Θ(n^2) O(n^2) O(1)
Selection Sort Ω(n^2) Θ(n^2) O(n^2) O(1)
Tree Sort Ω(n log(n)) Θ(n log(n)) O(n^2) O(n)
Shell Sort Ω(n log(n)) Θ(n(log(n))^2) O(n(log(n))^2) O(1)
Bucket Sort Ω(n+k) Θ(n+k) O(n^2) O(n)
Radix Sort Ω(nk) Θ(nk) O(nk) O(n+k)
Counting Sort Ω(n+k) Θ(n+k) O(n+k) O(k)
Cubesort Ω(n) Θ(n log(n)) O(n log(n)) O(n)

Learn More

Get the Official Big-O Cheat Sheet Poster

Contributors

标签:Sort,log,Thy,Complexities,Big,Tree,Complexity,Algorithms,Know
From: https://www.cnblogs.com/kungfupanda/p/17624354.html

相关文章

  • 知识图谱(Knowledge Graph)- Neo4j 5.10.0 CentOS 安装
    系统需求版本JDKCPU内存硬盘Neo4j5.x17Intelx86-x64Corei3minimum,Corei7recommended.AMDx86-x64,MacARM.最低2GB,推荐16GB+10G+Neo4j5.x11Neo4j5.x8JDK17下载:https://www.oracle.com/java/technologies/do......
  • 知识图谱(Knowledge Graph)根本概念
    目录知识图谱定义基础概念:知识图谱构建的关键技术知识图谱的构建实体命名识别知识抽取实体统一指代消解知识图谱的存储RDF和图数据库的主要特点区别知识图谱能干什么反欺诈不一致性验证客户失联管理知识推理常见图数据库2012年5月17日,Google正式提出了知识图谱(KnowledgeGraph)的......
  • typeScript学习-TS类型-其他特殊类型-any、unknown
    typeScript学习其他特殊类型:any,unknown,never,void,元组(tuple),可变元组 any比较经典的应用场景:1、自定义守卫2、需要进行asany类型断言的场景unknown一般用作函数参数:用来接收任意类型的变量实参,但在函数内部只用于再次传递或输出结果,不获......
  • ethereum错误之already known
    根据提供的错误信息error(*github.com/ethereum/go-ethereum/rpc.jsonError)*{Code:-32000,Message:"alreadyknown",Data:interface{}nil},这是一个来自以太坊的JSON-RPC错误。该错误的含义是“alreadyknown”,即“已经存在”。在以太坊中,当您尝试发送一个已经存在于区......
  • spring-mvc 系列:视图(ThymeleafView、InternalResourceView、RedirectView)
    目录一、ThymeleafView二、转发视图三、重定向视图四、视图控制器view-controller五、配置jsp解析SpringMVC中的视图是View接口,视图的作用渲染数据,将模型Model中的数据展示给用户SpringMVC视图的种类很多,默认有转发视图和重定向视图当工程引入jstl的依赖,转发视图会自动转换为Js......
  • 解决报错:Redis ERR unknown command ‘FLUSHDB‘
    RedisERRunknowncommand‘FLUSHDB’报错信息:ERRunknowncommand`flushdb`ERRunknowncommand`flushall`解决方案:我的redis版本是5.0.7修改配置文件打开/etc/redis/redis.conf文件,将下面两行代码注释掉rename-commandFLUSHALL37_dba_FLUSHALLrename-commandFLUSHDB......
  • nvidia-docker启动容器报错 Unknown runtime specified nvidia
    使用nvidia-docker创建容器时报错:Errorresponsefromdaemon:Unknownruntimespecifiednvidia.See'dockerrun--help'.主要原因在于配置docker镜像时,daemon.json文件被修改了。只要添加对应内容即可。vim /etc/docker/daemon.json原文件:{"registry-mirr......
  • Springboot中怎么选择性使用thymeleaf进行渲染?
    SpringBoot默认支持多种模板引擎,包括Thymeleaf。如果你想选择性地使用Thymeleaf进行渲染,这基本上取决于你的Controller的实现。以下是一个基本示例:首先,确保你的SpringBoot项目已经添加了Thymeleaf的依赖。在你的pom.xml文件中,你应该看到类似以下的内容<dependency>......
  • 论文解读(Moka‑ADA)《Moka‑ADA: adversarial domain adaptation with model‑orient
     Note:[wechat:Y466551|可加勿骚扰,付费咨询]论文信息论文标题:Moka‑ADA:adversarialdomainadaptation withmodel‑orientedknowledgeadaptation forcross‑domainsentimentanalysis论文作者:MaoyuanZhangXiangLiFeiWu论文来源:2023aRxiv论文地址:download 论......
  • rke up etcd报错: etcd cluster is unhealthy
    问题添加node,rkeup报错:WARN[0197][etcd]host[10.7.0.51]failedtochecketcdhealth:failedtoget/healthforhost[10.7.0.51]:Get"https://10.7.0.51:2379/health":remoteerror:tls:badcertificateWARN[0290][etcd]host[10.7.0.52]failedtoch......