Most Programmers Don't Know About This in Python. #python #coding #programming

preview_player
Показать описание
This class is super useful and a great alternative for the list data type in python.
In this video we will learn about deque class to work with the insertion and deletion of the element, we will learn how this is more efficient then the list and why the list has O(n) time complexity while the deque has O(1) time complexity.
#python #programming #coding
Рекомендации по теме
Комментарии
Автор

great, we have solved an o(n) complexity issue with o(n+1) complexity by moving all values into a new variable

parasetanol
Автор

Soo...
That solution sounded horrible, so I had to time it.
I created a list with 10 Million numbers, just so it's actually measurable.

Inserting something to the beginning of that list takes ~0.0049 seconds.
So yes, that it quiet a lot of time for just one number.

So let's turn it into a deque. :)
Just turning that into the deque takes ~0.05 seconds.
That is already 10 times the time the insert statement takes. ._.
Well, anyway, let's continue.

Adding the number to the front takes seconds. Great improvement! Blazingly fast! Nothing can stop us now! :D

But now we have to return the list.
And we are not in a small project, so we better not just completely mess up the stuff everywhere else by suddenly having a deque in production what no one expects.
So we have to turn it back into a list.

And turning a deque into a list takes ~0.05 seconds again. Hey, it's consistent in both directions. :)

So, great solution.
A problem that would have required ~0.0049 seconds now requires ~0.1 seconds.
Just 20 times slower. :)

Even if you have to add more than 20 numbers to the beginning you can do that more efficiently without using the deque.
WIth employees = [stuff to add to the beginning] + employees, which takes ~0.05 seconds.

mrxgamers
Автор

manual says: Deques are a generalization of stacks and queues (the name is pronounced “deck” and is short for “double-ended queue”).

triip
Автор

I'd rather have O(1) indexing than O(1) insertion. Linked lists have an O(n) time complexity for selection, which is less desirable in most cases.

TheCodeGriffin
Автор

Its not deck, its d queue common data data structures. By the way u created new data structures and copied the elements. Behind the secne it will copy the element to deque which is o(n) time complixity. And u increased the space complixity

thenaughtyanil
Автор

If you're worrying about time complexity in Python you done messed up

cuicuidev
Автор

I might be nitpicking but it is not pronounced as "deck" it is pronounced as "de-queue"

rishabhtomarAda
Автор

i think deque uses 2 queues, not a doubly linked list; linked lists are always bad no matter what

simonwillover
Автор

"most programmers don't know this"... proceeds to show this

devnarula
Автор

For this problem specifically, would you be able to reverse the list, append, and reverse again? What is time complexity of that?

trevor
Автор

now you are using more memory and average access time to a random element has also increased. You must know how it would be used to say something is better or worse. If you insert only now and then, but access it way more frequently, then you have created a bottleneck. There is no free lunch.

easobral
Автор

Nice man, deque - i dont use for python, only for c++. Its interesting o(n) and o(1)

yehorishtvan
Автор

Wont that be O(2n)? Assuming we beed the employee list back as an array, making a deque shoukd be O(n) and making a list from it should also be O(n).


Btw i might be wrong, just asking

infiteri
Автор

or you could be a rational human and just add it to the back of the list 🙄

kelvinnnnnnnn
Автор

Hey hi everyone
I am that new intern he's been talking about in every video .he ows me credits for that🙂‍↔️

hariram
Автор

if you need speed and efficiency, just use sth else

ArmirMitrandir
Автор

so you're just going to put an architecture problem on an intern?

vilkillian
Автор

eh what is the complexity of converting list to a deque 😂

guyspet
Автор

Day by day I like lists less and less 😊

mesmeridze
Автор

who tf runs this channel, it consistently posts literally the worst python content out there

mrtoine
welcome to shbcf.ru