[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]

>Enough chit-chat, let's see that Bubble Sort.

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: 39
Thread images: 5

File: interview.jpg (1MB, 2500x1407px) Image search: [Google]
interview.jpg
1MB, 2500x1407px
>Enough chit-chat, let's see that Bubble Sort.
>>
[removes bubble solution from pocket]
>>
File: 1476744239283.jpg (39KB, 508x524px) Image search: [Google]
1476744239283.jpg
39KB, 508x524px
>>59850691
>Everyone on /g/ is a programmer
Getting real tired of your shitty memes
>>
>interviewing for programming jobs
If you're not a microarchitect, you can go somersault off the World Trade Center.
>>
>>59850691
*this kills the /g/entleman*
>>
File: 1490716010763_1.jpg (93KB, 919x829px) Image search: [Google]
1490716010763_1.jpg
93KB, 919x829px
>>
>>59850764
>microarchitect
go ask find a computer engineering grad that isn't working in software engineering, id are you
>>
>>59850755

To be fair I would expect that anyone with a degree related to computers or math can implement a bubble sort in pseudocode. If you can't, it's because you suck at learning.
>>
>>59850786
//ask, i dare*
>>
>>59850691
gib job

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Integer> numbers = new ArrayList<>();

while (true) {

System.out.println("\nEnter a multiple of 3 or 5, type 0 to quit and check array");

int input = sc.nextInt();

if (input == 0) {
break;
} else if (input % 3 == 0 && input % 5 == 0) {
System.out.println("\nFizzledBuzzlet: " + input);
} else if (input % 3 == 0) {
System.out.println("\nFizzled: " + input);
} else if (input % 5 == 0) {
System.out.println("\nBuzzlet: " + input);
} else if (input % 3 != 0 && input % 5 != 0) {
System.out.println("\n" + input + " is not a multiple of 3 or 5");
}
numbers.add(input);
}
System.out.println("///////////////////////////////////////////////////////");
System.out.println("\n" + (numbers) + " Before sort");
bubbleSort(numbers);
System.out.println("\n" + (numbers) + " After sort");
}

public static void bubbleSort(ArrayList<Integer> numbers) {
int count = 0;
for (int outer = 0; outer < numbers.size() - 1; outer++) {
for (int inner = 0; inner < numbers.size() - outer - 1; inner++) {
if (numbers.get(inner) < numbers.get(inner + 1)) {
swap(numbers, inner);
count = count + 1;
}
}
}
}

public static void swap(ArrayList<Integer> numbers, int inner) {
int temp = numbers.get(inner);
numbers.set(inner, numbers.get(inner + 1));
numbers.set(inner + 1, temp);
}
}
>>
>>59850795
I do networking and security, never needed this shit. How's freshman year going?
>>
>>59850801
>>59850786
All the successful ones at hardware companies. The only ones not working are the ones who don't have enough experience to work with hardware. Hardware industry naturally favors people with 10+ years of experience nowadays, but that'll change once they realize no one will be maintaining their stupid life support architectures after all the oldfags die out or retire.
:^)
>>
File: 1457983662851.jpg (29KB, 550x335px) Image search: [Google]
1457983662851.jpg
29KB, 550x335px
>>59850691

>yes yes, your github and portfolio of projects are well done, HOWEVER
>>
>>59850811

It has nothing to do with needing it, from only that statement I know that it's been less than 20 years since you started working. It's just a basic task to verify that you're not retarded, if I ask you to sole 2+2 will you complain that you never have to do it in practice? You're retarded.
>>
>>59850861
But I add two things with two other things all the time. Probably on a daily basis. Your analogy is shit.
>>
>>59850947
How come?
>>
>>59850795
Bubble-sort to me is a filter question. If you can't do it, the interview just stops. I mean, it's bubble sort guys.
>>
>>59850947
My profesor once told us in a lecture how he proudly explained to some Chinese programming champion how this is bad programming. I can't remember the reason. Probably I didn't even understand it in first place. I still avoid it though.
>>
>>59850795
>>59851015
I had to look up which one one bubble sort is to be honest. I can never remember the names of sorting algorithms.
>>
Well, uh, so uh, to sort we, uh, well...

Maybe we'll start with some test cases, so uh, ...

>3, 8, 12, 17

Uh... Oops, those are already sorted, so uh...

Actually, that's uh, probably a good test case too, so uh, I'lll just... you know...

I should start coding... Yeah....

Okay so uhh, first we need to write a function declaration, so uhhhh...

Should I use python? ...

