• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

数组:在连续的内存空间中存储相同类型的元素。

区分:

(1)元素和索引

Index是元素的下标,在数组中的相对位置。

元素

一个

2

指数

0

一个

2

(2)数组访问和数组搜索

访问a[1]是2,搜索2得到索引1。

操作的重要时间复杂度:

(1)访问O(1)

(2)搜索O(N)

(3)插入O(N)

删除O(N)

注意:由于数组存储在连续的内存空间中,需要访问的索引可以通过计算直接访问,所以时间复杂度为O(1);搜索最坏情况需要遍历数组,最坏情况下在数组中插入和删除元素需要移动,所以时间复杂度为O(N)。

特点:适合读而不写,多读少写。

常见操作:

创建一个数组

添加元素

访问元素

修改元素

删除元素

遍历数组

查找元素

数组的长度

数组排序(语言内置的排序方法)

Python3:

30bmb504di12606.png

Java:

【更正】:Java代码中获取数组长度的时间复杂度为O(1)。

zgkphecurst2607.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now