3 ms·
I think don't try to memorize the big-Os. Just read through a basic DS&A text, and see the standard structures: vectors, trees, linked lists, hashmaps. If you
by lordnacho 3y ago
I think don't try to memorize the big-Os. Just read through a basic DS&A text, and see the standard structures: vectors, trees, linked lists, hashmaps.
If you can picture them in your mind using blocks and arrows, the big-Os fall out of them naturally. To find an element, do you have to follow one pointer, then another? Do you have a choice at each junction? Is it contiguous? Hashmaps you have to convince yourself that it is indeed constant time, but once you get it you won't be in doubt.
Do the same for "what if I have to rearrange it, adding or removing an element?" and you get a bunch of other logical big-O answers.
There's a bunch of things made up of these things (LRU cache) and you can similarly logic your way to the answer, but I don't think I've come across an algo problem that isn't just a mash of these basic structures.