O(1):constant - the operation doesn't depend on the size of its input, e.g. adding a node to the tail of a linked list where we always maintain a pointer to the tail node.
int i=0;
i++;
++i;
i+=6;
O(n):linear - the run time complexity is proportionate to the size of n.
int i,n=100,s=0;
for(i=0;i<n;i++)
{
s+=1;
}
O(n2):quadratic - the run time complexity is proportionate to the square of size of n, e.g., bubble sort.
int i,j,n=100,s=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
s+=1;
}

}
O(n3):cubic - very rare.
int i,j,k,n=100,s=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
s+=1;
}
}
}
O(logmn): logarithmic: normally associated with algorithms that break the problem into smaller chunks per each invocation, e.g. searching a binary search tree.
int i,n=100,m=2; /* m could be any number, e.g.,2,10 */
for(i=0;i<n;i++)
{
i=i*m;
}
O(nlogn): just nlogn: usually associated with an algorithm that breaks the problem into smaller chunks per each invocation, and then takes the results of these smaller chunks and stitches them back together, e.g. quick sort.
int i,n=100;

int m_expo(int m)
{
/* an auxilary function that return the value
of m to the mth exponential, not included to the
time consumation*/

int k = m;
for(j=1;j<m;j++)
{
/* 2 could also be other number */
k = k * k;
}
return k;
}

/* this is the part whose consumation is O(nlogn) */
for(i=0;i<m_expo(n);i++)
{
/* 10 could be other number */
i=i*10;
}
O(n1/2): square root.
int i,n=100;
while(i*i<n)
{
i++;
}
O(2n):exponential - incredibly rare.
int i,n=100;
int expo(int m)
{
/* an auxilary function that return the value
of 2 to the mth exponential, not included to the
time consumation*/

int k =1;
for(j=1;j<m;j++)
{
/* 2 could also be other number */
k = k * 2;
}
return k;
}

/* this is the part whose consumation is O(2n)) */
while(i<expo(n))
{
i++;
}
O(n!):factorial - incredibly rare.
int i,n=100;
int factorial(int m)
{
/* an auxilary function that return the
factorial value of m */

int k =1;
for(j=1;j<=m;j++)
{
/* 2 could also be other number */
k = j * k;
}
return k;
}

/* this is the part whose consumation is O(n!) */
while(i<factorial(n))
{
i++;
}
O(nn):not exist in real life.
int i,n=100;
int mm_expo(int m)
{
/* an auxilary function that return the value
of m to the mth exponential, not included to the
time consumation*/

int k = m;
for(j=1;j<m;j++)
{
k = k * m;
}
return k;
}

/* this is the part whose consumation is O(nn)) */
while(i<mm_expo(n))
{
i++;
}

Examples of complexity pattern的更多相关文章

  1. Observer Pattern

    Motivation We can not talk about Object Oriented Programming without considering the state of the ob ...

  2. A Pattern Language for Parallel Application Programming

    A Pattern Language for Parallel Application Programming Berna L. Massingill, Timothy G. Mattson, Bev ...

  3. 脚本AI与脚本引擎

    Scripted AI and Scripting Engines 脚本AI与脚本引擎 This chapter discusses some of the techniques you can us ...

  4. linq 动态组合条件

    http://www.albahari.com/nutshell/predicatebuilder.aspx Dynamically Composing Expression Predicates S ...

  5. Java内部类、静态嵌套类、局部内部类、匿名内部类

    Nested classes are further divided into two types: static nested classes: If the nested class is sta ...

  6. Python中的正则表达式regular expression

    1 match = re.search(pat,str)  If the search is successful, search() returns a match object or None o ...

  7. DescribingDesign Patterns 描述设计模式

    DescribingDesign Patterns 描述设计模式 How do we describe design patterns?Graphical notations, while impor ...

  8. 【ASP.NET Web API教程】3.2 通过.NET客户端调用Web API(C#)

    原文:[ASP.NET Web API教程]3.2 通过.NET客户端调用Web API(C#) 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本博客文章,请先看前面的 ...

  9. A brief introduction to weakly supervised learning(简要介绍弱监督学习)

    by 南大周志华 摘要 监督学习技术通过学习大量训练数据来构建预测模型,其中每个训练样本都有其对应的真值输出.尽管现有的技术已经取得了巨大的成功,但值得注意的是,由于数据标注过程的高成本,很多任务很难 ...

随机推荐

  1. 扩展django的User的部分方法

    这做项目时发现django自带的User中的字段不够用,默认的auth_user表总共只有11个字段,如果需要更多的字段该怎么办,在网上搜了一下,有这么几种方法. 1. 直接修改django 源码,修 ...

  2. Learning Bayesian Network Classifiers by Maximizing Conditional Likelihood

    Abstract Bayesian networks are a powerful probabilistic representation, and their use for classifica ...

  3. JavaScript测试题

    您的回答: 1.我们可以在下列哪个 HTML 元素中放置 Javascript 代码? 您的回答:<script> 2.写 "Hello World" 的正确 Java ...

  4. Spark源码学习1.6——Executor.scala

    Executor.scala 一.Executor类 首先判断本地性,获取slaves的host name(不是IP或者host: port),匹配运行环境为集群或者本地.如果不是本地执行,需要启动一 ...

  5. yii2从零开始一,安装

    1.官网下载软件包 这里选择普通包,也可以是增强包 2.运行basic目录下 requirements.php ,查看环境是否符合要求,yii2要求php5.4以上 3.运行 basic/web下in ...

  6. Mysqli封装

    <?php //headerheader('content-type:text/html;charset=UTF-8'); class DB {    //定义属性    private $ho ...

  7. opensuse 13.1 安装配置从0开始

    主要目的为自己留作备份,仅作参考! 1. 输入法 托盘->输入法->配置 去掉除英语和Sunpinyin之外的输入法,配置Sunpinyin,使用双拼方案,重启fcitx. 另外需要禁用笔 ...

  8. 学习Core 本机开发调试 (环境)

    安装  https://www.microsoft.com/net/download 本机开发调试 需要下载安装这3个,如果没装 windows(Server Hosting)可能会 出现502.5报 ...

  9. 关于Blender

    一.插入背景图片  1.'N'调出右栏工具,拖至后面有Background Images 打钩,点开三角形,按'add image'all views 可以确定加入图片到哪个view,open可以添加 ...

  10. 对git的理解及常用指令

    以前总听说git[分布式版本控制系统]自己愣是搞不懂它到底要干哈-什么叫版本控制系统根本理解不了.现在工作需要必须要用到,结果好像就突然懂了git是干什么滴. 所以!原理这个东西的理解是要建立在大量的 ...