程序员面试必知的8个数据结构

by Fahim ul Haq

瑞士计算机科学家Niklaus Wirth在1976年写了一本书,名为《算法+数据结构=程序》。

40多年后,这个等式仍然成立。这就是为什么软件工程候选人必须证明他们对数据结构及其应用程序的理解。

几乎所有问题都要求考生表现出对数据结构的深刻理解。无论您刚毕业(从大学还是编程训练营)毕业,还是有数十年的经验都没关系。

有时访谈问题明确提到数据结构,例如“给定二叉树”。其他时候它是隐式的,例如“我们要跟踪与每个作者关联的书籍数量”。

即使您只是想在当前工作中变得更好,学习数据结构也是必不可少的。让我们从了解基础开始。

什么是数据结构?

简而言之,数据结构是一个以特定布局存储数据的容器。这种“布局”使数据结构在某些操作中有效,而在另一些操作中效率低下。您的目标是了解数据结构,以便选择最适合当前问题的数据结构。

为什么我们需要数据结构?

由于数据结构用于以有组织的形式存储数据,并且由于数据是计算机科学中最重要的实体,因此数据结构的真正价值显而易见。

无论您要解决什么问题,都必须以一种或另一种方式处理数据-无论是员工的薪水,股票价格,购物清单还是简单的电话簿。

根据不同的场景,数据需要以特定的格式存储。我们有一些数据结构可以满足我们以不同格式存储数据的需求。

常用数据结构

让我们首先列出最常用的数据结构,然后逐一介绍它们:

  1. 数组

  2. 堆栈

  3. 队列

  4. 链表

  5. 前缀树

  6. 哈希表

数组

数组是最简单,使用最广泛的数据结构。其他数据结构(如堆栈和队列)是从数组派生的。

这是大小为4的简单数组的图像,其中包含元素(1、2、3和4)。

每个数据元素都被分配一个称为Index的正数值它对应于该项在数组中的位置。大多数语言将数组的起始索引定义为0。

以下是两种类型的数组:

  • 一维数组(如上所示)

  • 多维数组(数组中的数组)

阵列的基本操作

  • 插入—在给定索引处插入元素

  • Get —返回给定索引处的元素

  • 删除-删除给定索引处的元素

  • Size —获取数组中元素的总数

Array面试常见问题

  • 查找数组的第二个最小元素

  • 数组中的第一个非重复整数

  • 合并两个排序的数组

  • 重新排列数组中的正值和负值

堆栈

我们都熟悉著名的“撤消”选项,该选项几乎存在于每个应用程序中。有没有想过它是如何工作的?想法是:您将工作的先前状态(限于特定数量)存储在内存中,顺序是最后一个出现在最前面。这不能仅仅通过使用数组来完成。这就是堆栈派上用场的地方。

堆叠的真实示例可能是一堆以垂直顺序放置的书。为了获得位于中间位置的书,您需要删除所有放在其顶部的书。这就是LIFO(后进先出)方法的工作方式。

这是包含三个数据元素(1、2和3)的堆栈图像,其中3在顶部,并且将首先删除:

堆栈的基本操作:

  • 推入—在顶部插入一个元素

  • Pop —从堆栈中移除后返回顶部元素

  • isEmpty —如果堆栈为空,则返回true

  • Top —返回顶部元素,而不从堆栈中移除

堆栈采访常见问题

  • 使用堆栈评估后缀表达式

  • 对堆栈中的值进行排序

  • 检查表达式中的平衡括号

队列

与Stack类似,Queue是另一个线性数据结构,该结构以顺序方式存储元素。堆栈和队列之间唯一的显着区别是,队列使用FIFO 方法代替了LIFO方法,该方法是先进先出的缩写。

排队的一个完美的现实例子:排队的人在售票亭等车。如果有新人来,他们将从头开始而不是从一开始就加入队伍—站在最前面的人将是第一个获得票证并因此离开队伍的人。

这是包含四个数据元素(1、2、3和4)的Queue图像,其中1在顶部,并且将首先删除:

