【数据结构】第零章 相关基础知识回顾

§0 相关基础知识回顾

§0.1 数据与数据结构

  1. 线性结构(linear structure,也称线性表,如数组、链表、栈、队列等)
  2. 非线性结构(nonlinear structure,如树结构、群结构)

§0.2 C++基础知识回顾

§0.2.1 类的初始化

class Point {
public:
	Point(int, int);
	/* omit */
private:
	int x, y;
};
// Regular initialization
Point::Point(int x, int y) {
	this->x = x;
	this->y = y;
}
// If want to initialize const
Point::Point(int x, int y) : x(x), y(y) {
	/* initialize other variable */
}

§0.2.2 输入输出的重载

class Point {
public:
	Point(int, int);
	/* omit */
	// Overloading of input and output
	friend istream& operator>>(istream& in, Point& p);
	friend ostream& operator<<(ostream& out, Point& p);
private:
	int x, y;
};
// Input overloading is in the same way
ostream& Point::operator<<(ostream& out, Point& p) {
	out << "P(" << p.getX() << "," << p.getY() << ")" << endl;
	return out;
}

§0.2.3 C++中的继承

  1. 子类继承的格式为:class Subclass : public Superclass,即在冒号后选择继承方式(如public)再选择基类。
  2. 子类构造函数的格式为:Subclass(/*argument list*/) : Superclass(/*argument list*/),即在冒号后调用基类的构造函数。
class Animal {
public:
	Animal(int weight) {
		/* omit */
	}
	/* omit */
};
class Fish : public Animal {
public:
	Fish(int weight, int length) : Animal(weight) {
		/* omit */
	}
	/* omit */
};

§0.3 算法概览

§0.3.1 算法的定义

  1. 有输入
  2. 有输出
  3. 确定性(Definiteness)
  4. 有穷性(Finiteness)
  5. 可行性(Effectiveness)

§0.3.2 算法的性能标准

算法是解决特定问题求解步骤的描述,在计算机中表现为指令的有限序列,并且每条指令表示一个或多个操作。

  1. 正确性(Correctness)
  2. 可读性(Readability)
  3. 健壮性(Robustness)
  4. 效率(Efficiency)

§0.3.3 时间复杂度度量

  1. 定义
    在进行算法分析时,语句总的执行次数T(n)是关于问题规模n的函数,进而分析T(n)随n的变化情况,并确定T(n)的数量级。
    算法的时间复杂度,记作:T(n)=O(f(n))。表示随问题规模n的增大,算法执行时间的增长率和f(n)的增长率相同,称作算法的渐近时间复杂度,简称为时间复杂度。其中f(n)是问题规模n的某个函数。用大写O()来体现算法时间复杂度的记法,称之为大O记法
  2. 度量方式
语句程序步数
注释0
声明语句0
不包含函数调用的表达式1
包含函数调用的表达式包括分配给函数调用的程序步数
赋值语句与表达式同理,若赋值语句中的变量是数组或字符串,则程序步数等于变量的体积加上表达式的程序步数
循环语句需要考虑循环控制部分
条件分支语句判断的表达式程序步数+大括号内的步数
转移语句(continue, break, return)除return外为1,return为后面跟的表达式的程序步数
  1. 常见阶数
    常数阶O(1),对数阶O(logn),线性阶O(n),平方阶O(n²),指数阶O(2^n)等。

§0.3.4 空间复杂度度量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值