...You don't mind? Sounds good, so uh...

We write...

>Define bubblsort:

Wait crap, I misspelled bubble, one sec...

>define bubblesort:

So uh- wait, I need to take a list or somethinng to sort, one sec:

>define bubblesort(list):

So uh... I think that one's right.

So uh, we should... check if elements are sorted, so we should probably define a function for that, one second...

>define isSorted(list):

So we need to loop the list to do that so, uh, we can...

Uh...

Actually I forgot the forall thing, so for now let's just do it like C. So...

>For i in range(0,list.size):

Uh... wait, so, i is an index, but in Python the list iterates over objects, so, uh.

Actually, is it okay if we start over in C++?

I, uh, so... I think I'm a little low on time... maybe I'll just change the loop and keep going, functions were defined, we can fix it, uh, if we have time after.

So uh, we write in in c++:

>(for (i =0, i<=list.size, i+=1)):

Or uh, something like that, so, uh, this will get us all the indexes and...

...We're low on time? Well, uh, we can, uh, at least finish writing the test cases, I think. So uh,

>3, 8, 12, 16, 10000

Well, wait, that's a little hard to fit on the board, maybe I'll just use...

>3, 8, 12, 16, 10

Wait, uh, I wanted this one to be the sorted test case so uh we can fix it...

>3, 8, 12, 16, 105

And uh, now we just need the unsorted case, uhh...

>105, 16, 12, 8, 3

Uhh, yeah, that's okay I guess... iIt could be anything, really.

I think this is a good start, so uh, if you wanna stop we can...

Oh okay, thanks for your time too.

>Interview feedback:
>
>>
>>59851171
Fuck you for wasting my time on this post
>>
>>59851009
First off, you're creating a new object every iteration (input). That's relatively fine for primitive types but it's not a good habit to get into. Secondly, while(true) loops are fine if you wanted to do something like this:
while(true){
...
if(conditionOne){
doStuff();
break;
}else if(conditionTwo){
doSomethingElse();
break;
}else...
...
}

where you have to do specific calls right after a condition switches. However, most times, you'll need to know which case was true (but now possibly isn't) for later parts of the code, so you'll need to use a boolean for it which would defeat the purpose of the while(true) loop, as you could move that if statement outside of it and add a few boolean objects.

What I'd do is this:
int input;
do{
...
input = sc.nextInt();
...
} while (input != 0);
>>
I could probably come up with a psudo solution from memory and probably be close to the actual algorithm
>>
>>59851120
Potential infinite loop
>>
>>59851189

Real interview I had to sit through. I actually have to give feedback and have no fucking clue what to say
>>
>>59851303
Just come up with a general algorithm to detect whether or not it will halt.

In all seriousness, while(true){...if(condition) break;...} can get stuck in an infinite loop the same way as while(condition){...}
>>
>>59851322
while(!condition)*
>>
File: 1471621363046.jpg (26KB, 457x480px) Image search: [Google]
1471621363046.jpg
26KB, 457x480px
>>59850691
Fuck it and let's do quick sort
>>
>>59851322
Yeah but depending on the circumstances can you really detect a halt or just a really long running loop?
>>
negative numbers are fucking me, probably has to do with the 0
bubblesort = takeWhile (not . sorted) . iterate bubble
where sorted = and . map snd . scanl (\(x,_) y -> (,) y $ x <= y) (0, True)
bubble [x] = [x]
bubble (x:y:ys) = if y<x then y : bubble (x:ys)
else x : bubble (y:ys)
>>
>>59851348
It depends.
for(i=1;i<100;i++) sysout(i); will obviously halt, and it's possible to detect some haltable programs for relatively simple programs.

The halting problem only really states there's no general algorithm for it, so for specific cases there are algorithms you can use to prevent infinite loops.
>>
>>59851147
same, I now that I looked at it I clearly remember it, but I confuse it with other sorting algorithms I generally disregard since I never use them anyway
>>
>>59851360
oops, that's the test one
its actually
bubblesort = head . dropWhile (not . sorted) . iterate bubble
>>
>>59851171

AAAAAAAAAAAAAAA
>>
>>59851313
>try first outlining your solution in English or pseudocode before picking a language
>>
>>59851171

>That mangled for loop

You're trying to rustle me anon
>>
>>59850802
why are my eyes bleeding
>>
>>59850802
>count++;
Besides that pretty solid code 8/10
>>
>>59850691

>tfw when people imlement selection sort or shaker sort instead


>>59851171

That's surprisingly accurate..
Thread posts: 39
Thread images: 5


[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.