队列的基本操作

  • Enqueue()—将元素插入队列的末尾

  • Dequeue()-从队列的开头删除一个元素

  • isEmpty()—如果队列为空,则返回true

  • Top()—返回队列的第一个元素

排队面试常见问题

  • 使用队列实现堆栈

  • 反转队列的前k个元素

  • 使用队列生成从1到n的二进制数

链表

链表是另一种重要的线性数据结构,乍一看可能与数组相似,但在内存分配,内部结构以及插入和删除的基本操作上有所不同。

链表就像一个节点链,其中每个节点都包含诸如数据之类的信息以及指向链中后续节点的指针。有一个头指针,它指向链接列表的第一个元素,如果列表为空,则仅指向null或不指向任何内容。

链接列表用于实现文件系统,哈希表和邻接列表。

这是链表内部结构的直观表示:

以下是链接列表的类型:

  • 单链表(单向)

  • 双链表(双向)

链表的基本操作:

  • InsertAtEnd —在链表的末尾插入给定元素

  • InsertAtHead —在链接列表的开头/开头插入给定元素

  • 删除-从链接列表中删除给定元素

  • DeleteAtHead —删除链接列表的第一个元素

  • 搜索-从链接列表中返回给定的元素

  • isEmpty —如果链接列表为空,则返回true

常见问题链表面试问题

  • 反向链接列表

  • 检测链表中的循环

  • 从链表的末尾返回第N个节点

  • 从链接列表中删除重复项

图(Graph)

图是一组以网络形式相互连接的节点。节点也称为顶点。阿对(x,y)的被称为边缘这表明顶点X被连接到顶点ÿ。一条边可能包含权重/成本,表示从顶点x到y遍历需要多少成本

图的类型:

  • 无向图

  • 有向图

在编程语言中,图形可以使用两种形式表示:

  • 邻接矩阵

  • 邻接表

常见的图遍历算法:

  • 广度优先搜索

  • 深度优先搜索

Graph面试常见问题

  • 实施广度和深度优先搜索

  • 检查图是否为树

  • 计算图中的边数

  • 查找两个顶点之间的最短路径

树(Tree)

树是由顶点(节点)和连接它们的边组成的分层数据结构。树类似于图,但是区别图与树的关键是树中不能存在循环。

树在人工智能和复杂算法中被广泛使用,以提供有效的存储机制来解决问题。

这是一棵简单的树的图像,以及树数据结构中使用的基本术语:

以下是树的类型:

  • 一元树

  • 平衡树

  • 二叉树

  • 二进制搜索树

  • AVL树

  • 红黑树

  • 2–3树

其中,二叉树和二叉搜索树是最常用的树。

树面试常见问题

  • 查找二叉树的高度

  • 在二叉搜索树中找到第k个最大值

  • 查找距根“ k”距离的节点

  • 在二叉树中查找给定节点的祖先

前缀树(Trie)

Trie,也称为“前缀树”,是一种类似树的数据结构,被证明对于解决与字符串有关的问题非常有效。它提供了快速的检索功能,主要用于在字典中搜索单词,在搜索引擎中提供自动建议,甚至用于IP路由。

这是Trie中三个单词“ top”,“ thus”和“ their”的存储方式的说明:

单词以从上到下的方式存储,其中绿色节点“ p”,“ s”和“ r”分别表示“ top”,“ thus”和“ their”的结尾。

特里采访常见问题:

  • 计算Trie中的单词总数

  • 打印所有存储在Trie中的单词

  • 使用Trie排序数组的元素

  • 使用Trie从字典中套用单词

  • 建立T9字典

哈希表

散列是用于唯一标识对象并将每个对象存储在一些预先计算的唯一索引(称为“键”)的过程。因此,对象以“键值”对的形式存储,此类项目的集合称为“字典”。可以使用该键搜索每个对象。基于哈希的数据结构不同,但是最常用的数据结构是哈希表

哈希表通常使用数组来实现。

