Saturday, April 9, 2016

HackerRank: Count strings (II)

April 9, 2016

Julia likes to have some adventure and just get into other people's solution, and quickly learn something in next 20 - 30 minutes.

Problem statement:


Statistics: time spent:  11:22am - 1:00pm

Here is the solution from a programmer working in Apple:

Code to study by Apple engineer


Comments after reading:

1. This problem is about DFA, NDFA, those content learning in Formal Language, how to build a compiler.

Friendly remind - great time to study formal language, first time for computer science master degree, score C in the course, and then in 2001 to prepare Ph.D. qualification example, Julia spent a lot of time to read the textbook again.
 

2. The string parsing is more complicate, '(', ')' should be treated as operator, and then, you can build up something.

3. Read the wiki webpage to quickly refresh knowledge
https://en.wikipedia.org/wiki/Deterministic_finite_automaton

4. Play with Visual studio and also the code - debug and run through the test case 20-30 minutes:
(ab)|(ba)  2
((a|b)*)  5

5. And put some diagram on the paper, take picture, post here and see if you can draw the state diagram for this machine.  ( 20 - 30 minutes)

Julia likes to read the code, and also debug the code;

Some facts:

1. she learned Formal language in 2001 to prepare Ph.D. qualification exam, but she never did spend time to work on an concrete example, debug the code to see how it is designed.

2. the code is well designed, and also beautiful code to read;

It is hard to figure out how to construct the Ndfa, but reading the code, Julia, you should figure out the design:




No comments:

Post a Comment