Python Data Structure 简明教程
Python - DS Introduction
在此,我们将了解与 Python 编程语言相关的数据结构。
Here, we will understand what is data structure with regards to Python programming language.
Data Structure Overview
数据结构是计算机科学的基本概念,它有助于用任何语言编写高效的程序。Python 是一种高级、解释性、交互性和面向对象的脚本语言,通过使用它,我们可以比其他编程语言更简单地学习数据结构的基础知识。
Data structures are fundamental concepts of computer science which helps is writing efficient programs in any language. Python is a high-level, interpreted, interactive and object-oriented scripting language using which we can study the fundamentals of data structure in a simpler way as compared to other programming languages.
在本章中,我们将学习一些常用数据结构的简短概述,以及它们与一些特定 python 数据类型的关联方式。还有一些特定于 python 的数据结构,被列为另一种类别。
In this chapter we are going to study a short overview of some frequently used data structures in general and how they are related to some specific python data types. There are also some data structures specific to python which is listed as another category.
General Data Structures
计算机科学中的各种数据结构大致分为以下两类。我们将在后续章节中详细讨论以下每种数据结构。
The various data structures in computer science are divided broadly into two categories shown below. We will discuss about each of the below data structures in detail in subsequent chapters.
Liner Data Structures
这些是按顺序存储数据元素的数据结构。
These are the data structures which store the data elements in a sequential manner.
-
Array − It is a sequential arrangement of data elements paired with the index of the data element.
-
Linked List − Each data element contains a link to another element along with the data present in it.
-
Stack − It is a data structure which follows only to specific order of operation. LIFO(last in First Out) or FILO(First in Last Out).
-
Queue − It is similar to Stack but the order of operation is only FIFO(First In First Out).
-
Matrix − It is two dimensional data structure in which the data element is referred by a pair of indices.
Non-Liner Data Structures
这些数据结构中没有数据元素的顺序链接。任何一对或一组数据元素都可以彼此链接,并且可以无需严格的顺序即可访问。
These are the data structures in which there is no sequential linking of data elements. Any pair or group of data elements can be linked to each other and can be accessed without a strict sequence.
-
Binary Tree − It is a data structure where each data element can be connected to maximum two other data elements and it starts with a root node.
-
Heap − It is a special case of Tree data structure where the data in the parent node is either strictly greater than/ equal to the child nodes or strictly less than it’s child nodes.
-
Hash Table − It is a data structure which is made of arrays associated with each other using a hash function. It retrieves values using keys rather than index from a data element.
-
Graph − It is an arrangement of vertices and nodes where some of the nodes are connected to each other through links.
Python Specific Data Structures
这些数据结构特定于 python 语言,它们在 python 环境中存储不同类型的数据和更快处理数据方面提供了更大的灵活性。
These data structures are specific to python language and they give greater flexibility in storing different types of data and faster processing in python environment.
-
List − It is similar to array with the exception that the data elements can be of different data types. You can have both numeric and string data in a python list.
-
Tuple − Tuples are similar to lists but they are immutable which means the values in a tuple cannot be modified they can only be read.
-
Dictionary − The dictionary contains Key-value pairs as its data elements.
在下一章中,我们将学习如何使用 Python 实现这些每个数据结构的详细信息。
In the next chapters we are going to learn the details of how each of these data structures can be implemented using Python.