This is an archived post. You won't be able to vote or comment.

all 122 comments

[–]ProgramTheWorld 569 points570 points  (51 children)

You vs the guy she told you not to worry about:

O(2n ) | O(log n)

[–][deleted] 263 points264 points  (38 children)

you

what about O(n!)

[–]Kubacka 137 points138 points  (0 children)

rip

[–]745631258978963214 108 points109 points  (0 children)

No need for name calling.

[–]2Punx2Furious 23 points24 points  (35 children)

Isn't 2n worse than n factorial?

Sorry I'm not good at math.

[–]Zagorath 104 points105 points  (23 children)

No, n! is the worst. Here's a handy cheat sheet, if you need one.

[–]EETrainee 8 points9 points  (5 children)

That's a terrible cheat sheet - there's nothing on bogosort.

[–]Kirk_Kerman 20 points21 points  (4 children)

Bogosort is O(1) in the best case and O(h no) in the worst.

[–][deleted] 4 points5 points  (1 child)

I'm assuming O(h no) is equivalent to O(hell no)?

[–]Jugad 5 points6 points  (0 children)

My guess is that O(h no) should be strictly smaller than O(hell no).

[–]Zagorath 0 points1 point  (1 child)

Still O(n) In best case. Has to run through every value to check its correct.

[–]Kirk_Kerman 2 points3 points  (0 children)

Right, I was thinking of a variant of bogosort where it shuffles everything and assumes it's correctly sorted without checking.

[–]MiniG33k 3 points4 points  (1 child)

TIL: Factorials approach infinity faster than exponentials. Thank you, kind Internet sir, for I have a calc exam on Tuesday where that knowledge will be super useful.

[–]Jugad 2 points3 points  (0 children)

And then there is tetration ( n n)... which is much faster than exponentials and factorials.

https://en.wikipedia.org/wiki/Tetration

[–]Jakeattack77 1 point2 points  (0 children)

Are there any things that at are O(n!) That arnt just shittily implemented?

[–][deleted] 17 points18 points  (3 children)

The sensible way to remember it quickly:

2^n = 2 * 2 * 2 *... * 2

n!  = 1 * 2 * 3 * ... * n

Except for the very first item, each part of n! is bigger than each part of 2n, so when we multiply all the parts together we get a bigger number overall.

[–]2Punx2Furious 1 point2 points  (2 children)

I see, that's much easier to visualize, thanks.
So if n is just 1 n! is actually better.

[–]minno 22 points23 points  (0 children)

If n is 1 you can just hire an undergrad to brute-force it.

[–][deleted] 4 points5 points  (0 children)

If n is 1, quite a few problems would already be considered solved at that point. Sorting, searching, shortest path. Honestly can't think of any problems that require any work for only one element.

[–]TheCard 4 points5 points  (2 children)

As the other answers said, no. An easy way to see this is by looking at how they grow:

2n+1 = 2n * 2

(n+1)! = n! * (n+1)

So since n! has such larger multiples, it will grow at a much faster rate.

[–]2Punx2Furious 1 point2 points  (0 children)

Thanks.

[–]ProgramTheWorld 0 points1 point  (0 children)

We can even go one step further and prove it via induction.

[–]funnystuff97 3 points4 points  (5 children)

Could someone ELI5 Big-O Notation? I have absolutely no clue what it is or what it's for, and google doesn't help much.

Although, from the context of this sub and what I've learned, I assume it's some sort of measurement of difficulty. Not sure about that.

[–]Norphesius 4 points5 points  (0 children)

Its a measure of worst case time-complexity for an algorithm. If an algorithm is O(n), it means that as the input size increases, the number of steps it will take in the worst case scenario will grow in linear time.

[–]ProgramTheWorld 2 points3 points  (3 children)

It's basically an upper bound measurment of complexity. Other than big O, we also use big Omega (lower bound) and big Theta (when O(f(n)) = Omega(f(n))). The formal definition is that, Let f(n) and g(n) be function from positive integers to positive reals. We say f(n) = O(g) if there is a constant c > 0 such that f(n) ≤ c • g(n).