哈希数据结构的性能取决于以下三个因素:

  • 散列函数

  • 哈希表的大小

  • 碰撞处理方法

这是散列如何在数组中映射的说明。该数组的索引是通过哈希函数计算的。

散列面试常见问题

  • 在数组中查找对称对

  • 追踪完整的旅程

  • 查找一个数组是否是另一个数组的子集

  • 检查给定数组是否不相交

以上是进入编码面试之前您绝对应该知道的前八个数据结构。

【英语能力提升】英文原文:

Niklaus Wirth, a Swiss computer scientist, wrote a book in 1976 titled Algorithms + Data Structures = Programs.

40+ years later, that equation still holds true. That’s why software engineering candidates have to demonstrate their understanding of data structures along with their applications.

Almost all problems require the candidate to demonstrate a deep understanding of data structures. It doesn’t matter whether you have just graduated (from a university or coding bootcamp), or you have decades of experience.

Sometimes interview questions explicitly mention a data structure, for example, “given a binary tree.” Other times it’s implicit, like “we want to track the number of books associated with each author.”

Learning data structures is essential even if you’re just trying to get better at your current job. Let’s start with understanding the basics.

What is a Data Structure?

Simply put, a data structure is a container that stores data in a specific layout. This “layout” allows a data structure to be efficient in some operations and inefficient in others. Your goal is to understand data structures so that you can pick the data structure that’s most optimal for the problem at hand.

Why do we need Data Structures?

As data structures are used to store data in an organized form, and since data is the most crucial entity in computer science, the true worth of data structures is clear.

No matter what problem are you solving, in one way or another you have to deal with data — whether it’s an employee’s salary, stock prices, a grocery list, or even a simple telephone directory.

Based on different scenarios, data needs to be stored in a specific format. We have a handful of data structures that cover our need to store data in different formats.

Commonly used Data Structures

Let’s first list the most commonly used data structures, and then we’ll cover them one by one:

  1. Arrays

  2. Stacks

  3. Queues

  4. Linked Lists

  5. Trees

  6. Graphs

  7. Tries (they are effectively trees, but it’s still good to call them out separately).

  8. Hash Tables

Arrays

An array is the simplest and most widely used data structure. Other data structures like stacks and queues are derived from arrays.

Here’s an image of a simple array of size 4, containing elements (1, 2, 3 and 4).

Each data element is assigned a positive numerical value called the Indexwhich corresponds to the position of that item in the array. The majority of languages define the starting index of the array as 0.

The following are the two types of arrays:

  • One-dimensional arrays (as shown above)

  • Multi-dimensional arrays (arrays within arrays)

Basic Operations on Arrays

  • Insert — Inserts an element at a given index

  • Get — Returns the element at a given index

  • Delete — Deletes an element at a given index

  • Size — Gets the total number of elements in an array

Commonly asked Array interview questions

  • Find the second minimum element of an array

  • First non-repeating integers in an array

  • Merge two sorted arrays

  • Rearrange positive and negative values in an array

Stacks

We are all familiar with the famous Undo option, which is present in almost every application. Ever wondered how it works? The idea: you store the previous states of your work (which are limited to a specific number) in the memory in such an order that the last one appears first. This can’t be done just by using arrays. That is where the Stack comes in handy.

A real-life example of Stack could be a pile of books placed in a vertical order. In order to get the book that’s somewhere in the middle, you will need to remove all the books placed on top of it. This is how the LIFO (Last In First Out) method works.

Here’s an image of stack containing three data elements (1, 2 and 3), where 3 is at the top and will be removed first:

Basic operations of stack:

  • Push — Inserts an element at the top

  • Pop — Returns the top element after removing from the stack

  • isEmpty — Returns true if the stack is empty

  • Top — Returns the top element without removing from the stack

Commonly asked Stack interview questions

  • Evaluate postfix expression using a stack

  • Sort values in a stack

  • Check balanced parentheses in an expression

Queues

