通用程序算法和数据结构

In this article, I am going to walk you through the concepts of the common Data Structures that every student, colleague working with computers should be aware of. Data Structure forms an integral part of any system or database design. It is a very interesting and intuitive concept that you can apply anywhere. Through this article, I aim to introduce the beginners to the concepts of Data Structures and brush up the same for colleagues who have already been associated with the industry for years. This will also help you understand some database concepts more easily once you have a grasp over these concepts.

在本文中,我将带您了解通用数据结构的概念,每个使用计算机的学生和同事都应该了解这些概念。 数据结构构成任何系统或数据库设计的组成部分。 这是一个非常有趣且直观的概念,您可以将其应用于任何地方。 通过这篇文章,我旨在向初学者介绍数据结构的概念,并为已经与该行业联系多年的同事们提炼它们。 一旦掌握了这些概念,这也将帮助您更轻松地理解一些数据库概念。

In this article, I am going to cover the most important and frequently used Data Structures in day-to-day life of a software developer. Please note other data structures might not be covered in this article and I will explain those in some other article.

在本文中,我将介绍软件开发人员日常工作中最重要和最常用的数据结构。 请注意,本文可能未涵盖其他数据结构,我将在其他一些文章中进行解释。

  1. Arrays 数组
  2. Linked Lists 链表
  3. Stacks 堆栈
  4. Queues Queue列

Let us now begin understanding these, one by one.

现在让我们开始一个一个地理解这些。

数组 (Arrays)

An array is a collection of elements that are stored at adjacent memory locations. These are structures that can hold data for the same data type and are fixed in length. Be it an array of integers, strings, or even an array of array. These arrays have indexes which means they can be accessed randomly by providing the index of the position. Each of the elements in the array is stored in the memory with a specific address that can be used to retrieve the element back. The last element in an array is always NULL.

数组是存储在相邻内存位置的元素的集合。 这些结构可以保存相同数据类型的数据,并且长度固定。 可以是整数,字符串或什至是数组的数组。 这些数组具有索引,这意味着可以通过提供位置索引来随机访问它们。 数组中的每个元素都有一个特定的地址存储在内存中,该地址可用于取回元素。 数组中的最后一个元素始终为NULL

Figure 1 – Data Structures – Arrays

图1 –数据结构–数组

Considering an analogy, you may think of a multi-story building as an array. In that building, all the floors have the same floor plan (same data type) and your friend might reside on the second floor (index = 2).

考虑一个类比,您可能会将多层建筑物视为一个数组。 在该建筑物中,所有楼层都具有相同的楼层平面图( 相同的数据类型 ),并且您的朋友可能位于第二层(索引= 2)。

Figure 2 – Array Analogy by using a building (Source)

图2 –使用建筑物进行数组类比( 来源 )

Basically, we can perform the following operations on an array.

基本上,我们可以对数组执行以下操作。

  • Traverse – Navigate through the elements in the array and display each of them 遍历 –浏览数组中的元素并显示每个元素
  • Search – We can also search for a specific element by providing the index of the element 搜索 –我们还可以通过提供元素的索引来搜索特定元素
  • Update – Values at certain specified indexes can also be updated 更新 –某些指定索引处的值也可以更新

A limitation of an array is that we cannot insert or remove elements from the array dynamically. This is because the arrays are mostly fixed in size. If you need to add an element to the array, then you might need to create a new array with length greater than that of the current one and then copy the elements from one array to the other. Same goes for deletion as well, you need to create a new array with reduced size.

数组的局限性在于我们不能动态地从数组中插入或删除元素。 这是因为数组的大小通常是固定的。 如果需要向数组添加元素,则可能需要创建一个长度大于当前数组长度的新数组,然后将元素从一个数组复制到另一个数组。 删除同样适用,您需要创建一个尺寸减小的新阵列。

Arrays are mostly used to build or develop other complex data structures such as heaps, hash tables, array lists, etc.

