# Solved > 12. Recursively implementing a DFA The diagram below:1592732 …

12. Recursively implementing a DFA

The diagram below is an example of a deterministic finite state automaton, or DFA. This particular DFA describes an algorithm to determine if a sequence of characters is a properly formatted monetary amount with commas.  For example, “\$1,000” and “\$25” and “\$551,323,991,391” are properly formatted but “1,000” (no initial \$) and “\$1000” (missing comma) and “\$5424,132” (missing comma) are not.

The DFA works by starting in the oval labeled IsMoney.  This is the initial state.  If the first character of the string is ‘\$’ then we advance to the second character and move to state 0.  Otherwise we conclude the string is not a proper monetary amount.  In state 0 if the second character is a digit between 1 and 9 then we advance to the third character and move to state 1.  Otherwise we conclude the string is not a proper monetary amount.  In state 1 if we have no more characters left in the string then we conclude that the string is a monetary amount.  This is called a final state and is indicated by a bold oval. If the third character is a digit between 0 and 9 then we advance to the fourth character and move to state 2.  Otherwise if the third character is a comma then we advance to the fourth character and move to state 4.  Otherwise we conclude the string is not a proper monetary amount. The rest of the DFA behaves in a similar manner.

Write a program that uses recursion to implement the DFA.  Your program should have a separate function for each state in the DFA.  Each function should invoke the function corresponding to the next state indicated by the arrows in the diagram.  There is mutual recursion because of the loop from state 7 to state 4.  Test your solution with several strings and output whether each string is a properly formatted monetary amount.

This solution calls a function for every character in the string.  However, the solution may be written in a tail-recursive manner so it is possible that long strings will not exhaust the stack if your compiler is efficient.

GraduateWriterHelp.com is an online academic writing platform that provides extensive assistance to graduate school students as they work through their research projects, papers and dissertations. GraduateWriterHelp.com gives students access to experienced professionals who can provide the help they need in a timely and efficient manner. The service offers a wide range of services, including editing, proofreading, formatting, researching and more that can give students the confidence they need to write the perfect paper or dissertation for their chosen subject matter.

GraduateWriterHelp.com offers a wealth of different services designed to make research projects easier for graduate school students. These include editing, proofreading, formatting and researching services, all tailored specifically for graduate-level studies such as PhDs or Master’s degrees in any field from business administration to engineering or even psychology – all with the aim of helping busy students find success in their academics without having to sacrifice other important commitments like family time or work hours towards earning a living wage outside of college hours.

Using GraduateWriterHelp.com gives you access to experts from all over the world who are highly qualified and experienced in helping graduate-level students to complete successful projects in various fields quickly and efficiently – something that would otherwise be difficult, if not impossible, given tight deadlines associated with most Ph.D./Master’s degree programs today. Moreover, using this platform makes it easier for students to keep up with multiple research tasks simultaneously since there are so many different experts available on tap at any one time – no longer will you have to put off studying one topic while focusing on another because of lack of resources! Additionally, having access to professional editors, proofreaders, but also formatters means that quality control standards aren’t sacrificed when finishing major pieces – since these individuals understand what makes up good academic writing better than anyone else and can offer guidance on how best one should go about making improvements along those lines. Finally, there is also an added cost-saving benefit associated with utilizing Graduate Writer Help compared to hiring an independent contractor (which could potentially run into thousands depending on length/complexity).
This service allows users only pay for what students need, which tends to be much lower overall because customers pay per hour rather than project basis, thus resulting to greater financial flexibility, especially for those just starting out postgraduate studies looking to conserve some pennies here there whenever possible!

## Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
\$26
The price is based on these factors:
Number of pages
Urgency
Basic features
• Free title page and bibliography
• Unlimited revisions
• Plagiarism-free guarantee
• Money-back guarantee
On-demand options
• Writer’s samples
• Part-by-part delivery
• Overnight delivery
• Copies of used sources
Paper format
• 275 words per page
• 12 pt Arial/Times New Roman
• Double line spacing
• Any citation style (APA, MLA, Chicago/Turabian, Harvard)

# Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

### Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

### Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

### Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.