Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:51:37+00:00 2026-06-11T12:51:37+00:00

Question: Define a DFA that accepts all strings over {0,1} such that every block

  • 0

Question:

Define a DFA that accepts all strings over {0,1} such that every block of five consecutive positions contains at least two 0s. Please read the question carefully. Ask yourselves: Does this allow e (epsilon (empty string)) to be accepted? How about 0101? Such English descriptions are found in various books, and I want to make sure you know how to read and interpret.

Instructor Hint: “The “blocks of 5″ DFA can be programmatically generated without much trouble. I did it both ways (by hand and programmatically). Because I’m good with Emacs and Keyboard Macros, I could do even the ‘by hand’ mechanically and quite fast. But programmatic is less error-prone and compact.”


I’m drawing this thing out, and I think I’m doing it wrong, as it is getting out of control.

My sketch of the DFA before I make it in python:
enter image description here

However, this isn’t right, because index 2, 3, 4, 5, and 6 constitute a block of five consecutive positions, so I need to account for at least two zeroes in that. Oh, great, and I have been thinking it needs two 1s, not two 0s. Am I going about this the entirely wrong way? Because the way I’m thinking, this is going to have a huge amount of states.

(goes back to drawing this large DFA)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:51:38+00:00Added an answer on June 11, 2026 at 12:51 pm

    If you want to do it the old school way:

    def check(s):
        buffer = s[:5]
        i = 5
        count0, count1 = 0, 0
        while i < len(s):
            if len(buffer) == 5:
                first = buffer[0]
                if first == '0':
                    count0 -= 1
                else:
                    count1 -= 1
                buffer = buffer[1:]
            buffer += s[i]
            if buffer[-1] == '0':
                count0 += 1
            else:
                count1 += 1
            if count0 < 2:
                return "REJECT"
            i += 1
        if buffer.count('0') >= 2:
            return "ACCEPT"
        else:
            return "REJECT"
    

    A slightly smarter way:

    def check(s):
        return all(ss.count('0')>=2 for ss in (s[i:i+5] for i in xrange(len(s)-4)))
    

    The verbose code of the above method:

    def check(s):
        subs = (s[i:i+5] for i in xrange(len(s)-4))
        for sub in subs:
            if sub.count('0') < 2:
                return "REJECT"
        return "ACCEPT"
    

    Haven’t tested this code, but it should likely work. Your professor probably wants the third method.

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully this is an easy question. How can I define an XML type such
From another question I have learnt that it is possible in Java to define
Random question that crossed my mind: If I define an array in PHP like
first question: Define a function that joins a list of lists together using a
Question : What is the proper way to define a function in JavaScript that
Simple question here. I have to define classes that will contain sets of books,
Quick question: When you define, in your ORM column definition, that a column is
Question in SSAS for y'all. I am attempting to define a One to Many
I've been given the question: Define a predicate ordered/1, which checks if a list
Question Is there a way to define a method only once in C# (in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.