数组主要用于构建或开发其他复杂的数据结构,例如堆,哈希表,数组列表等。

链表 (Linked Lists)

Linked Lists are sequential data structures which are connected to one another in a linear fashion. For this reason, you cannot access a linked list randomly, but only sequential access is possible. There are three types of linked lists. All the elements in a linked list are known as nodes. Each node comprises of a key and a pointer to the next node. The Head and Tail are the starting and ending nodes of the linked list, respectively.

链表是顺序数据结构,它们以线性方式相互连接。 因此,您不能随机访问链接列表,而只能进行顺序访问。 链接列表有三种类型。 链表中的所有元素都称为节点。 每个节点都包含一个密钥和一个指向下一个节点的指针分别是链表的开始和结束节点。

Figure 3 – Data Structures – Linked Lists

图3 –数据结构–链接列表

  • Singly Linked Lists – In these, we can only navigate only forward
  • 单链接列表 –在这些列表中 ,我们只能向前浏览
  • Doubly Linked Lists – Here, we can traverse both forward and reverse. This is done by an additional pointer known as the 双链表 –在这里,我们可以遍历正向和反向。 这是由被称为previous 先前的其他指针完成
  • Circular Linked Lists – In this case, the next pointer of the tail is connected to the head and the previous pointer of the head is connected to the tail of the list 循环链接列表 –在这种情况下,尾部的下一个指针连接到头部,头的前一个指针连接到列表的尾部

The following operations can be performed on a linked list.

可以在链接列表上执行以下操作。

  • Search – You can find the first element with a key 搜索 –您可以找到带有键kk
  • Insert – You can insert elements either at the beginning of the list, in the end, or in the middle of the linked list 插入 –您可以在列表的开头,结尾或中间插入元素
  • Delete – Similarly, you can remove elements from either beginning of the list, from the middle, or the end of the list 删除 –同样,您可以从列表的开头,列表的中间或结尾删除元素

An important application of a circular linked list can be seen in Windows while switching between multiple programs using the Alt + Tab keys.

在Windows中可以看到循环链接列表的重要应用,同时使用Alt + Tab键可以在多个程序之间切换。

堆栈 (Stacks)

Stacks are also very commonly used data structures used in most of the major applications around the world. It follows the common acronym LIFO, which means Last In First Out. You can resemble it to something like a stack of plates, so, the one which is kept at the last is taken at the first.

堆栈也是世界上大多数主要应用程序中非常常用的数据结构。 它遵循通用首字母缩写词LIFO ,意思是后进先出。 您可以将其类似于一堆盘子,因此,最后存放的是第一个。

Figure 4 – Stack of plates (Source)

图4 –板叠( 来源 )

There are two prime operations that you can perform on a stack – Push and Pop.

您可以在堆栈上执行两个主要操作-推入和弹出。

  • Push – Add an element to the top of the stack –将元素添加到堆栈顶部
  • Pop – Remove an element from the top of the stack and return it 弹出 -从堆栈顶部删除一个元素并返回

Apart from these two, you can also use the following operations on a stack.

除了这两个以外,您还可以在堆栈上使用以下操作。

  • Peek – It is used to return the top element of the stack without removing or deleting it 窥视 –用于返回堆栈的顶部元素而不删除或删除它
  • isFull – Used to check if the stack is full isFull –用于检查堆栈是否已满
  • isEmpty – Used to check if the stack is empty isEmpty –用于检查堆栈是否为空

The most common applications of stacks are used in implementing function calls in recursive programming. This also gives rise to a very common and frequent error, known as the stack overflow error.

堆栈的最常见应用程序用于在递归编程中实现函数调用。 这也会引起一个非常常见的错误,即堆栈溢出错误。

Queue列 (Queues)

