数据结构
定义
数据结构是计算机存储、组织数据的方式
数据结构是相互之间存在的一种或者多种特定关系的数据元素的集合
分类
逻辑结构和物理结构
数据结构课程目录
1.顺序表网吧五连坐
2.链表:神奇的寻宝游戏
3.栈:先进电梯的人最后出来
4.队列:食堂打饭喽
5.树与二叉树:把树倒过来
6.堆与优先队列:把东西堆起来
7.排序算法:从小到大排好队
8.查找与哈希表:缩小范围
9.森林与并查集:谁和谁是一伙的
算法的时间复杂度
用估算算法运行耗时的表达式
//O(1)
printf("hello,world\n");
//O(n)
for(int i=0;i<n;i++){
printf("hello,world\n");
}
//O(n^2)
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("hello,world\n");
}
}
// O(1)
printf("hello,world\n");
printf("hello,world\n");
printf("hello,world\n");
//O(n^2+n)
for(int i=0;i<n;i++){
printf("hello,world\n");
for(int j=0;j<n;j++){
printf("hello,world\n");
}
}
//O(log(m))
while(n){
printf("hello,world"),
n/=2;
}
算法的空间复杂度
用于估算算法占用空间的表达式