数据结构与算法 算法_数据结构和算法简介

数据结构与算法 算法

数据结构和算法简介 (Introduction to Data Structures and Algorithms)

Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures is about rendering data elements in terms of some relationship, for better organization and storage. For example, we have some data which has, player's name "Virat" and age 26. Here "Virat" is of String data type and 26 is of integer data type.

数据结构是一种收集和组织数据的方式,使我们可以有效地对这些数据执行操作。 数据结构是关于按照某种关系呈现数据元素,以便更好地组织和存储。 例如,我们有一些数据,其玩家名称为 “ Virat”, 年龄为 26 。这里的“ Virat”是String数据类型,而26是整数数据类型。

We can organize this data as a record like Player record, which will have both player's name and age in it. Now we can collect and store player's records in a file or database as a data structure. For example: "Dhoni" 30, "Gambhir" 31, "Sehwag" 33

我们可以将这些数据组织为“ 玩家记录”之类的记录,其中将包含玩家的姓名和年龄。 现在,我们可以收集球员记录并将其作为数据结构存储在文件或数据库中。 例如 :“ Dhoni” 30,“ Gambhir” 31,“ Sehwag” 33

If you are aware of Object Oriented programming concepts, then a class also does the same thing, it collects different type of data under one single entity. The only difference being, data structures provides for techniques to access and manipulate data efficiently.

如果您了解面向对象的编程概念,那么一个class也会做同样的事情,它会在一个实体下收集不同类型的数据。 唯一的区别是,数据结构提供了有效访问和操纵数据的技术。

In simple language, Data Structures are structures programmed to store ordered data, so that various operations can be performed on it easily. It represents the knowledge of data to be organized in memory. It should be designed and implemented in such a way that it reduces the complexity and increases the efficiency.

用简单的语言来说,数据结构是编程为存储有序数据的结构,因此可以轻松地对其执行各种操作。 它表示要在内存中组织的数据知识。 它的设计和实现应降低复杂性并提高效率。

数据结构的基本类型 (Basic types of Data Structures)

As we have discussed above, anything that can store data can be called as a data structure, hence Integer, Float, Boolean, Char etc, all are data structures. They are known as Primitive Data Structures.

正如我们上面讨论的,任何可以存储数据的东西都可以称为数据结构,因此Integer,Float,Boolean,Char等都是数据结构。 它们被称为原始数据结构

Then we also have some complex Data Structures, which are used to store large and connected data. Some example of Abstract Data Structure are :

然后,我们还有一些复杂的数据结构,用于存储大型和连接的数据。 抽象数据结构的一些示例是:

  • Linked List

    链表
  • Tree

  • Graph

    图形
  • Stack, Queue etc.

    堆栈,队列等

All these data structures allow us to perform different operations on data. We select these data structures based on which type of operation is required. We will look into these data structures in more details in our later lessons.

所有这些数据结构使我们能够对数据执行不同的操作。 我们根据所需的操作类型选择这些数据结构。 在后面的课程中,我们将更详细地研究这些数据结构。

数据结构与算法 算法_数据结构和算法简介



The data structures can also be classified on the basis of the following characteristics:

还可以根据以下特征对数据结构进行分类:

Characterstic Description
Linear In Linear data structures,the data items are arranged in a linear sequence. Example: Array
Non-Linear In Non-Linear data structures,the data items are not in sequence. Example: Tree, Graph
Homogeneous In homogeneous data structures,all the elements are of same type. Example: Array
Non-Homogeneous In Non-Homogeneous data structure, the elements may or may not be of the same type. Example: Structures
Static Static data structures are those whose sizes and structures associated memory locations are fixed, at compile time. Example: Array
Dynamic Dynamic structures are those which expands or shrinks depending upon the program need and its execution. Also, their associated memory locations changes. Example: Linked List created using pointers
特征性 描述
线性的 在线性数据结构中,数据项按线性顺序排列。 示例: 数组
非线性的 在非线性数据结构中,数据项不是按顺序排列的。 示例:
同质 在同类数据结构中,所有元素都是同一类型。 示例: 数组
非均质的 在非同类数据结构中,元素可以是或可以不是同一类型。 示例: 结构
静态的 静态数据结构是在编译时其大小和结构与内存位置相关的固定数据结构。 示例: 数组
动态 动态结构是根据程序需要及其执行而扩展或缩小的结构。 同样,它们关联的内存位置也会更改。 示例: 使用指针创建的链表