A queue is another data structure that follows FIFO or First In First Out. You can resemble this with a real-life queue and hence the name. It is also a dynamic data structure which means you can only add elements to the end of the queue and remove only from the beginning. Unlike a stack, a queue is open at both ends, and thus it allows the addition of elements at the end of the queue while removal of the items can be done from the beginning of the queue.

队列是遵循FIFO或先进先出的另一种数据结构。 您可以将它与现实生活中的队列和名称类似。 它也是一个动态数据结构,这意味着您只能将元素添加到队列的末尾,而只能从队列的开头删除。 与堆栈不同,队列的两端都是开放的,因此它允许在队列末尾添加元素,同时可以从队列开始处删除项目。

Figure 5 – Example of a real-life queue

图5 –真实队列的示例

The following operations can be performed in a queue.

可以在队列中执行以下操作。

Figure 6 – Data Structures – Queue in programming (Source)

图6 –数据结构–编程队列( 源 )

  • Enqueue – Used to add an item to the end of the queue. If the queue is already full, then it will throw an Overflow condition 入队 –用于将项目添加到队列的末尾。 如果队列已满,则将引发溢出条件
  • Dequeue – Used to remove an item from the beginning of the queue. If the queue is empty, then it will throw an Underflow condition 出队 –用于从队列的开头删除项目。 如果队列为空,则将引发下溢条件
  • Front – Used to return the item at the front of the queue –用于返回队列前的项目
  • Rear – Used to return the item at the end of the queue 后方 –用于在队列末尾返回项目

Queues are mostly used while designing multi-threaded applications such that the first thread gets executed first and the last executes at the last. Also, another application would be using priority queues while designing microservice architecture systems. Amazon SQS and Azure Service Bus are examples of a cloud-based message queue system which implements the concept of queues to send and receive messages.

在设计多线程应用程序时,通常使用队列,以便第一个线程首先执行,最后一个线程最后执行。 同样,另一个应用程序在设计微服务体系结构系统时将使用优先级队列。 Amazon SQS和Azure Service Bus是基于云的消息队列系统的示例,该系统实现了队列概念来发送和接收消息。

结论 (Conclusion)

In this article, we have seen how important it is to understand the concepts of the common Data Structures. These concepts will help you when you start designing a new system from scratch or while trying to understand some of the existing data systems. I remember during my days back in college, it was one of the most important topics that we had to learn thoroughly. Yet today, these are one of the most frequently asked questions in any software development interview. I would strongly recommend everyone to have a good understanding of these concepts before appearing for any technical discussion.

在本文中,我们已经了解了理解通用数据结构的概念有多么重要。 当您从头开始设计新系统或尝试了解一些现有数据系统时,这些概念将为您提供帮助。 我记得在上大学的那一天,它是我们必须彻底学习的最重要的主题之一。 时至今日,这些已成为所有软件开发面试中最常见的问题之一。 我强烈建议大家在出现任何技术讨论之前对这些概念有一个很好的了解。

翻译自: https://www.sqlshack.com/understanding-common-data-structures/

通用程序算法和数据结构