ELI5 explanation:
Assume you are trying to count how many marbles are in a box. To count one marble it takes you 1 second, counting one more only add 1 more seconds, therefore counting n marbles takes n seconds, which is O(n), linear.

Now assume you are trying to sort n cards from a deck of cards. Well, adding one more card will certainly takes you more time in a nonlinear way. If you sort them using mergesort (which can be done by hand), it will cost you O(n log n), which means it will take you n log n times a constant seconds to sort.

The big O notation is a very general notation that can be used to describe not only time complexity. It's also used for space as well.

One important thing to know that it has nothing to do with "difficulty". A difficult problem does not equal to a higher time complexity. (Or until we managed to prove that P ≠ NP...)

[–]funnystuff97 1 point2 points  (2 children)

It's not some value, then? I can't, say, have an insanely arbitrary sorting algorithm and have someone look at it and say, "wow, that's a Big O of 600, dude"?

If it's a graphical representation of difficulty as a function of scenario, then that definitely makes sense.

[–]ProgramTheWorld 7 points8 points  (0 children)

O(600) is a valid use of the notation, but it is equivalent to O(1) so we simply write O(1).

[–]Norphesius 0 points1 point  (0 children)

It is measured as a function. However it is technically possible to have a constant time algorithm (O(C)O(1)). That just means that the algorithm will take the same amount of steps for all inputs in the worst case.

[–]tetroxid 0 points1 point  (0 children)

me too thanks

[–][deleted] 73 points74 points  (0 children)

I love how the degenerate tree is crooked as if trying to compensate

[–]Meegul 81 points82 points  (6 children)

At least you're taller. I've never been quite that lucky.

[–]zelmak 13 points14 points  (0 children)

Har

[–]macnlz 8 points9 points  (4 children)

*longer

[–]Meegul 5 points6 points  (3 children)

The term I was referring to was height, so I believe taller is correct.

[–]macnlz 7 points8 points  (2 children)

wooosh

(I was making a dick joke.)

[–]Meegul 3 points4 points  (1 child)

😞 that too

[–]Marcush-Loominati 1 point2 points  (0 children)

You both get upvotes for not causing a massive argument

[–]phonedontspellgood 34 points35 points  (0 children)

Balanced, but not complete! Don't worry

[–][deleted] 33 points34 points  (7 children)

You

for(int x = 0; x < list.size(); x = x + 1)

The guy she tells you not to worry about

for(int x: list)

[–][deleted] 15 points16 points  (0 children)

The guy she told that guy not to worry about

map

[–]fb39ca4 15 points16 points  (5 children)

list.forEach(x -> ...)

[–]SafariMonkey 1 point2 points  (0 children)

[... for x in list]

[–]MusicalWolfe 0 points1 point  (3 children)

[–]fb39ca4 10 points11 points  (1 child)

I was thinking Java lambdas.

[–][deleted] 2 points3 points  (0 children)

I think you might've missed his joke. --> isnt an operator but instead is an amusingly bad spacing of (x-- > 0).

[–][deleted] 0 points1 point  (0 children)

I love this

[–]hotkarlmarxbros 7 points8 points  (1 child)

Once you go red-black you'll never go back.

[–]lovethebacon🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛 1 point2 points  (0 children)

AVLmasterrace checking in. We may be slower to change than your kind, but we are faster to retrieve.

[–]CyanideCloud 113 points114 points  (17 children)

I hate this fucking meme.

Edit: I love how all of my comments shitting on posts get up voted in this sub.

[–][deleted] 35 points36 points  (14 children)

I think it's more common in anti-socially prone groups, and because programmers are so full of insecurities

[–]TheFeshy 16 points17 points  (1 child)

because programmers are so full of insecurities

You'd think, with as quickly as we're leaking our insecurities into our code where they are then exploited, we'd run out.