Similar to Stack, Queue is another linear data structure that stores the element in a sequential manner. The only significant difference between Stack and Queue is that instead of using the LIFO method, Queue implements the FIFO method, which is short for First in First Out.

A perfect real-life example of Queue: a line of people waiting at a ticket booth. If a new person comes, they will join the line from the end, not from the start — and the person standing at the front will be the first to get the ticket and hence leave the line.

Here’s an image of Queue containing four data elements (1, 2, 3 and 4), where 1 is at the top and will be removed first:

Basic operations of Queue

  • Enqueue() — Inserts an element to the end of the queue

  • Dequeue() — Removes an element from the start of the queue

  • isEmpty() — Returns true if the queue is empty

  • Top() — Returns the first element of the queue

Commonly asked Queue interview questions

  • Implement stack using a queue

  • Reverse first k elements of a queue

  • Generate binary numbers from 1 to n using a queue

Linked List

A linked list is another important linear data structure which might look similar to arrays at first but differs in memory allocation, internal structure and how basic operations of insertion and deletion are carried out.

A linked list is like a chain of nodes, where each node contains information like data and a pointer to the succeeding node in the chain. There’s a head pointer, which points to the first element of the linked list, and if the list is empty then it simply points to null or nothing.

Linked lists are used to implement file systems, hash tables, and adjacency lists.

Here’s a visual representation of the internal structure of a linked list:

Following are the types of linked lists:

  • Singly Linked List (Unidirectional)

  • Doubly Linked List (Bi-directional)

Basic operations of Linked List:

  • InsertAtEnd — Inserts a given element at the end of the linked list

  • InsertAtHead — Inserts a given element at the start/head of the linked list

  • Delete — Deletes a given element from the linked list

  • DeleteAtHead — Deletes the first element of the linked list

  • Search — Returns the given element from a linked list

  • isEmpty — Returns true if the linked list is empty

Commonly asked Linked List interview questions

  • Reverse a linked list

  • Detect loop in a linked list

  • Return Nth node from the end in a linked list

  • Remove duplicates from a linked list

Graphs

A graph is a set of nodes that are connected to each other in the form of a network. Nodes are also called vertices. A pair(x,y) is called an edge, which indicates that vertex x is connected to vertex y. An edge may contain weight/cost, showing how much cost is required to traverse from vertex x to y.

Types of Graphs:

  • Undirected Graph

  • Directed Graph

In a programming language, graphs can be represented using two forms:

  • Adjacency Matrix

  • Adjacency List

Common graph traversing algorithms:

  • Breadth First Search

  • Depth First Search

Commonly asked Graph interview questions

  • Implement Breadth and Depth First Search

  • Check if a graph is a tree or not

  • Count the number of edges in a graph

  • Find the shortest path between two vertices

Trees

A tree is a hierarchical data structure consisting of vertices (nodes) and edges that connect them. Trees are similar to graphs, but the key point that differentiates a tree from the graph is that a cycle cannot exist in a tree.

Trees are extensively used in Artificial Intelligence and complex algorithms to provide an efficient storage mechanism for problem-solving.

Here’s an image of a simple tree, and basic terminologies used in tree data structure:

The following are the types of trees:

  • N-ary Tree

  • Balanced Tree

  • Binary Tree

  • Binary Search Tree

  • AVL Tree

  • Red Black Tree

  • 2–3 Tree

Out of the above, Binary Tree and Binary Search Tree are the most commonly used trees.

Commonly asked Tree interview questions

  • Find the height of a binary tree

  • Find kth maximum value in a binary search tree

  • Find nodes at “k” distance from the root

  • Find ancestors of a given node in a binary tree

Trie

Trie, which is also known as “Prefix Trees”, is a tree-like data structure which proves to be quite efficient for solving problems related to strings. It provides fast retrieval, and is mostly used for searching words in a dictionary, providing auto suggestions in a search engine, and even for IP routing.

Here’s an illustration of how three words “top”, “thus”, and “their” are stored in Trie:

