Wow, I was surprised to see mine at the edge of the graph on its own. I wonder is that a good or bad thing..! :-)
My first two submissions aren't even on the graph. :-)
Interviewing programmers: Analysis taster (work in progress)
21–30 of 34 posts
Re: Interviewing programmers: Analysis taster (work in progress)
#22Is there a full size image so I can read the labels and find my submission? :)
It wasn't intended for that purpose, but stand by ... EDIT: OK, I've uploaded a larger version where the labels are readable, but I've had to change the layout so the nodes don't overlap. The lengths of the edges are now not always realted to the distance, although it's approximate. http://www.solipsys.co.uk/Writings/x.dot.png Note: Yours might still not be on it, as yours might be one of the outliers. You can email…
I had no idea my solution would be automatically validated - I was happy enough to get an in-place O(n) solution. The complete lack of pointers on my part must be what separated me from the cluster of correct solutions at the center.
Re: Interviewing programmers: Analysis taster (work in progress)
#23Earlier quoted context omitted.
It wasn't intended for that purpose, but stand by ... EDIT: OK, I've uploaded a larger version where the labels are readable, but I've had to change the layout so the nodes don't overlap. The lengths of the edges are now not always realted to the distance, although it's approximate. http://www.solipsys.co.uk/Writings/x.dot.png Note: Yours might still not be on it, as yours might be one of the outliers. You can email…
Yeowch! Mine (g034.d) shows up as the second red dot from the left. I submitted a quick pseudocode answer without any research in an effort to mimic interview whiteboarding conditions. I had no idea my solution would be automatically validated - I was happy enough to get an in-place O(n) solution. The complete lack of pointers on my part must be what separated me from the cluster of correct solutions at the center.
As an experiment I fixed that, but you had another problem as well which also caused it to fail.
Re: Interviewing programmers: Analysis taster (work in progress)
#24Is there a full size image so I can read the labels and find my submission? :)
It wasn't intended for that purpose, but stand by ... EDIT: OK, I've uploaded a larger version where the labels are readable, but I've had to change the layout so the nodes don't overlap. The lengths of the edges are now not always realted to the distance, although it's approximate. http://www.solipsys.co.uk/Writings/x.dot.png Note: Yours might still not be on it, as yours might be one of the outliers. You can email…
Re: Interviewing programmers: Analysis taster (work in progress)
#25Re: Interviewing programmers: Analysis taster (work in progress)
#26I would expect the while loop to compile something like this:
while(condition)
{
// stuff
i++;
}
becomes loop:
if(!condition)
goto end;
// stuff
i++;
goto loop;
end:
I would expect the for loop to do this: for(;condition;i++) {
// stuff
}
becomes loop:
if(!condition)
goto end;
// stuff
i++;
goto loop;
end:
So what's actually going on?Re: Interviewing programmers: Analysis taster (work in progress)
#27I know little assembly, and am not going to attempt to pick it apart, so I can't attest to any speed difference. But as an example the first and the last compile to the same, though the last has 2 fewer instructions and some -16s changed to -24s. The first is identical to the second. The third has a bit of shuffling, but also appears identical to the first. And the last two are identical to each other (well, obviously).
How much optimization are you looking for in your C-code vs your coder's productivity? If they can get the last ones in one shot, all well and good, but if not is refactoring worth anything in this case?
edit: with -O3 optimizations on gcc, they all appear to be literally identical, the only differences I can see being variable names and the order of functions (in code, not in call order) between the first three and the last two.
Re: Interviewing programmers: Analysis taster (work in progress)
#28Is there a full size image so I can read the labels and find my submission? :)
It wasn't intended for that purpose, but stand by ... EDIT: OK, I've uploaded a larger version where the labels are readable, but I've had to change the layout so the nodes don't overlap. The lengths of the edges are now not always realted to the distance, although it's approximate. http://www.solipsys.co.uk/Writings/x.dot.png Note: Yours might still not be on it, as yours might be one of the outliers. You can email…
Edit: I suspect one of the clusters will be people like me who use array access syntax rather than pointer access.
Re: Interviewing programmers: Analysis taster (work in progress)
#29I'd be interested in an analysis of the compiled assembly for those 5 versions in 2b. A quick test on my end shows them all to be extremely similar. I know little assembly, and am not going to attempt to pick it apart, so I can't attest to any speed difference. But as an example the first and the last compile to the same, though the last has 2 fewer instructions and some -16s changed to -24s. The first is identical t…
Each of these changes is unnecessary and in some cases
damage readability. Further, a good compiler will get
most, if not all, of the efficiency for you without
making these changes.
If changes damage readability and don't change the compiled code, don't make them!Readability has to be balanced against efficiency, but too often people think something is more efficient when it isn't. As always, profile before "improving."
As I say, these are issues for discussion. Let me add at this point that some of the submitted versions, and some of my reference versions, are significantly different in both style and efficiency.
There is more to come.
Re: Interviewing programmers: Analysis taster (work in progress)
#30I'm quite familiar with C, but I don't see the difference between the while and for loops in the trivia box on article 2 of the series. I would expect the while loop to compile something like this: while(condition) { // stuff i++; } becomes loop: if(!condition) goto end; // stuff i++; goto loop; end: I would expect the for loop to do this: for(;condition;i++) { // stuff } becomes loop: if(!condition) goto end; // stu…