通用程序算法和数据结构_了解通用数据结构相关推荐

  1. 通用程序测试软件,得实打印机通用驱动程序系列1

    得实打印机通用驱动程序系列1是一款得实Dascom除DS-9XX.AR-4XX型号外其他系列都能使用的得实打印机通用驱动程序,该驱动是官方通用版本,适用于除DS-9XX.AR-4XX型号外得实所有其他 ...

  2. 四大金刚 数据结构_学习JavaScript数据结构与算法(三):集合

    集合(Set遇新是直朋能到) 说起集合,就想起刚进高中时,数学第一课讲的就是集合.因此在学习集合这种数据结构时,倍感亲切. 集合的基本性质有一条: 集合中元素是不重复的.因为这种性质,所以我们选用了对 ...

  3. 数据结构和算法学多久_重新学习数据结构和算法

    数据结构和算法学多久 为什么? 我记得在我第一次参加计算机科学算法课程时 伊丽莎白市州立大学(ECSU)认为:"我得到了什么 我自己变成了?!". 材料令人生畏,而且(大部分时间) ...

  4. java是什么数据结构_什么是数据结构?

    本篇文章主要来介绍什么是数据结构. 首先让我们来看一张图片: 数据存储于计算机的内存中.内存如上图所示,形似排成 1 列的箱子,1 个箱子里存储 1 个数据. 数据存储于内存时,决定了数据顺序和位置关 ...

  5. 树的结构 数据结构_段树| 数据结构

    树的结构 数据结构 What is a segment tree? 什么是段树? A segment tree is a full binary tree where each node repres ...

  6. 信号放大器数据结构_[11/11]数据结构 二叉树应用(树型信号放大器,file transfer,遍历的非递归实现)...

    树型分布网络信号放大器 森林和二叉树的相互转换 并查集 例题:File transfer #include <iostream> using namespace std; //typede ...

  7. 一般项目中哪里体现了数据结构_优秀程序员都应该学习的数据结构与算法项目(GitHub 开源清单)...

    前言 算法为王. 想学好前端,先练好内功,内功不行,就算招式练的再花哨,终究成不了高手:只有内功深厚者,前端之路才会走得更远. 强烈推荐 GitHub 上值得前端学习的数据结构与算法项目,包含 gif ...

  8. 乐华v56与v59的区别_乐华V59-5键通用程序(通用板)驱动程序

    本压缩数据包含以下文件: 15方屏1024x768 单8位通用程序5键 17宽屏30片双6位屏1440x900通用程序 5键 17方19方1280x1024双8位通用程序 5键 185屏18.5液晶1 ...

  9. 无法创建t的通用数组_创建通用数组的问题

    无法创建t的通用数组 在这篇文章中,我们将介绍一篇全面的文章,其中介绍了创建通用数组的问题. Java编程语言于2004年9月在Java 5.0" Tiger"发行版中添加了泛型. ...

最新文章

  1. vs2012html图片,简单几步 实现vs2010对html5的支持
  2. Android Studio 从安装到 Hello World
  3. [Gamma]Scrum Meeting#5
  4. 阿里8亿加持B端智能化后,本地生活服务更好做了吗?
  5. Vue表格中,对数据进行转换、处理
  6. 日志不说谎--Asp.net的生命周期
  7. keyshot环境素材文件_超赞|15个不翻墙免费可商用矢量素材下载网站推荐
  8. Java使用笔记之stream和sorted使用
  9. CUDA编程入门教程
  10. 【学习笔记】常见的激励函数和损失函数
  11. java sqlserver 图书馆管理系统_基于JAVA+SQLServer的图书馆管理系统.doc
  12. 用opencv压缩图片
  13. Vue 大量数据展示卡顿解决方案(长列表优化)
  14. uniapp swiper waterfall同用 tabbar页面卡顿
  15. moment.js时间操作
  16. 红绿灯的html代码,红绿灯.html
  17. Proteus——测量脉冲频率
  18. 销售宝:ERP软件系统对于企业有什么帮助?
  19. 一个例题:浮动引起元素变成行内块元素-display:inline-block
  20. 两个开关电源可以并联使用吗开关电源有均流功能,只有开关电源有均流功能的才可以并联使用。没有的切记不可并联使用。电工之家百度快照课复制(可以把网址复制到百度搜索栏,不是http网址搜索栏)

热门文章

  1. bottle模板中的替换
  2. Unity 3D 正交相机(Orthographic)
  3. JS:ES6-4 简化对象与箭头函数
  4. react-native相机
  5. 电脑护眼模式_电脑手机护眼小工具
  6. CCF CSP202112-2 序列查询新解
  7. 为什么要从vmware切换到kvm?
  8. 股票市值高好还是低好呢?
  9. python是什么类型的语言
  10. 买的首套房开发商指定的银行是5.88的利率,朋友都说利率有点高,怎样才能省点钱呢?