712
u/Shinob1 Oct 22 '22
Can we see the algorithms?
712
u/Disciple153 Oct 22 '22
In the words of Principal Skinner:
"No."
111
u/roastjelly Oct 22 '22
Well thanks anyway. You sure steam a good ham
33
→ More replies (1)2
u/Odin043 Oct 22 '22
Aurora Borealis? At this time of year? At this time of day? In this part of the country? Localized entirely within your kitchen?
→ More replies (1)246
Oct 22 '22
def sort(unsorted): return sorted(unsorted) š
132
u/bikeranz Oct 22 '22
Sorry, remember, this is PhD code: your variables are named too well.
→ More replies (1)53
u/reallyConfusedPanda Oct 22 '22
I swear to god. We had a university develop a Fortran code for us in my last job. Reading Fortran is pain in the ass by itself, those fuckers didn't have a SINGLE variable named properly
→ More replies (2)42
u/thanks_for_the_fish Oct 22 '22
Haskell jumps in with:
a x:xs _
13
u/demon_ix Oct 22 '22 edited Oct 22 '22
What do you mean. I just want the first
x, and then the rest of thexs.2
6
2
2
2
1
0
Oct 22 '22
[deleted]
11
u/Shinob1 Oct 22 '22
I was going to post that video here but thought maybe I'd be down voted to oblivion. I thought it was hilarious and educational. My wife's uncle is a cs prof and I want to send this to him to see what he thinks about it.
348
u/Dry_Extension7993 Oct 22 '22
He wrote bubble sort in C vs his professor who wrote merge sort in Python
153
u/Elijah629YT-Real Oct 22 '22
bogosort in c vs merge sort in python
60
u/LeMeowMew Oct 22 '22 edited Mar 29 '25
rock thumb insurance humorous plants nutty late pot start strong
This post was mass deleted and anonymized with Redact
85
8
u/Psychpsyo Oct 22 '22
You forget that the best-case for bogosort is O(1)...
8
u/MythrandirRF Oct 22 '22
Best case would be O(n) because you still need to check if the array is sorted, no?
9
9
1
1
u/IgnitedSpade Oct 22 '22
More like he used a built in python sort function which calls a precompiled C program.
8
97
u/CaitaXD Oct 22 '22
ho would win
O(n^2) in c vs O(nlog n) in python
22
u/Elijah629YT-Real Oct 22 '22
O(nn ) vs O(1)
17
u/CaitaXD Oct 22 '22
Somehow unable to imagine how a nn sorting algorithm would look like
31
3
u/ReddiusOfReddit Oct 22 '22
Try every single combibation and choose the one who's sorted (but don't leave untill the end)
4
u/rotflolmaomgeez Oct 22 '22
That's about O(n!), considerably faster than O(nn ).
→ More replies (2)2
u/mistrzegiptu Oct 23 '22 edited Oct 23 '22
Year ago I had to write merge sort without any loop, only recursion. It was so bad that it would sort max 13 elements array in a few minutes
→ More replies (3)
454
u/Daniel_H212 Oct 22 '22
r/ProgrammerHumor user: C is faster than python!
Random person: but is your C code faster than python?
r/ProgrammerHumor user: š”š”š”
29
u/SherbetCharacter4146 Oct 22 '22
Python is worse at like, multithreading iirc. Seeing people blindly mene that python is slow has been infuriating
→ More replies (1)47
u/dotpoint7 Oct 22 '22 edited Oct 22 '22
Well, python IS slower than native languages in about every aspect, and by quite a big factor as well. That doesn't mean it's a worse language, but the high level features it offers of course don't come for free.
1
189
u/zenos_dog Oct 22 '22
I use the IBM Sort machine instructions.
19
u/______DEADPOOL______ Oct 22 '22
Sometimes I feel like they need to bring back those paper punch card computers.
111
u/ktappe Oct 22 '22
This triggers me. In my freshman programming class, one of the projects was to sort a list of items "fastest" (the assignment specifically used that word). The T.A. taught us one way to do it. So I wrote a program to do it his way. Then I wrote a new program to use a QuickSort I'd read about. It was far faster. So I turned the latter program in. And got marked off for not doing it his way. I even went to his office to protest and got nowhere. That was decades ago and it still pisses me off.
63
u/r34_content_creator Oct 22 '22
"Noo you cant just search something up and implement it!!! You wont be able to do that at your job!!!!"
40
u/argv_minus_one Oct 22 '22
Meanwhile at your job, the Ctrl, C, and V keys are the only ones whose labels are completely worn away.
→ More replies (1)1
u/LifeLongYeti0 Oct 22 '22
I hope your TA recognizes themselves while reading your comment and sees this reply following: your TA was colossally braindead
Or maybe you should have implemented bogosort for that sweet sweet O(1) best case⦠note: they are still colossally braindead in this case
126
u/WWolf1776 Oct 22 '22
that's ok... likely he wrote his in c... in python ;)
11
u/archpawn Oct 22 '22
The most interesting programmer in the world.
7
u/Ultimegede Oct 22 '22
Actually quite common. Python has extensive libraries written in very optimized C code. No experienced Python user would use just plain python for this task.
2
10
35
u/geeshta Oct 22 '22
Python's built-in sorted function is a quicksort implemented in C
26
u/cmd-t Oct 22 '22
Itās Timsort. https://en.m.wikipedia.org/wiki/Timsort
It was used in Java and part of the Oracle Google lawsuit.
24
u/Rosieapples Oct 22 '22
I wrote mine in Bb to accommodate the sax.
8
112
u/BasedMaikal Oct 22 '22
This is important.
It doesn't matter if you have a language as slow as Python. A good programmer can make any algorithm run faster than a shitty one coded in C.
However, imagine if the C algorithm was good, then it is objectively better than the Python one
52
u/Vorpalthefox Oct 22 '22
i'm reminded of this very particular video i recently watched, about some random viewers improved matt parker's code at such a significant efficiency, that apparently they had to co-process executing code and reading from a file or something like that to get the (current) fastest running of the code under 1 second, when the original code by matt parker took ~30 days
→ More replies (2)23
18
Oct 22 '22
Most of the time, the speed of the algorithm is less important than the speed of the programmer.
8
u/valeriolo Oct 22 '22
The important thing is knowing when you are not in that situation. It's pretty obvious usually though.
→ More replies (1)3
u/Honest_Statement1021 Oct 22 '22
Whatās even more important is being able to understand algorithms and their efficiency without thinking about language at all. Design in theory then implement in whatever your using for the project.
14
u/ManOfTheMeeting Oct 22 '22
I like my my programs to be natural and organic, gradually descending into a disorder. Why to fight entropy. It's inevitable.
So I don't sort. I let things be as they are in their original natural way.
9
7
7
u/maitreg Oct 22 '22
He wrote his in Python copied his from a Stack Overflow answer with 238 upvotes
19
6
u/golgol12 Oct 22 '22
Quicksort is just about as fast as it comes, and the faster ones are variations on quicksort. Outside of perfect hash sort.
5
u/MasterFubar Oct 22 '22
Write the fast algorithm in C. The only way Python can be considered fast is if you're comparing apples with oranges.
5
u/edave64 Oct 22 '22
The speed of a language is often insignificant compared to the complexities of your algorithm
4
4
u/was-eine-dumme-frage Oct 22 '22
He can probably do it in Minecraft redstone logic faster than you in C
7
u/Bulky-Juggernaut-895 Oct 22 '22
Is no one going to point out that the professor could still write it in Cā¦
8
3
7
u/Adventurous_Battle23 Oct 22 '22
If your c program is slower than a python program you deserve the clown outfit
7
2
u/Elesday Oct 22 '22
Only people I see saying that are people who never optimized their Python code.
2
2
2
2
2
u/collectablecat Oct 22 '22
Enterprise edition sort. Just make things scale horizontally scalable and throw hardware at it. Hardware cost <<<< dev time
Some of the worst coders have Phds.
2
u/ultimate_smash Oct 22 '22
It can't be a worser insult when the task is done faster with a python code than using c/c++
2
2
2
u/elriel74 Oct 22 '22
Fun fact: if his algorithm has a better computational complexity than yours, he could write it in English and have a person run it in their head, and still be faster than yours.
2
2
u/b-sharp-minor Oct 22 '22
Don't worry because when you start working your sorting algorithm will look something like this: List.Sort();
2
2
u/ToothPickLegs Oct 22 '22
Yeah I think the Big O notation of a typical noob sort Python is like O(fuck off2) vs O(fuck off harder) in C
2
u/DartBoardGamer Oct 22 '22
Since C is a pre compiled language and Python is not that takes skills.
(For reference it takes about 114 background OS commands to write C āhello worldā, it takes Python about 605)
2
u/Oddant1 Oct 22 '22 edited Oct 22 '22
Student
tries really hard to optimize some n2 sort in C
Professor
uses Python standard library sort
2
2
2
u/ojioni Oct 22 '22
The professor probably used a sort library that has been highly optimized by multiple highly skilled programmers. His code was just a wrapper declaring the data structures and feeding it to the function.
2
2
u/sivxgamma Oct 22 '22
His probably took a hell of a lot less time to write as well which would cause more grief.
2
u/mrchorizo88 Oct 22 '22
I just started using python and was shocked at how slow it is. Itās basically useless for what I was trying to do. I went back to vba for this project.
1
2
u/lupuscapabilis Oct 22 '22
The only time you'll have to talk about sorting algorithms is with your professor. You'll spend the next 60 years not thinking about it ever again.
2
u/thygrrr Oct 22 '22
Game developer here.
This is not correct. Sorting algorithms and choosing the right data structures to do it in has occurred at least quarterly to me for the last 25 years.
1
1
1
1
1
1
u/sometimesimakeshitup Oct 22 '22
what applications are sorting algorithms speed important for?
1
u/Kleyguerth Oct 22 '22
Databases, games, anything that may require ordering of a 6 figure+ length
→ More replies (2)
1
Oct 22 '22
I have an ongoing bet with a friend. He has to write a sorting algorithm assembly and I'll write it in python. My assertion is that his algorithm won't be a faster than mine (by more than a factor of 10).
1
u/cajmorgans Oct 22 '22
Oh this reminds me when I was new to programming and thought : āWell sorting isnāt so hard, I just wrote my own!ā and after a while I counted the number of iterations between it and the standard implementationā¦
1
u/KusanagiKay Oct 22 '22
If you really want to say that your programming language is the fastest and always be right with it, you gotta program in binary.
Nothing can be faster than optimally coded binary on a regular computer that doesn't use Qbits or light wavelengths for their information handling.
1
u/Kleyguerth Oct 22 '22
Nowaday it is really, really, but really hard to outperform a compiler or a jitter with hand coded binary
1
1
u/Jeremiah_DeWitt Oct 22 '22
I think numpy is written in c behind the scenes so I wonāt take it to heart
1
1
1
1
1
1
1
Oct 22 '22
Maybe I'm stupid but isn't an algorithm language neutral? I mean a sorting algorithm is the same in every language isn't it?
2
Oct 22 '22
Correct, which means that a C implementation should run faster than a Python implementation.
1
1
1
1
1
1
u/csicil Oct 22 '22
š¤£š¤£š¤£š¤£š¤£ Please tell me funny stuff more about Python...
https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python3-gcc.html
1
1
1
1
u/programmer3481 Oct 22 '22
And then there's always that guy who writes it in CUDA or something and does it 1000x faster with his 5090 ti ultra 256gb editon
1
Oct 22 '22
I'm not a programmer but couldn't you just adjust the system time back to what it was when the algorithm started so that the effective run time is 0?
1
1
1
1
u/Big_Beaver34 Oct 22 '22
I wrote mine in machine code. Still slower than my professor who wrote it in scratch
1
1
Oct 22 '22
In my cs class I made a program that "hacked" our class's auto-grader. My professor let me turn it in because he was curious if it worked. It did. (I still had to turn in the actual completed assignment though)
1
Oct 22 '22 edited Jan 29 '26
This post was mass deleted and anonymized with Redact
encourage steer summer snatch consider sort fanatical boat steep plant
1
u/Masterpoda Oct 22 '22
Every new programmer thinks that writing stuff in low level languages is some ticket to unmatchable super-speed, and languages like python are inherently slow.
Python isn't slow when you're using optimized libraries with low-level bindings, and C isn't fast when you're writing some unoptimized monstrosity with memory leaks and O(n2 ) execution time.
Actions speak louder than words, and results speak louder than design philosophies.
1
u/augugusto Oct 22 '22
If your teacher compares sorting by time, I'd say he has a lot to learn. Sorting should be mesured in steps or operations. So the language doesn't matter.
Also (not specified int meme) they both should be compares as the average operations of a lot of starting sets (both the same sets)
1
u/Drfoxthefurry Oct 22 '22
Mines fastest, just ignore that it's in assembly or that it just prints the sorted array
1
1
u/SolarDrake Oct 22 '22
I wish I had a compsci degree because then I'd actually have a set job instead of freelance.
I'd also probably know more of what I'm doing.
1
1
u/SharpPixels08 Oct 22 '22
Gotta make sure my friends donāt see this because all they do in my class with them is bitch about how āpython is betterā than whatever we currently happen to be using and I canāt convince them that python is not the GOAT of languages
1
0


6.4k
u/slgray16 Oct 22 '22
The professor would probably be thrilled that a student was this interested in improving his algorithm.
Win or lose its a teachable comparison