The words are stored in the top to the bottom manner where green colored nodes “p”, “s” and “r” indicates the end of “top”, “thus”, and “their” respectively.

Commonly asked Trie interview questions:

  • Count total number of words in Trie

  • Print all words stored in Trie

  • Sort elements of an array using Trie

  • Form words from a dictionary using Trie

  • Build a T9 dictionary

Hash Table

Hashing is a process used to uniquely identify objects and store each object at some pre-calculated unique index called its “key.” So, the object is stored in the form of a “key-value” pair, and the collection of such items is called a “dictionary.” Each object can be searched using that key. There are different data structures based on hashing, but the most commonly used data structure is the hash table.

Hash tables are generally implemented using arrays.

The performance of hashing data structure depends upon these three factors:

  • Hash Function

  • Size of the Hash Table

  • Collision Handling Method

Here’s an illustration of how the hash is mapped in an array. The index of this array is calculated through a Hash Function.

Commonly asked Hashing interview questions

  • Find symmetric pairs in an array

  • Trace complete path of a journey

  • Find if an array is a subset of another array

  • Check if given arrays are disjoint

The above are the top eight data structures that you should definitely know before walking into a coding interview.

https://www.freecodecamp.org/news/the-top-data-structures-you-should-know-for-your-next-coding-interview-36af0831f5e3/

最后,附上数据结构与算法的基本知识点:

数据结构与算法

数据结构

