Sunday, May 27, 2018

Breadth first search distributed algorithm - 6th mock interview from the coach


Introduction


It is my most favorite algorithm May 2018. I was surprised to spend more than one hour to write the C# code and also fixed my original design issue. My design was kind of weak until I tried to test the third test case with 4 x 4 matrix. I found out the answer is not correct. For some reason, the current layer of node will get into next round when I apply breadth first search. Later, I added a hashset to exclude the current layer node to get into next round.

The algorithm is so ineresting and I remmebered that I worked on the similar algorithm called shortest distance to all building.


Algorithm 


I wrote a breadth first search algorithm based on my coach's hint. Find all elements in the matrix with zero value first, put all of them in the queue, and then process breadth first search on those elements in the same time.

It is kind of distributed algorithm. I like the challenge. I feel excited after I complete the algorithm.

Here is my mock interview transcript.

Here is my C# code after mock interview.



No comments:

Post a Comment