---
title: "数据结构_概述"
author: "包su"
date: "2013-04-15T18:29:54Z"
tags: []
categories: ["企业架构"]
slug: "untitled"
draft: false
lastmod: "2013-04-15T18:28:45Z"
id: 1847782
url: "https://baosu.iteye.com/blog/1847782"
---

前言\*\*\*\**

最近在看 data structures and algorithms in java，也准备把 算法导论 看一下

之下 和 本分类 将记录一些 数据结构 相关的问题

日后，将持续 完善/修正 本分类

 

正文\*\*\*\**

 

1.什么是 数据结构 和 算法：

a data structure is a systematic way of organizing and access­ing data,

and an algorithm is a step-by-step procedure for performing some task in a finite amount of time

 

2.算法效率的考量

characterizing the running times of algorithms and data structure operations,

with  space usage also being of interest

即是：时间复杂度 和 空间复杂度

 

2.1.时间复杂度

只是给人大致感觉

时间复杂度为O(n)的算法a的所耗费的时间 不一定比 O(n^2)的算法b的所耗费的时间 少

但是，一般情况下（如n很大时），小

请，仅和问题的规模n有关

时间 会随着 n的增大而xxx，和其他的因素无关

 

primitive operation：

如：赋值操作，这些操作，本身所耗费的时间能被计算（被认为是一个constant），

由它们所耗费的时间，最终得出 算法耗费的总时间

 

大Ο

![](http://dl.iteye.com/upload/attachment/0083/1900/591c7f0d-bd59-31d7-8827-60464d3d84e4.jpg)

我们通常用大O来表示 时间复杂度，如：算法的时间复杂度为g(n)

那么，f(n)是什么

它是另外一个多项式

如，对于算法![](http://dl.iteye.com/upload/attachment/0083/1912/003f3b1b-5fda-394a-96e2-042d46bd2ae5.jpg)  
大致上要执行：

i=0时，1次a赋值，1次A\[i]赋值，1次j赋值，1次j比较，1次a赋值

i=1时，1次a赋值，1次A\[i]赋值，2次j赋值，2次j比较，2次a赋值

i=k时，1次a赋值，1次A\[i]赋值，k次j赋值，k次j比较，k次a赋值

...

将上述时间相加，你会得出f(n)=...

而，我们也往往通过这种计算，得出时间复杂度

 

常见的时间复杂度排序（从小到大） 

![](http://dl.iteye.com/upload/attachment/0083/1879/b35be06a-368a-3b8e-acf2-810b4113d128.jpg)

 

大Ω

![](http://dl.iteye.com/upload/attachment/0083/1902/fd97c9aa-23b8-3b00-9287-cd1808c6bdf7.jpg)  
 

大Θ  
![](http://dl.iteye.com/upload/attachment/0083/1904/1a426ae4-00ae-3d87-9c4b-1407b6fb1c06.jpg)