【Data Structure】 Linear Data Structures---Arrays 线性结构 之 数组

Linear Data Structures

Linear Data Structures are a type of data structure in computer science where data elements are arranged sequentially or linearly. Each element has a previous and next adjacent, except for the first and last elements.

its characteristics

  • Sequential Organization: In linear data structures, date eles are arranged sequentially, one after the other.
    Each ele has a unique predecessor (expect for the first ele) and a unique successor(expect for the last ele ).
  • Order Preservation:
    The order in which elements are added to the data structure is preserved. This means that the first element added will be the first one to be accessed or removed, and the last element added will be the last one to be accessed or removed.
  • Fixed or Dynamic Size: Linear data structures can have either fixed or dynamic sizes. Arrays typically have a fixed size when they are created, while other structures like linked lists, stacks, and queues can dynamically grow or shrink as elements are added or removed.
  • Efficient Access: Accessing elements within a linear data structure is typically efficient. For example, arrays offer constant-time access to elements using their index.

Common linear date structure

Linear data structures are commonly used for organising and manipulating data in a sequential fashion. Some of the most common linear data structures include:

  • Arrays: A collection of elements stored in contiguous memory locations.
  • Linked Lists: A collection of nodes, each containing an element and a reference to the next node.
  • Stacks: A collection of elements with Last-In-First-Out (LIFO) order.
  • Queues: A collection of elements with First-In-First-Out (FIFO) order.

Arrays

A array is a collection of items of some date type in stored at contiguous memory locations

数组 是一组连续存储的具有相同数据类型的数组元素的集合。

在这里插入图片描述

Characteristics of Array Data Structure:
  • Homogeneous Elements: All elements within an array must be of the same data type.
  • Contiguous Memory Allocation: In most programming languages, elements in an array are stored in contiguous (adjacent) memory locations.
  • Zero-Based Indexing: In many programming languages, arrays use zero-based indexing, which means that the first element is accessed with an index of 0, the second with an index of 1, and so on.
  • Random Access: Arrays provide constant-time (O(1)) access to elements. This means that regardless of the size of the array, it takes the same amount of time to access any element based on its index.
  • 相同数据类型
  • 连续存储
  • 索引从0开始
  • 随机访问: 时间复杂度O(1)
Types of arrays:
1-D arrays One-Dimensional Array

This is the simplest form of an array, which consists of a single row of elements, all of the same data type. Elements in a 1D array are accessed using a single index.
在这里插入图片描述

一维数组(最简单最常见的)

2-D arrays Two-Dimensional Array

A two-dimensional array, often referred to as a matrix or 2D array, is an array of arrays. It consists of rows and columns, forming a grid-like structure. Elements in a 2D array are accessed using two indices, one for the row and one for the column.
在这里插入图片描述

二维数组:具有行列。对其元素进行访问需要两个下标,即行数和列数

Multi-Dimensional Array

Arrays can have more than two dimensions, leading to multi-dimensional arrays. These are used when data needs to be organized in a multi-dimensional grid.

在这里插入图片描述

Types of Array operations:
  • Accessing Elements: Accessing a specific element in an array by its index is a constant-time operation. It has a time complexity of O(1).
  • Insertion: Appending an element to the end of an array is usually a constant-time operation, O(1) but insertion at the beginning or any specific index takes O(n) time because it requires shifting all of the elements.
  • Deletion: Same as insertion, deleting the last element is a constant-time operation, O(1) but deletion of element at the beginning or any specific index takes O(n) time because it requires shifting all of the elements.
  • Searching: Linear Search takes O(n) time which is useful for unsorted data and Binary Search takes O(logn) time which is useful for sorted data.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

拾贰_C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值