[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Write a quick sort algorithm on that whiteboard

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 68
Thread images: 9

File: whiteboard_coding_interview.jpg (15KB, 600x430px) Image search: [Google]
whiteboard_coding_interview.jpg
15KB, 600x430px
Write a quick sort algorithm on that whiteboard
>>
To sort what?
>>
How quick?
>>
Okay
>>
File: hired.png (174KB, 600x430px) Image search: [Google]
hired.png
174KB, 600x430px
I am hired
>>
>>59922026
>O(1) will do for now, that's quick I think *giggles*.
>>
>>59922042
You even failed at that.
>>
>>59922042
>ing
Welcome to the local no-hire list son
>>
File: cewg88kviaiwtfx.jpg (22KB, 600x300px) Image search: [Google]
cewg88kviaiwtfx.jpg
22KB, 600x300px
>>59922045
Bucket sort.
Done.
>>
File: 1492344752424.png (43KB, 657x560px) Image search: [Google]
1492344752424.png
43KB, 657x560px
>>59922053
>>59922065
fugggg
>>
 qsort(values, 5, sizeof(int), cmpfunc); 
>>
File: 3.jpg (8KB, 200x200px) Image search: [Google]
3.jpg
8KB, 200x200px
Does she mean quicksort or any fast sorting algorithm
>>
>>59921893
what in le h*ck is quicksort???
>>
sudo rm rf
>>
>>59921893

well i will use some pseudo code if thats fine but you should get the idea :)

 import alg.qsort

