chapter_array_and_linkedlist/summary/ #150
Replies: 36 comments 37 replies
-
对 Cache locality 的一个简单解释:Why does cache locality matter for array performance? |
Beta Was this translation helpful? Give feedback.
-
"列表的出现大大提升了数组的实用性,但副作用是会造成部分内存空间浪费",这里的”部分内存空间浪费“是指额外增加的变量如容量、长度、扩容倍数所占的内存吗? |
Beta Was this translation helpful? Give feedback.
-
Q&A看得我云里雾里,不过小结的总结很简练。局部缓存的知识感觉很及时 |
Beta Was this translation helpful? Give feedback.
-
Q&A的最后一条的解释可能不是很完美。在Python中分代码块,如果在同一个代码块里面,则采用统一代码块下的缓存机制。如果属于不同的代码块,则采用小数据池的缓存机制(可以理解成单例的或者全局的字典),而且对于int类型来说,小数据池的缓存范围在-5到256 |
Beta Was this translation helpful? Give feedback.
-
JavaScript中数组没有要求一定要是一样的类型吧?目前在学java感觉两科语言差异还是有蛮多的 |
Beta Was this translation helpful? Give feedback.
-
Hi, K神, |
Beta Was this translation helpful? Give feedback.
-
关于Q&A第一条有些不懂的地方 |
Beta Was this translation helpful? Give feedback.
-
关于Q&A中 在 Python 中初始化 n = [1, 2, 3] 与初始化 m = [2, 1, 3] |
Beta Was this translation helpful? Give feedback.
-
DAY3 |
Beta Was this translation helpful? Give feedback.
-
python中的列表是本文提到的动态数组吗。列表允许存储不同类型的元素,但数组要求相同类型的元素 |
Beta Was this translation helpful? Give feedback.
-
例如,双向队列适合使用链表实现,我们维护一个指针变量始终指向头结点、尾结点,每次插入与删除操作都是 O(1)。 |
Beta Was this translation helpful? Give feedback.
-
对于“初始化列表 res = [0] * self.size() 操作,会导致 res 的每个元素引用相同的地址吗?”这个问题。在python中,正如您之前讲到的列表中每个数字都是一个引用,那您回答中的“初始化二维列表 res = [[0] * self.size()] 多次引用了同一个列表 [0]”是如何发现的呢? |
Beta Was this translation helpful? Give feedback.
-
想问一下:有没有推荐的相应的题目可以用来巩固和拓展的呀 |
Beta Was this translation helpful? Give feedback.
-
对于 “ 初始化列表 res = [0] * self.size() 操作,会导致 res 的每个元素引用相同的地址吗?” 这个问题,运行下面的代码得到每个对象的 id 地址值是同样的,那为什么答案是 "不会引用相同的地址" 呢? res = [0] * 5
for r in res:
print(id(r)) |
Beta Was this translation helpful? Give feedback.
-
two day. |
Beta Was this translation helpful? Give feedback.
-
最后一个Question的 |
Beta Was this translation helpful? Give feedback.
-
打卡,数组和链表两种线性数据结构,都支持数据插入,删除,查询,修改.数组空间长度不可变,空间效率低.链表分散存储的特性使得它可以有效利用空间,但链表的查修操作的时间复杂度为O(n).列表是一种抽象的数据结构概念,可以由数组或者链表形成,它也称为动态数组,可以动态地进行扩容,从而克服了数组长度不可变的缺点 |
Beta Was this translation helpful? Give feedback.
-
2024.5.29直接拿下打卡! 数组和链表这两种数据结构是互补的, 今天才知道列表原来是一种抽象的数据结构概念,是可以动态修改并支持增删查改的数据结构,之前一直和链表混着用。 还有这两种数据结构对于缓存机制有着不同的效益,综合看用数组偏多,实际还是看具体需求,链表更多地应用在数据动态性更强的案例中。 发现不管是力扣题目还是hello算法介绍,在python语言上,都会去使用类别注释,个人觉得还是比较好的习惯,我之前觉得麻烦一直没有使用类别注释,觉得后面需要培养这个习惯。因为python天生支持多态的特性,而其他语言比如java和c++都需要明确指出数据类型,对于代码解释性更强。 |
Beta Was this translation helpful? Give feedback.
-
列表这里可以看一下Java的源码 虽然我算法学的是c++ 哈哈。。使用c++实时模拟一下列表实现,很有用,特别是感受数组扩容与设置报错的过程,对自己的编程逻辑很有好处 |
Beta Was this translation helpful? Give feedback.
-
每一章或者每一小节后面是不是可以给一些相关的算法题(或者力扣题的地址)以供练习更好 |
Beta Was this translation helpful? Give feedback.
-
链表增删的时候没有元素移动
…---- 回复的原邮件 ----
| 发件人 | ***@***.***> |
| 日期 | 2024年09月09日 15:42 |
| 收件人 | ***@***.***> |
| 抄送至 | ***@***.***>***@***.***> |
| 主题 | Re: [krahets/hello-algo] chapter_array_and_linkedlist/summary/ (Discussion #150) |
我有一个疑问,既然链表访问的时间复杂度为O(n),那链表想要增删某一个元素时不是要先访问再增删吗,时间复杂度为O(n);数组增删的时间复杂度为O(n),为什么说链表在增删上效率更高
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
"栈上的数组的大小需要在编译时确定,而堆上的数组的大小可以在运行时动态确定",哪位大哥可以解释下这句话的意思 |
Beta Was this translation helpful? Give feedback.
-
这个还是没太理解,有没有大神讲解一下 |
Beta Was this translation helpful? Give feedback.
-
Q:操作 res = [[0]] * n 生成了一个二维列表,其中每一个 [0] 都是独立的吗? res = [[0]] * 3 # [[0], [0], [0]]
res[0][0] = 1 # [[1], [1], [1]]
res = [[0] * 3] # [[0], [0], [0]]
res[0]= [1] # [[1], [0], [0]] |
Beta Was this translation helpful? Give feedback.
-
“Python 中的数字也被包装为对象,列表中存储的不是数字本身,而是对数字的引用” 长见识了 |
Beta Was this translation helpful? Give feedback.
-
好家伙,python里面变量存储的都是对象的引用,涨知识了,那是不是所有弱类型语言的实现都是和python一样? |
Beta Was this translation helpful? Give feedback.
-
day03 |
Beta Was this translation helpful? Give feedback.
-
在该列表中,所有整数 0 都是同一个对象的引用。这是因为 Python 对小整数(通常是 -5 到 256)采用了缓存池机制,以便最大化对象复用,从而提升性能。 虽然它们指向同一个对象,但我们仍然可以独立修改列表中的每个元素,这是因为 Python 的整数是“不可变对象”。当我们修改某个元素时,实际上是切换为另一个对象的引用,而不是改变原有对象本身。 然而,当列表元素是“可变对象”时(例如列表、字典或类实例等),修改某个元素会直接改变该对象本身,所有引用该对象的元素都会产生相同变化。 |
Beta Was this translation helpful? Give feedback.
-
打卡2025/6/8太精彩了! |
Beta Was this translation helpful? Give feedback.
-
你的邮件我已经收到!
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
chapter_array_and_linkedlist/summary/
一本动画图解、能运行、可提问的数据结构与算法入门书
https://www.hello-algo.com/chapter_array_and_linkedlist/summary/
Beta Was this translation helpful? Give feedback.
All reactions