Colton Idle
12/29/2022, 10:02 PM@elizarov
was talking about here that itd be "harmful" to have it?ephemient
12/29/2022, 10:03 PMLinkedList
. however, by conforming to the List
interface, none of those are realized in Java at allephemient
12/29/2022, 10:03 PMget()
is linear-time, unlike every other list in existenceChris Lee
12/29/2022, 10:04 PMephemient
12/29/2022, 10:05 PMephemient
12/29/2022, 10:07 PMColton Idle
12/29/2022, 10:07 PMephemient
12/29/2022, 10:07 PMColton Idle
12/29/2022, 10:07 PMChris Lee
12/29/2022, 10:07 PMephemient
12/29/2022, 10:08 PMColton Idle
12/29/2022, 10:08 PMChris Lee
12/29/2022, 10:09 PMColton Idle
12/29/2022, 10:14 PMColton Idle
12/29/2022, 10:14 PMephemient
12/29/2022, 10:14 PMephemient
12/29/2022, 10:14 PMColton Idle
12/29/2022, 10:15 PMChris Lee
12/29/2022, 10:15 PMephemient
12/29/2022, 10:15 PMKristian Nedrevold
12/29/2022, 10:16 PMephemient
12/29/2022, 10:17 PMChris Lee
12/29/2022, 10:18 PMephemient
12/29/2022, 10:18 PMChris Lee
12/29/2022, 10:19 PMephemient
12/29/2022, 10:21 PMKristian Nedrevold
12/29/2022, 10:23 PMephemient
12/29/2022, 10:23 PMFrancesc
12/29/2022, 10:56 PMstorage
should be val
in that gistColton Idle
12/29/2022, 10:59 PMJavier
12/29/2022, 11:42 PMJavier
12/29/2022, 11:43 PM@sandeep549 I cannot agree with you. All deques (incl. queues and stack) are much faster when they are based on arrays. You should never use linked lists for that purpose, especially if you do competitive programming where performance is important.
You only need linked lists when you need to insert into the middle in O(1). This almost never happens in practice and extremely rarely needed in competitive programming. When it does happen you usually need an “intrusive list” which Java’sdoes not provide anyway.LinkedList
Toddobryan
12/30/2022, 3:49 AMephemient
12/30/2022, 4:07 AMephemient
12/30/2022, 4:09 AMpaulpaul1076
12/30/2022, 4:25 AMToddobryan
12/30/2022, 5:03 AMephemient [8:07 PM]
allocating the memory for a new link node can also result in pauses, so that isn’t as large of an advantage as it soundsBut only if there’s garbage collection or a similar issue. If you have an array representing a list of 10k items, and you’ve run out of space, the default code for ArrayList is going to allocate an array of size 20k and copy all 10k elements of the first array into it. Adding to either end of a linked list (assuming you have references to both ends) will involve allocation of a new node and the setting of three references: the previous end gets a reference to the new node, the new node gets a reference to the previous end, and the new node gets a reference to whatever is used to indicated end-ness, null or a dummy reference. The work is literally constant every time. It’s true that the JVM could decide to do something else during that time, but it’s a guarantee with an array implementation that every so often, you will be doing a lot more work for some operations because of the way that add works on ArrayList.
ephemient
12/30/2022, 5:10 AMephemient
12/30/2022, 5:20 AMAlbert Chang
12/30/2022, 7:14 AMKlitos Kyriacou
12/30/2022, 10:22 AMpaulpaul1076
12/31/2022, 3:31 AMephemient
12/31/2022, 3:39 AMSeq
for almost everything. but even so: Scala's List
isn't SeqLike
so it doesn't suffer the stupid API issues that Java's LinkedList
doespaulpaul1076
01/01/2023, 12:05 AMChris Lee
01/01/2023, 12:07 AMpaulpaul1076
01/01/2023, 12:11 AMephemient
01/01/2023, 12:15 AMephemient
01/01/2023, 12:16 AMColton Idle
01/01/2023, 3:41 PMephemient
01/01/2023, 4:38 PMephemient
01/01/2023, 4:39 PMephemient
01/01/2023, 4:41 PM