什么是数据结构?逻辑、存储、运算

  • 数据(data)

    • 数据(data)是事实或观察的结果,是对客观事物的逻辑归纳,是用于表示客观事物的未经加工的原始素材。数据是对客观事物的性质、状态以及相互关系等进行记载的物理符号或这些物理符号的组合。它是可识别的、抽象的符号。
      数据可以是连续的值,比如声音、图像,称为模拟数据;也可以是离散的,如符号、文字,称为数字数据。
      在计算机科学中,数据是指所有能输入计算机并被计算机程序处理的符号的介质的总称,是用于输入电子计算机进行处理,具有一定意义的数字、字母、符号和模拟量等的通称。计算机存储和处理的对象十分广泛,表示这些对象的数据也随之变得越来越复杂。在计算机系统中,数据以二进制信息单元0、1的形式表示。

    • 抽象数据类型

    • 问题建模

  • 结构(structure)

  • 数据结构(data structure)

    • 数据结构是计算机存储、组织数据的方式。数据结构是指相互之间存在一种或多种特定关系的数据元素的集合。通常情况下,精心选择的数据结构可以带来更高的运行或者存储效率。数据结构往往同高效的检索算法和索引技术有关。

    • 数据结构(data structure)是带有结构特性的数据元素的集合,它研究的是数据的逻辑结构和数据的物理结构以及它们之间的相互关系,并对这种结构定义相适应的运算,设计出相应的算法,并确保经过这些运算以后所得到的新结构仍保持原来的结构类型。简而言之,数据结构是相互之间存在一种或多种特定关系的数据元素的集合,即带“结构”的数据元素的集合。“结构”就是指数据元素之间存在的关系,分为逻辑结构和存储结构。[2]

    • 数据的逻辑结构和物理结构是数据结构的两个密切相关的方面,同一逻辑结构可以对应不同的存储结构。算法的设计取决于数据的逻辑结构,而算法的实现依赖于指定的存储结构。[2]

    • 数据结构的研究内容是构造复杂软件系统的基础,它的核心技术是分解与抽象。通过分解可以划分出数据的3个层次;再通过抽象,舍弃数据元素的具体内容,就得到逻辑结构。类似地,通过分解将处理要求划分成各种功能,再通过抽象舍弃实现细节,就得到运算的定义。上述两个方面的结合可以将问题变换为数据结构。这是一个从具体(即具体问题)到抽象(即数据结构)的过程。然后,通过增加对实现细节的考虑进一步得到存储结构和实现运算,从而完成设计任务。这是一个从抽象(即数据结构)到具体(即具体实现)的过程。[3]

  • 数据结构研究对象

    • 数据结构研究的内容:就是如何按一定的逻辑结构,把数据组织起来,并选择适当的存储表示方法把逻辑结构组织好的数据存储到计算机的存储器里。算法研究的目的是为了更有效的处理数据,提高数据运算效率。数据的运算是定义在数据的逻辑结构上,但运算的具体实现要在存储结构上进行。一般有以下几种常用运算:[3]
      (1)检索。检索就是在数据结构里查找满足一定条件的节点。一般是给定一个某字段的值,找具有该字段值的节点。[3]
      (2)插入。往数据结构中增加新的节点。[3]
      (3)删除。把指定的结点从数据结构中去掉。[3]
      (4)更新。改变指定节点的一个或多个字段的值。[3]
      (5)排序。把节点按某种指定的顺序重新排列。例如递增或递减。[3]

  • 数据的结构有哪些类型?

    • 数据的逻辑结构在计算机存储空间中的存放形式称为数据的物理结构(也称为存储结构)。一般来说,一种数据结构的逻辑结构根据需要可以表示成多种存储结构,常用的存储结构有顺序存储、链式存储、索引存储和哈希存储等。

    • 指数据的逻辑结构在计算机存储空间的存放形式。[1]

    • 数据的物理结构是数据结构在计算机中的表示(又称映像),它包括数据元素的机内表示和关系的机内表示。由于具体实现的方法有顺序、链接、索引、散列等多种,所以,一种数据结构可表示成一种或多种存储结构。[1]

    • 数据元素的机内表示(映像方法):用二进制位(bit)的位串表示数据元素。通常称这种位串为节点(node)。当数据元素有若干个数据项组成时,位串中与各个数据项对应的子位串称为数据域(data field)。因此,节点是数据元素的机内表示(或机内映像)。[1]

    • 关系的机内表示(映像方法):数据元素之间的关系的机内表示可以分为顺序映像和非顺序映像,常用两种存储结构:顺序存储结构和链式存储结构。顺序映像借助元素在存储器中的相对位置来表示数据元素之间的逻辑关系。非顺序映像借助指示元素存储位置的指针(pointer)来表示数据元素之间的逻辑关系。[1]

    • 指反映数据元素之间的逻辑关系的数据结构,其中的逻辑关系是指数据元素之间的前后间关系,而与他们在计算机中的存储位置无关。逻辑结构包括:[1]

    • 1.集合:数据结构中的元素之间除了“同属一个集合” 的相互关系外,别无其他关系;[1]

    • 2.线性结构:数据结构中的元素存在一对一的相互关系;[1]

    • 3.树形结构:数据结构中的元素存在一对多的相互关系;[1]

    • 4.图形结构:数据结构中的元素存在多对多的相互关系。[1]

    • 数据的逻辑结构

    • 数据的物理结构

    • 数据存储结构

