数据结构完全小白,本科两门数据库,选修课数据结构却被我落下了...当时不知道这么重要吖。。
入门选了两本书,普林斯顿的《算法(第四版》和《大话数据结构》,打算好好补补数据结构的知识
列了一下大神们的建议,慢慢攻破~~
1. Arrays 数组
- Know how to use arrays. You will use them a lot.
- Learn how to make them grow dynamically (for programming languages like C).
- Know how to use a standard library array (example: vector)
- Learn to use strings (they are arrays).
- Know how to sort them with two good sorting algorithms (QuickSort and MergeSort)
- Learn to search in an array. First linear search and then binary search.
- Learn QuickSelect, it will be useful.
2. Linked Lists 线性表
- Learn to create a linked list.
- Know the basic operations: insert, print, delete. 幼儿园小朋友排队的例子让我对这个记忆很深~
- You won't use linked lists a lot in the real word, but having a solid understanding of how they work will be of great use.
- Know different versions of linked lists: circular and double, for example. 循环链表和双向链表,以及书中还介绍了静态链表
- Know the advantages of a linked list vs an array 数组需要考虑下标增减的问题
3-4. Stacks and Queues 栈和队列
- Learn to implement stacks and queues with arrays and lists. Know the advantages.
- For stacks, learn postfix conversion and evaluation. Also learn parenthesis matching. This will help you master stacks. 中缀表达式-->后缀表达式(括号匹配),后缀表达式计算,先进后出的特性
- For queues, you should try to do some multithreading programming.
这整章内容是我学的比较吃力的,同时也是很重要的内容:
栈是仅限在表尾进行插入和删除的线性表,允许插入和删除的一端叫top(栈顶)--下标为0的一端,也称作LIFO结构,像子弹枪哈哈哈这个书上看到的比喻很赞,也让我很好理解出栈次序。
插入(push)和删除(pop)就是改变top指针,将新元素赋值给栈顶空间/将删除元素赋值给e
缺点是:事先必须确定数组储存空间大小--->一个数组存储两个栈(像合租房子),它们在数组两端,当top1+1=top2的时候栈满了,不会溢出。这样的pop只需要判断是栈1还是栈2,stackNumber。书中说使用这种数据结构的时候,是在两个栈需求有相反关系的时候,比如炒股。不相同数据类型的栈,不要用这种方法。
应用:递归--调用自己的函数。复习java的时候也看了,迭代用循环结构,递归用选择结构。
队列是只允许一端进行插入,另一端进行删除的线性表。FIFO结构,就像平时生活中的排队。插入在队尾,删除在队头。
引入两个指针,front和rear,队头不一定是下标为0 ---- 防止假溢出,循环队列,也就是首尾相连。但是front=rear的时候既有可能是队满了,也有可能是空。--用空闲元素解决,循环队列
5. Trees 树
- If you did a proper work with linked lists, trees should feel a little natural.
- Learn to implement a binary tree (insert, delete, search).
- Know the basic properties of a tree.
- Learn at least one self-balancing tree (AVL, Splay, Red-Black).
- I like a lot the Trie data structure. It has some pretty nice applications.
- Another data structure used a lot is the heap.
- Learn Breadth First Search and Depth First Search.
唯一的root和不相交的sub-tree。离散数学里面这部分的内容当时也学得不错~包括Breadth First Search and Depth First Search
basic properties:degree是sub-tree的数量,树的degree是树中结点degree的最大值。level--树中结点最大层次就是depth。
存储结构:孩子双亲表示法,兄弟双亲表示法。。。等等
二叉树:很重要的内容,斜树(线性表也可以理解为树的一种特殊结构),满二叉树,完全二叉树(没有空档编号),以及二叉树的五个性质
三种遍历:前序遍历,中序遍历,后序遍历(重要的内容)
线索二叉树相当于把一棵二叉树转变成了一个双向链表,将二叉链表中的空指针改为指向前驱或后继的线索--->为了区分,加入ltag和rtag(0或1),e.g.知道是左孩子还是前驱
应用:赫夫曼编码
树还有非常非常多值得挖掘学习的地方,以后我也会加深学习~
- Hashmap is a really useful data structure.
- Learn how to use them and how to implement one (so learn how to do a neat hashing function).
7. Graphs 图
- Learn what is a graph and how to implement them with a matrices and lists.
- Learn how to use them and how to implement one (so learn how to do a neat hashing function).
- Learn how to find shortest path in a graph.
- Implement DFS and BFS.
这部分内容也是大二离散数学和大三运筹学的内容,包括关键路径、最小生成树等等,当时学得也比较不错,现在来巩固一下~ 首先巩固的就是各种各样的术语
寻找最短路径在毕业设计的时候就要用到了,选择多个目的地怎么实现最优路径达到价钱最少呢?
深度优先遍历,广度优先遍历
最小生成树最有名的两个算法:prim算法和kruskal算法
最短路径也有两个有名的算法:dijkstra算法和floyd算法
Dijkstra算法算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径。主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止。而Floyd-Warshall算法是解决任意两点间的最短路径的一种算法,可以正确处理有向图或负权的最短路径问题,同时也被用于计算有向图的传递闭包。
8-10. Algorithms
- As I mentioned before, learn sorting and searching algorithms.
- Learn Big O notation.
- Search: MergeSort, QuickSort, HeapSort.
- Diskstra. You won't use this, but it will give you a better understanding of graphs.
- Array data structure and Sparse array
- Linked list and Doubly linked list
- Stack (abstract data type) and Queue (abstract data type)
and Double-ended queue - Binary tree and Treap
- Red–black tree
- Heap (data structure)
- String (computer science) and Trie string这个部分主要讲了kmp算法以及其改进。针对string的函数的原理。http://www.tuicool.com/articles/e2Qbyyf
- B tree and B+ tree
- Graph (abstract data type)
- Hash table and Associative array