Quick Sort:

Time complexity: best case O(n*lgn), worst case O(n^2)

Space complexity: Best case O(lgn) -> call stack height

Worse case O(n^2) -> call stack height

Merge Sort

Time complexity: always O(n*lgn) because we always divide the array in halves.

Space complexity: O(lgn +  n)

Time & Space Complexity的更多相关文章

  1. 空间复杂度是什么?What does ‘Space Complexity’ mean? ------geeksforgeeks 翻译

    这一章比较短! 空间复杂度(space complexity)和辅助空间(auxiliary space)经常混用,下面是正确的辅助空间和空间复杂度的定义 辅助空间:算法需要用到的额外或者暂时的存储空 ...

  2. 什么是空间复杂度(What is actually Space Complexity ?)

    属于空间复杂度(Space Complexity)在很多情况下被错认为是附属空间(Auxiliary Space),下面是附属空间和空间复杂度的定义. 附属空间(Auxiliary Space)是算法 ...

  3. [Algorithm] Fibonacci Sequence - Anatomy of recursion and space complexity analysis

    For Fibonacci Sequence, the space complexity should be the O(logN), which is the height of tree. Che ...

  4. 空间复杂度(Space Complexity)

    空间复杂度(Space Complexity) 算法得存储量包括: 1.程序本身所占空间. 2.输入数据所占空间. 3.辅助变量所占空间. 输入数据所占空间只取决于问题本身,和算法无关,则只需分析除输 ...

  5. Sort a linked list in O(n log n) time using constant space complexity.

    因为题目要求复杂度为O(nlogn),故可以考虑归并排序的思想. 归并排序的一般步骤为: 1)将待排序数组(链表)取中点并一分为二: 2)递归地对左半部分进行归并排序: 3)递归地对右半部分进行归并排 ...

  6. 时间&空间(complexity)

    时间&空间复杂度 时间复杂度: 通俗来说就是随着数据量的增加,程序运行的时间花费量是怎么变化的,时间复杂度常用大o表示.举个例子,猜数字,猜10个,100个.1000个,猜数的数据量是在增加的 ...

  7. Leetcode: Convert sorted list to binary search tree (No. 109)

    Sept. 22, 2015 学一道算法题, 经常回顾一下. 第二次重温, 决定增加一些图片, 帮助自己记忆. 在网上找他人的资料, 不如自己动手. 把从底向上树的算法搞通俗一些. 先做一个例子: 9 ...

  8. [LeetCode] Counting Bits 计数位

    Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the ...

  9. [LeetCode] Increasing Triplet Subsequence 递增的三元子序列

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

随机推荐

  1. Manthan, Codefest 19

    目录 Contest Info Solutions A. XORinacci B. Uniqueness C. Magic Grid D. Restore Permutation E. Let The ...

  2. 「CF150E」Freezing with Style「点分治」「单调队列」

    题意 给定一颗带边权的树,求一条边数在\(L\).\(R\)之间的路径,并使得路径上边权的中位数最大.输出一条可行路径的两个端点.这里若有偶数个数,中位数为中间靠右的那个. \(n, L, R\leq ...

  3. 使用python画一颗圣诞树

    # -*- coding: utf-8 -*- # @Time : 18-12-26 上午9:32 # @Author : Felix Wang import turtle # 定义圣诞树的绿叶函数 ...

  4. codeforces396A

    sol:很显然就是找出所有质因数,然后分别塞进去就行了,怎么塞就是组合数.感觉就是道小学奥数题 #include <bits/stdc++.h> using namespace std; ...

  5. Spring - 环境安装

    安装IDEA的非Community版本和Java的包之后就可以用Java来HelloWorld了. 然后去这个链接:https://github.com/spring-guides/gs-rest-s ...

  6. 线程wait和notify方法的demo详解

    wait和notify都是针对某个线程而言的: package com.roocon.thread.t1; public class NewThread implements Runnable { @ ...

  7. 什么是IO流

    先看一段百度上的解释: 当然:如果你看不懂,那么你只需要记住下面3句话. 1. (1).我们知道,每个人家里喝的水都是从自来水厂来的,自来水厂的水又是从水源地来的, (2).水是通过水管来的. (3) ...

  8. 服务端 CORS 解决跨域

    当协议.域名.端口中任一个不同时产生跨域 CORS 跨域资源共享(Cross-origin resource sharing) 参考资料https://developer.mozilla.org/zh ...

  9. 上下文对象-请求对象-响应对象(ServletContext - response - request)

    目录 上下文对象-请求对象-响应对象 ServletContext response request 上下文对象-请求对象-响应对象 ServletContext 什么是ServletContext ...

  10. Matlab注释的几个方法

    Matlab最简单的注释当然是 %x= %这是注释,无法运行 x= %结果为2 然而%只能注释一行,如何注释更加快捷简便地注释多行呢? %{ .这就是传说中的多行注释 .成功! %} 经常需要调试程序 ...