常用的数据结构有哪些?

  • 数组(Array)

    • 0阶张量就是标量,也就是程序中的变量or常量。

    • 1阶张量就是向量,也就一维数组。

    • 2阶张量就是矩阵,也就二维数组。

    • 3阶张量就是三维数组。

    • N阶张量就是N维数组。

    • 数组是一种聚合数据类型,它是将具有相同类型的若干变量有序地组织在一起的集合。数组可以说是最基本的数据结构,在各种编程语言中都有对应。一个数组可以分解为多个数组元素,按照数据元素的类型,数组可以分为整型数组、字符型数组、浮点型数组、指针数组和结构数组等。数组还可以有一维、二维、三维、。。。、N维等表现形式。

    • 从张量角度来看数组

  • 栈( Stack)

    • 栈是一种特殊的线性表,它只能在一个表的一个固定端进行数据结点的插入和删除操作。栈按照后进先出的原则来存储数据,也就是说,先插入的数据将被压入栈底,最后插入的数据在栈顶,读出数据时,从栈顶开始逐个读出。栈在汇编语言程序中,经常用于重要数据的现场保护。栈中没有数据时,称为空栈。

  • 队列(Queue)

    • 队列和栈类似,也是一种特殊的线性表。和栈不同的是,队列只允许在表的一端进行插入操作,而在另一端进行删除操作。一般来说,进行插入操作的一端称为队尾,进行删除操作的一端称为队头。队列中没有元素时,称为空队列。

  • 链表( Linked List)

    • 链表是一种数据元素按照链式存储结构进行存储的数据结构,这种存储结构具有在物理上存在非连续的特点。链表由一系列数据结点构成,每个数据结点包括数据域和指针域两部分。其中,指针域保存了数据结构中下一个元素存放的地址。链表结构中数据元素的逻辑顺序是通过链表中的指针链接次序来实现的。

  • 树( Tree)

    • 树是典型的非线性结构,它是包括,2个结点的有穷集合K。在树结构中,有且仅有一个根结点,该结点没有前驱结点。在树结构中的其他结点都有且仅有一个前驱结点,而且可以有两个后继结点,m≥0。

  • 图(Graph)

    • 图是另一种非线性数据结构。在图结构中,数据结点一般称为顶点,而边是顶点的有序偶对。如果两个顶点之间存在一条边,那么就表示这两个顶点具有相邻关系。

  • 堆(Heap)

    • 堆是一种特殊的树形数据结构,一般讨论的堆都是二叉堆。堆的特点是根结点的值是所有结点中最小的或者最大的,并且根结点的两个子树也是一个堆结构。

  • 散列表(Hash)

    • 散列表源自于散列函数(Hash function),其思想是如果在结构中存在关键字和T相等的记录,那么必定在F(T)的存储位置可以找到该记录,这样就可以不用进行比较操作而直接取得所查记录。

  • 跳表

    • redis zset

数据结构的分类(按照数据的逻辑结构)

  • 线性结构

    • 线性表

    • 队列

    • 非空集

    • 有且仅有一个开始结点和一个终端结点

    • 所有结点都最多只有一个直接前趋结点和一个直接后继结点。

    • 特性

    • 例子

  • 非线性结构

    • 树( Tree)

    • 图(Graph)

    • 非线性结构就是表中各个结点之间具有多个对应关系。如果从数据结构的语言来描述,非线性结构应该包括如下几点:[5]

    • 1、非线性结构是非空集。[5]

    • 2、非线性结构的一个结点可能有多个直接前趋结点和多个直接后继结点。[5]

    • 在实际应用中,数组、广义表、树结构和图结构等数据结构都属于非线性结构。[5]

    • 特性

    • 例子

数据结构主要用来解决怎样的问题的?

  • 随着应用程序变得越来越复杂和数据越来越丰富,几百万、几十亿甚至几百亿的数据就会出现,而对这么大对数据进行搜索、插入或者排序等的操作就越来越慢,数据结构就是用来解决这些问题的。

怎么解决的?

  • 按一定的逻辑结构,把数据组织起来,并选择适当的存储表示方法把逻辑结构组织好的数据存储到计算机的存储器里。

算法

什么是算法?

常用的算法有哪些

  • 递归、排序、二分查找、搜索、哈希算法、贪心算法、分治算法、回溯算法、动态规划、字符串匹配算法。

算法的目的

  • 为了更有效的处理数据,提高数据运算效率。数据的运算是定义在数据的逻辑结构上,但运算的具体实现要在存储结构上进行。

算法的应用场景

程序=数据结构+算法

程序设计是什么?

程序设计的艺术

参考资料

  1. 彭军、向毅主编.数据结构预算法:人民邮电出版社,2013年

  2. 石玉强,闫大顺主编.数据结构与算法:中国农业大学出版社,2017.02:第5页

  3. 张青,王囡囡著.工程软件开发技术:北京理工大学出版社,2016.08:第133页

  4. 孟朝霞主编.大学计算基础(第2版):西安电子科技大学出版社,2012.02:第75页

  5. 刘亚东;曲心慧编.C/C++常用算法手册:中国铁道出版社,2017.09:第21页