最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Python中子列表的时间复杂度

SEO心得admin48浏览0评论
本文介绍了Python中子列表的时间复杂度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Python中,当我们从现有列表创建子列表时,时间复杂度是多少?

In Python, what is the time complexity when we create a sublist from an existing list?

例如,这里的data是我们现有列表的名称,而list1是通过对数据进行切片而创建的子列表.

For example, here data is the name of our existing list and list1 is our sublist created by slicing data.

data = [1,2,3,4,5,6..100,...1000....,10^6] list1 = data[101:10^6]

创建list1的运行时间是多少?

What is the running time for creating list1?

Is it O(10^6) i.e.O(N), or O(1)?

推荐答案

在python中获取列表切片为O(M - N)/O(10^6 - 101)

Getting a list slice in python is O(M - N) / O(10^6 - 101)

此处,您可以检查python列表操作的时间复杂度

Here you can check python list operations time complexity

在下面,python列表表示为数组.因此,您可以从一个索引(N)开始迭代,然后再从另一个索引(M)终止

By underneath, python lists are represented like arrays. So, you can iterate starting on some index(N) and stopping in another one(M)

发布评论

评论列表(0)

  1. 暂无评论