Python Sets Tutorial #1 & Time Complexity (BIG O)

preview_player
Показать описание
In this video I explain how to implement sets in python and explain the main advantages and disadvantages of them. I go over creating sets, removing and adding items and talk about the time complexity of these operations. Sets are an unordered collection of unique elements. They can perform the following three operations in constant (O(n)) time:
1. in
2. add
3. remove

Use sets when you want check if elements exist and don't care about the order or frequency of them.

Please leave a LIKE and SUBSCRIBE for more content!

Tags:
- Tech With Tim
- Sets in python
- Python Tutorials
- Python set tutorial
- Using sets python
- Time complexity of sets python
- Sets Python
- Sets Python 3
Рекомендации по теме
Комментарии
Автор

really love that you combined python data structure and big O!! I search through YT and only your video did this!! exactly what I need!! Will appreciate it if you could talk about how tuple, list, set, dictionary are implemented in python (that would naturally explain why each of them have such and such big O).

dant
Автор

I really liked how you explicitly explained what happens when you look up a value in a list, really good video thanks.

erlin
Автор

Thank you so much for the videos you are always clear, in depth and clear to understand.
One small thing I would like to point out about sets vs lists:
I made a small class to time and check the memory expense of a list vs a set these are the results of creating a100.000.000 list and set, and look for the last number in it:

Time to create: 3.4420700073242188
Memory size: 0.835GB
Found True in element type <class 'list'>
Elapsed time: 0.6005411148071289

Time to create: 4.165701866149902
Memory size: 4.295GB
Found True in element type <class 'set'>
Elapsed time: 0.0

So yes, sets are incomparably faster for the operation (as you perfectly explained in the video), but also slower to create and more than 5 times memory expensive!

Erfo
Автор

Hey Tim, that was an awesome explanation and Big O notation made the things more clear thanks for the awesome explanation

joeljacob
Автор

hi im using your tutorials to make a game... are you fine with me crediting you in my game for the help?

xXlolmineXx
Автор

maybe make the text more clear, or enlarge screen size
Sorry, I realized i just needed to do fullscreen

esh
Автор

what's the complexity for creating a set of a list of size n with k duplicates?

eladsilberring