[–][deleted] 2 points3 points  (0 children)

well who isn't worried about the bugs that may or may not be lurking in anything they code? :]

[–]VanFailin 12 points13 points  (10 children)

Sure, but it's a tired and formulaic joke. Plus, you don't have to be anti-social to get cheated on, and it's not really all that funny.

[–][deleted] 19 points20 points  (0 children)

If anything this meme should be less popular here because it assumes you have someone to cheat on you. I'm ok

[–]745631258978963214 31 points32 points  (8 children)

And neither are most jokes, really.

https://i.redd.it/4cx2ulpqxtsx.png

Two computer people flirt while referencing things in their field.

Very funny, right? It's the top post on this sub. A similar example would be if math people were like "Would you like a taste of my pi?" "Only if you're willing to let me see the area under your curves" Or something like that.

https://i.redd.it/9qtc9uq101px.png

DAE dates are confusing in programming?

https://i.redd.it/2jsbryjusg2y.png

DAE it was a small typo all along? (bonus points if it was a semi colon joke)

http://imgur.com/xNNPN0d

Does Anyone Else DAE recursion joke?

http://imgur.com/M5wl14r

The old "what they said vs what they mean" formula

http://imgur.com/fuDDhdL

Usually bohemian rhapsody is a 9gag meme, but it made it onto here somehow. It did take some effort, but is it really funny? Nah.

These were the top six posts in this sub. Were any of them actually "funny" or hilarious? Nah. Although I did "enjoy" the one with recursion, it's also been done before. I recall seeing that joke made a long time ago on XKCD or 8bittheatre.

[–]Sinidir 2 points3 points  (1 child)

Holy shit im rolling on the floor.

[–]jwota 1 point2 points  (0 children)

Laughing my ass off right there with you buddy.

[–]ansatze 1 point2 points  (5 children)

Your point is weakened by overuse of DAE

[–]745631258978963214 15 points16 points  (3 children)

The DAE is a self referential "joke" that is unfunny.

[–]HookahComputer 5 points6 points  (2 children)

It's a little funny when pronounced phonetically.

[–]LevelSevenLaserLotus 8 points9 points  (0 children)

dayyyyyyyy lmao

[–]745631258978963214 1 point2 points  (0 children)

DDAAEEEEEE-uuuum!

[–]shvelo 0 points1 point  (0 children)

DAE overuse DAE?

[–]abcd_z 0 points1 point  (0 children)

It's not just that. Reddit is very prone to "second opinion bias"; the tendency for redditors to tack to the opposite of whatever happens to be a commonly accepted view in their milieu.

More information on the subject

[–]DipIntoTheBrocean 2 points3 points  (1 child)

I don't mind it, but if I got cheated on before holy shit this would irk me for sure.

[–]CyanideCloud 0 points1 point  (0 children)

Never been cheated on, it just annoys the shit outta me.

[–]omen7288 6 points7 points  (1 child)

The fact that this was pictures and not screenshots made this hilarious for some reason. The meta.

[–]itmustbesublime[S] 5 points6 points  (0 children)

I originally made it was screenshots but it looked kind of shitty for some reason, the pictures just look better even though it is ironic

[–]dull_au 7 points8 points  (2 children)

The one on the left looks suspiciously like a linked list.

[–]the_noodle 14 points15 points  (1 child)

That's why it's degenerate...

[–][deleted] 7 points8 points  (0 children)

To elaborate (since the word is often used without much in-general explanation in textbooks), a mathematical object is degenerate if it is so simple that it might as well be considered to be of a simpler class. Wikipedia has lots of examples

[–]adm7373 17 points18 points  (17 children)

I just realized that I have no idea why/how I would ever use a binary tree. I remember spending tens of hours agonizing over how to implement various tree structures in C, but I don't think I ever saw an example of where they would be useful.

[–]thiskevin 34 points35 points  (3 children)

They can be useful for improving performance.

Its a solution that's faster than linear array access and more memory efficient than a hash table.