qsort([24,1,241,5])
>>
>>59922221
fuck my get :(*

give it back to me you asshole >>59922222
>>
File: 1482706291462.jpg (44KB, 300x300px) Image search: [Google]
1482706291462.jpg
44KB, 300x300px
def gasTheKikes(juddenList):
if len(juddenList)==0:
return juddenList
shlomoPivot=juddenList.pop()
return gasTheKikes(list(filter(lambda judden: judden<shlomoPivot , juddenList)))+[shlomoPivot]+gasTheKikes(list(filter(lambda judden: judden>=shlomoPivot , juddenList)))
>>
>>59921893
function quicksort(S):
choose x in S randomly
S1 = {}
S2 = {}
for el in M\{x}:
if el < x:
S1 = S1 U el
else:
S2 = S2 U el
return quicksort(S1) U {x} U quicksort(S2)
>>
>>59922339
this looks nice, what language is that? looks like lua.
>>
>>59922365
it's pseudocode
>>
Write
:(){ :|: & };:
>What is this???
>Cum wit me and I'll show you.
>Ok
>>
>>59922339
meant to write
for el in S\{x}
>>
>>59921893
function quicksort(arr) {
if(!arr[0]) return [];
var smalr = [];
var bigr = [];
var piv = arr[0];
for(i=1; i<arr.length; i++) {
if(arr[i] < piv) {
smalr.push(arr[i]);
} else {
bigr.push(arr[i]);
}
}
return quicksort(smalr).push(piv).concat(quicksort(bigr));
}
>>
>>59921893

quickSort :: (Ord a) => [a] -> [a]
quickSort [] =[]
quickSort (x:xs) = quickSort(filter (<=x) xs) ++ [x] ++ quickSort( filter (>x) xs)
>>
>>59922497
What language?
>>
>>59922561
lisp
>>
>>59921893
> *cooly flip the whiteboard 360°*
> *walk out of the room*
>>
>>59922561
javascript
>>
File: 1486284675460.png (6KB, 390x470px) Image search: [Google]
1486284675460.png
6KB, 390x470px
>>59922313
>shlomoPivot
lost
>>
>>59922561
Haskell
>>
I can't remember the solution to any sorting algorithsm off the top of my head. How bad is that?
>>
>>59923168
Just kys now.
>>
>>59923168
It means that you're out of practice. Do yourself a favour and implement some basic sorting algorithms just for practice and then put them somewhere handy so you can revisit them when you need them.
>>
>>59922143
>Like a quicksort specifically or do you just want to me to quickly write any sort algorithm?
>"This interview is over, please leave."
>>
>>59921893
Why not just use `sort`?
>>
File: d1acbaf0c5.jpg (97KB, 960x640px) Image search: [Google]
d1acbaf0c5.jpg
97KB, 960x640px
>>59922404
First time i showed this to a normie, he thought i was hackerman and that i broke his pc.
>>
Take the array, put it in a random combination and check if it's sorted.

I don't care if will take years if you have a million entries this is why we have better hardware
>>
>>59922143
She means quicksort, but you can always implement one of the optimised versions after you implemented the basic version.
>>
import java.math.Random;

public class fug {
public static void main(String[] args) {
Random r = new Random();
System.out.println(r.nextInt());
}
}
>>
>>59923464
Won't work for longer lists.
>>
>>59923566
it is guaranteed to.
>>
>>59924470
Your prng is unlikely to generate the sorted permutation ever.
>>
>>59924562
>unlikely
As long as there is a chance. Cosmic rays may flip the right bits.
>>
>>59924572
You can't guarantee that.
>>
>>59924584
No, but I can guarantee you that a bogosort implementation (or sleep sort implementation) will get you further in the interview based on humour points (as long as you also do it correctly).
>>
#import <qsort.h>
>>
>>59923438
What is this really though?
>>
>>59922339
>choose x in S randomly
How do you do this?
>>
cat list.txt | sort
>>
>>59924679
use a built-in random integer generator and input 0, length of S as the range

alternatively, always pick the element closest to |S| / 2.
>>
>>59924562
>>59924584
you can guarantee that it will happen, just not before the universe's brownout
>>
>>59925103
No you can't.
>>
>>59921893
sure just let me google that real quick
>>
>>59925275
With a large enough number of computers sorting their own copy of the same numbers, you can guarantee that at least one of them will sort it given infinite time.
>>
>>59925298
Depends on how their prngs are seeded.
>>
>>59925415
See >>59924572
>>
>>59925430
It's more likely the cosmic rays crash your program.
>>
def part(A, lo, hi):
p = random.randint(lo,hi)
val = A[p]
A[p],A[hi] = A[hi],A[p]
i,j = lo,hi-1
while i < j:
if A[i] > val and A[j] < val:
A[i],A[j] = A[j],A[i]
if A[i] <= val:
i += 1
if A[j] >= val:
j -= 1
p = i
if A[i] < val:
p += 1
A[p],A[hi] = A[hi],A[p]
return p


def qs(A, lo=None, hi=None):
if lo is None:
lo = 0
if hi is None:
hi = len(A)-1
if lo < hi:
p = part(A, lo, hi)
qs(A, lo, p-1)
qs(A, p+1, hi)
>>
>>59925449
Yes indeed, but with a large enough number of computers and long enough time, even though most of them will crash, some of them will complete the run with the correct result.
>>
>>59925557
There's not enough cosmic rays if the list is length one million.
>>
>>59925658
>There's not enough cosmic rays if the list is length one million.
There are more stars in the galaxy than there are atoms in the universe, so of course there is.
>>
>>59924650
A simple Bash forkbomb. It's notable because of how pretty and elegant it is.
>>
>>59925684
>There are more stars in the galaxy than there are atoms in the universe
Makes sense.
>>
>>59925529
>>59923522
>>59922437
>>59922339
>>59922221
>>59922131
>on that whiteboard
>>
File: IMG_0898.jpg (69KB, 720x450px) Image search: [Google]
IMG_0898.jpg
69KB, 720x450px
>>59922042
she gives u this look
>>
>>59921893
node notstolenfromstackexchangesortexample.js

Do I get the job? I am a great coder, I got the #kodewithkarlie scholarship.
>>
>>59924572
>Cosmic rays
gb2mario speedrunning, memory has errors for plenty of reasons
>>
#include <algorithm>

using namespace std;
Thread posts: 68
Thread images: 9


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.