什么是算法? (What is an Algorithm ?)

An algorithm is a finite set of instructions or logic, written in order, to accomplish a certain predefined task. Algorithm is not the complete code or program, it is just the core logic(solution) of a problem, which can be expressed either as an informal high level description as pseudocode or using a flowchart.

算法是为了完成某些预定义任务而编写的一组有限的指令或逻辑。 算法不是完整的代码或程序,它只是问题的核心逻辑(解决方案),可以将其表达为非正式的高级描述(如伪代码)流程图

Every Algorithm must satisfy the following properties:

每个算法都必须满足以下属性:

  1. Input- There should be 0 or more inputs supplied externally to the algorithm.输入 -应该从外部向算法提供0个或多个输入。
  2. Output- There should be atleast 1 output obtained.输出 -应该至少获得1个输出。
  3. Definiteness- Every step of the algorithm should be clear and well defined.确定性 -算法的每个步骤均应明确且定义明确。
  4. Finiteness- The algorithm should have finite number of steps.有限 -算法应具有有限的步数。
  5. Correctness- Every step of the algorithm must generate a correct output.正确性 -算法的每一步都必须产生正确的输出。

An algorithm is said to be efficient and fast, if it takes less time to execute and consumes less memory space. The performance of an algorithm is measured on the basis of following properties :

如果执行所需的时间较少且占用的存储空间较少,则该算法被称为高效且快速的算法。 算法的性能是基于以下属性来衡量的:

  1. Time Complexity

    时间复杂度
  2. Space Complexity

    空间复杂度

空间复杂度 (Space Complexity)

Its the amount of memory space required by the algorithm, during the course of its execution. Space complexity must be taken seriously for multi-user systems and in situations where limited memory is available.

在执行过程中,算法所需的存储空间量。 对于多用户系统以及在可用内存有限的情况下,必须认真考虑空间复杂性。

An algorithm generally requires space for following components :

算法通常需要以下组件的空间:

  • Instruction Space: Its the space required to store the executable version of the program. This space is fixed, but varies depending upon the number of lines of code in the program.指令空间:存储程序的可执行版本所需的空间。 该空间是固定的,但是根据程序中的代码行数而变化。
  • Data Space: Its the space required to store all the constants and variables(including temporary variables) value.数据空间:存储所有常量和变量(包括临时变量)值所需的空间。
  • Environment Space: Its the space required to store the environment information needed to resume the suspended function.环境空间:存储恢复挂起功能所需的环境信息所需的空间。

To learn about Space Complexity in detail, jump to the Space Complexity tutorial.

要详细了解空间复杂性,请转至空间复杂性教程。

时间复杂度 (Time Complexity)

Time Complexity is a way to represent the amount of time required by the program to run till its completion. It's generally a good practice to try to keep the time required minimum, so that our algorithm completes it's execution in the minimum time possible. We will study about Time Complexity in details in later sections.

时间复杂度是一种表示程序运行直至完成所需时间的方法。 通常,最好将尝试的时间保持在最小,以便我们的算法在尽可能短的时间内完成执行。 我们将在后面的部分中详细研究时间复杂度

NOTE: Before going deep into data structure, you should have a good knowledge of programming either in C or in C++ or Java or Python etc.

注意:在深入研究数据结构之前,您应该具有使用C或C ++或Java或Python等进行编程的丰富知识。

翻译自: https://www.studytonight.com/data-structures/introduction-to-data-structures

数据结构与算法 算法