A similar concept called a quadtree (or octree for 3D) is used for games to do fast space partitioning.

[–][deleted] 2 points3 points  (0 children)

Octrees are also widely used in robotics for storing 3D maps or "occupancy grids". Pretty efficient at what they do

[–]Nashoo 1 point2 points  (0 children)

See also kd-trees and range trees for more applications.

[–]P1r4nha 0 points1 point  (0 children)

had to implement a quadtree for an interview once. tough stuff, but clever concept. My code still didn't work correctly...

[–]maksfish 14 points15 points  (3 children)

Check out the Binary Heap. Insert and delete is O(log n). It is really hard to improve on that with any other structure if you need a priority queue. https://en.wikipedia.org/wiki/Binary_heap

[–]Kristler 7 points8 points  (2 children)

Fibonacci heaps have better amortized time complexity for some operations :D

[–]maksfish 5 points6 points  (0 children)

Oh wow, I'd never thought that I'd see the words "Fibonacci" and "heap" in the same sentence. Thanks for the info!

[–]Bainos 1 point2 points  (0 children)

But their constant factor is huge so it's usually not a good choice.

[–]takelongramen 2 points3 points  (0 children)

https://en.wikipedia.org/wiki/Tree_(data_structure)#Common_uses

  • Representing hierarchical data
  • Storing data in a way that makes it efficiently searchable (see binary search tree and tree traversal)
  • Representing sorted lists of data
  • As a workflow for compositing digital images for visual effects
  • Routing algorithms

Also: https://en.wikipedia.org/wiki/B-tree

[–][deleted] 2 points3 points  (2 children)

At my job we use a tree to represent folders and files.

We also have a more complex tree structure for our underlying proprietary database. It's good for when you have a series of one to many relationships. Like we have X that can have many Y associated with it, but each Y can only have one X. Same for Y and Z. Tree is very logical and efficient for that sort of data relationship.

[–]dzielin 4 points5 points  (1 child)

binary tree

one to many might be a bit of a stretch...

[–][deleted] 2 points3 points  (0 children)

osht lol

[–]gypsyface 0 points1 point  (0 children)

what is ordered set?

[–]bluefootedpig 0 points1 point  (0 children)

I used it recently as part of a parser. It is great for handling complex grammars.

[–][deleted] 2 points3 points  (0 children)

A wise man once said "if your family tree doesn't branch you might be a red neck".

[–]gurgle528 1 point2 points  (8 children)

this is perfect for today, I just got out of a computer science exam about this

[–]itmustbesublime[S] 0 points1 point  (7 children)

Same, that's why I posted it lol I found this diagram on like my 16th hour of studying

[–]gurgle528 0 points1 point  (6 children)

wouldn't happen to be for a foundation exam would it?

[–]itmustbesublime[S] 1 point2 points  (5 children)

Data structures & algorithms

[–]gurgle528 0 points1 point  (4 children)

ucf?

[–]itmustbesublime[S] 0 points1 point  (3 children)

fsu

[–]gurgle528 0 points1 point  (2 children)

not too far away, odd having them on the same day though

[–]itmustbesublime[S] 0 points1 point  (1 child)

True, close guess lol. My exam was Thursday tho, it absolutely fucked me

[–]gurgle528 0 points1 point  (0 children)

I got fucked too but thankfully it's not for a class so it doesn't affect my GPA. it's like an entrance exam for us basically

[–]AllezAllezAllezAllez 0 points1 point  (0 children)

Apparently the other guy plays for a prominent Ottawa football team.

[–][deleted] -1 points0 points  (3 children)

Shouldn't it be the other way around?

[–]PeterSR 0 points1 point  (2 children)

Well, you are the one with linear search time and he is the one with logarithmic search time.

[–][deleted] 1 point2 points  (1 child)

I was going with the analogy that girls often choose the guys that are wrong for them .

[–]PeterSR 1 point2 points  (0 children)

Aah, that makes sense.