Showing posts with label H-Tree. Show all posts
Showing posts with label H-Tree. Show all posts

Sunday, April 29, 2018

Being interviewee: H-tree

April 29, 2018

Introduction


It was so nice to have a mock interview at 10:00 PM. I had chance to work on H-tree algorithm, and then I wrote a test case based on the advice of the peer. The peer finished his algorithm open bracket less than 7 minutes, I said so many good things about his performance; and then I told him that once I finish my algorithm, I will ask him a few algorithms and see how good he is. I finished my algorithm in less than 20 minutes.

Mock interview


Here is my C# code.


Saturday, February 10, 2018

Say hi to New York again

Feb. 20, 2018

Introduction


It is true that I met a peer from New York this morning 12:00 PM mock interview. I already met over 10 people from New York. I started to learn one thing a time from people working in New York industry.

It is fun and also people are more active to reach out to other people as well.

New York style


I did hear a few things about New York. How things work in the city of New York. Today I also learned a few things through discussion of JavaScript coding of a H-tree algorithm.

Here is JavaScript code.

Since the peer told me that he has over 10 - 12 years ruby on rail experience, so I asked him the question how he designed the JavaScript function, basically it is like functional programming style. const drawHTree = (x, y, length, depth) => {. 

I asked the peer to extract variable top_y, bottom_y, left_x, right_x four variable, and then I asked the peer to write to DrawLine the length of line and declare a variable for totalLines. 

I asked the peer to  count how many H-tree by steps, and then he quickly came out the time complexity. 





Saturday, January 20, 2018

H tree

January 20, 2018

Introduction


It is the classical recursive algorithm. I had 4:00 pm mock interview and then I had to write H-tree algorithm. It took me exactly 30 minutes to finish the analysis and also coding. I made a mistake in the writing first, draw one H tree first, and then call recursive tree four times for each corners of H-tree.


Code review


Here is the code.

Compared to last practice


Here is my practice in Dec. 2017. The code is almost exactly same. Only difference is that this time I work on the analysis of the algorithm, write down given constraints, and problem to solve. Write down the solution first before I write the code.

I need to work on the structure of recursive function, base case, inductive step. Please write down those steps in analysis first.

  if depth == 0
  return

  // draw one H-tree
  draw horizontal line
  draw vertical left line
  draw vertical right line

 // inductive step
 4  recursive function call for each corner of H-tree
 left top
 right top
 right bottom
 left bottom

Because my first writing in mock interview today has wrong logic like the following:

 if depth == 0
  return

  if(depth == 1)
 {
  // draw one H-tree
  draw horizontal line
  draw vertical left line
  draw vertical right line

  return; 
 }

 // inductive step
 4  recursive function call for each corner of H-tree
 left top
 right top
 right bottom
 left bottom

I found the bug in whiteboard testing and then I fixed it. But I should understand base case 100% before I write the code.

Tuesday, December 26, 2017

H-Tree recursive solution

Dec. 26, 2017

Introduction


I had a mock interview at 6 PM this evening and then I met a programmer who prepared a test case for my algorithm. I felt that the peer is the very good programmer and then I gave a lot of feedback on his coding review as well.

Here is my C# code to write a recursive function to implement H-tree.


Saturday, April 8, 2017

H tree - a talk about training

April 8, 2017

H-tree is constructed by layers, next layer will start from four corners of H as centers, and the size will be smaller one.

Problem statement - Read this Java implementation from princinton.edu - H-Tree

Introduction


Julia started to study mocking interview, and see how many things she should work on. Instead of writing a simple recursion version, Julia chose to write a BFS solution using queue. It is a good practice and also showed her passion to write a solution and learned from her mistakes on the mocking.

Training review 


Here is the C# code she wrote in mocking 30 minutes.

Spent over one hour to make the C# code bug-free and code readable.
Also, line 83, correct the calculation of length using square root 2. C# code is here.
Again, make variable names shortest, line 90 - 95. C# code is here.
Things learned in the mocking experience:

1. Julia thought out loud using queue to implement the solution, the interviewer gave out hints to use stack, depth first search;

2. Julia thought about using stack but forgot about recursive function is a natural stack; in other words, using simple recursive function call.

BFS/ DFS difference - DFS can use recursive call, internal stack.

3. Using Queue will work, but the depth should be pushed with queue with center node's information.

4. It is important to stay calm, write instructional code.

Highlight of good/ bad things in mocking experience
(the C# code in mocking experience, good thing is highlighted using brown color, bugs and mistakes are in yellow color):

0. line 1 - 12 work on a H-tree understanding, write a small test case. Understand the H-Tree draw lines, and also requirement of starting length and depth.
1. line 18 - 27, write an internal class Node, define two variables, node and depth.
2. line 22 - 26, Write public constructor of Node class to set up a new node
3.  line 30, Function name is very good - DrawHTreeToDepthUsingBFS
4.  line 30, Function DrawHTreeToDepthUsingBFS's design flaw - return argument should be IList<Node>, not IList<Tuple<int,int>>, missing depth information. Depth information is needed to calculate length of H-Tree.
5. line 29, time complexity is correct? Need to write a recurrence formula first, and then time complexity.
6. line 34 - 37, depth <= 0 will be better
6B. line 39 - syntax error - duplicate new Node(
7. line 41 - Enqueue method - input argument should be variable - node
8. line 43 - adjustLength = depth;  should be adjustLength = startLength, mix length and depth two variables
9. line 57 - 64, should add checking of depth, add H-tree is conditional - major issue
10. line 57 - 60, 4 corners of H, new center node's x, y values are not correct.


Julia, you have to learn from tennis training coach - Janko Tipsarevic - train yourself to be able to write a bug-free, very instructional code. When in real matches, a lot of emotions are mixed with pressures, will to win, anxiety and pressure, you will not notice those mistakes and errors.

Next time, try to write much more slowly, make sure that every line of code is bug-free, syntax ok, no duplicate code.

Through this mocking experience, Julia learned that she still had to practice more on BFS algorithm using Queue, Julia was very comfortable to write and understood that either BFS/ DFS will work out with no problem.

Julia did not have time to go over the code because the peer did not want to wait after 30 minutes.

Also, Julia did not come out using recursive function to write, even after hints. Julia was nervous because she asked help to understand H-Tree with the test case.

Julia likes to show her rigor training through asking over 30 algorithm questions she got from codereview.stackexchange.com code reviews last 6 months, she is able to write perfect and most modern C# code.

Actionable Items


1. Learn to interview people with different background, technical strength; Learn to write down notes and give out good advice.

2. Do not book more than one mocking a time.

3. Try to improve score of problem solving skills, ratings are low 3 of 7.

4. Take it slow, write instructional code, avoid duplicate code. Using meaningful variable name, function name.


5. Go through up-and-downs through mocking experience, learn to appreciate the time of peer. Try to
manage better the 30 minutes time. Avoid lengthy discussion, be very diplomatic, writing is most important part to show good skills and analysis.

6. Work on a small test case first, this part is very good warmup and prevent bugs in writing and design correctly first time.

7. Make the mocking experience more structured, write down a small test case to understand the problem, show some analysis, and talk about design and choices I may have.

8. All issues Julia had on real experience are reproduced in this mocking experience. Julia, practice more. Do not give up. Write down your feelings, and issues. You will sort it out later.

Follow up 


June 19, 2017 mocking third time. Very short and clean, using recursive function, using meaningful name. C# practice is here.