Introduction
Sorting is most basic algorithm in computer science. Here is the list of sorting algorithm on Leetcode and I like to review them.
On Nov. 15, 2017 10:00 pm, I practiced sort algorithm and my peer is a Chinese with over 10 years programming experience in USA. The peer gave me the excellent code review and made some great comments.
Let us first take a look at the overall evaluation. C# code is here.
So and So
It is my evaluation of coding on a sort algorithm. Things you should work on: No clear thought, messy coding. Here are the code review I got:
Transition from bottom up to top down
I went through bottom up approach to write a functionality of findMaxIndex by the help of whiteboard test with a simple test case: [1, 5, 4, 3, 2], I explained to the peer that I like to find index of max value of the array 5 first, and then second step is to move 5's position to the first element in the array, and then move first position to the last position of the array using flip API twice.
The peer complained that what is line 38 and line 39, it can be written as swap(arr, maxIndex + 1, subArrayLength). If you have time, then you can write the function, ask the peer if you should write the function or not, basically two flip calls.
Same story applies to line 24 to line 36.
The small research I have to do is to figure out if top-down approach is really great and I should learn. When I do not have clear solution for the algorithm, I often choose the bottom-up approach, use a simple test case to do whiteboard testing, write a working solution first. And then add on the solution. But I should not stop, need to add review, use top-down approach to extract functions, make meaningful names.
CountFound variable is not meaningful, it is better to use subarrayLength.
Argument today
You can not hide what you do at work, if you code messy at work then you will show up messy in mock interview.
No comments:
Post a Comment