数据结构及算法 3-先打下一点数据结构的基础

数据结构完全小白,本科两门数据库,选修课数据结构却被我落下了...当时不知道这么重要吖。。

入门选了两本书,普林斯顿的《算法(第四版》和《大话数据结构》,打算好好补补数据结构的知识


列了一下大神们的建议,慢慢攻破~~

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.知道是左孩子还是前驱

应用:赫夫曼编码

树还有非常非常多值得挖掘学习的地方,以后我也会加深学习~


6. Hashmap
  • 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.
  1. Array data structure and Sparse array
  2. Linked list and Doubly linked list
  3. Stack (abstract data type) and Queue (abstract data type) 
    and Double-ended queue
  4. Binary tree and Treap
  5. Red–black tree
  6. Heap (data structure)
  7. String (computer science) and Trie   string这个部分主要讲了kmp算法以及其改进。针对string的函数的原理。http://www.tuicool.com/articles/e2Qbyyf
  8. B tree and B+ tree
  9. Graph (abstract data type)
  10. Hash table and Associative array

顺序存储和链式存储:
顺序表的特点是逻辑上相邻的数据元素,物理存储位置也相邻,并且,顺序表的存储空间需要预先分配。
在链表中逻辑上相邻的数据元素,物理存储位置不一定相邻,它使用指针实现元素之间的逻辑关系。并且,链表的存储空间是动态分配的。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值