Thumbnail for Big O explained with a deck of cards by Fireship

Big O explained with a deck of cards

Fireship

1m 0s234 words~2 min read
YouTube auto captions
Transcript source

YouTube auto captions

This transcript was extracted from YouTube's auto-generated caption track. The transcript below is server-rendered so it can be read, searched, cited, and shared without opening the original YouTube player.

Pull quotes
[0:00]If you want to pop one card off the stack, that's extremely fast or O of one constant time.
[0:00]But if you then want to count the cards, you'll need to loop over the entire deck, resulting in O of N or linear time.
[0:00]That's going to require a strategy or algorithm like Bubble sort, where we loop over the deck repeatedly and swap out adjacent cards until the entire thing is perfectly sorted.
[0:00]Worst case, we loop over it 52 times, giving us O of n squared or quadratic time.
Use this transcript
Related transcript hubs

[0:00]If you want to get a job as a programmer, you need to know Big O. Imagine you have a shuffled deck of cards. If you want to pop one card off the stack, that's extremely fast or O of one constant time. But if you then want to count the cards, you'll need to loop over the entire deck, resulting in O of N or linear time. But now let's imagine we need to sort the deck in perfect order. That's going to require a strategy or algorithm like Bubble sort, where we loop over the deck repeatedly and swap out adjacent cards until the entire thing is perfectly sorted. Worst case, we loop over it 52 times, giving us O of n squared or quadratic time. Alternatively, if you're stupid, you could throw the cards up in the air and hope that they land perfectly sorted on the ground. That's called Bogosort and gives you O of N factorial, the worst possible time complexity. But now we want to find the eight of hearts in the sorted deck. Instead of looping through every card, you could do a binary search by splitting the deck in the middle. If the shown card is greater than nine, go left, otherwise go right. Continue that process to cut your work in half after every step, thus giving you O of log n or logarithmic time.

Need another transcript?

Paste any YouTube URL to get a clean transcript in seconds.

Get a Transcript