Do I need to consider instance restrictions when showing a language is in P?Decision problem and algorithmShowing a language is in co-NPCDo Turing machines assume something infinite at some point?Is deciding whether the language of a TM contains all strings of length 4 computable?Proving that a language is not RecursiveUndecidable vs Unsolvable?In which direction should I carry out a reduction when proving decidability/recognizability?The defining property of problems in NPIs there a polynomial time algorithm to determine whether an 'up down' language is 'emptible'?Define the following problem as a language and prove that it is undecidable with a reduction from the halting problem.

Four married couples attend a party. Each person shakes hands with every other person, except their own spouse, exactly once. How many handshakes?

In the 1924 version of The Thief of Bagdad, no character is named, right?

A Ri-diddley-iley Riddle

Why is there so much iron?

PTIJ What is the inyan of the Konami code in Uncle Moishy's song?

Recruiter wants very extensive technical details about all of my previous work

Could this Scherzo by Beethoven be considered to be a fugue?

TikZ-decoration: control decoration amplitude along curve

T-SQL LIKE Predicate failed to match with whitespace in XML converted varchar

Is there a term for accumulated dirt on the outside of your hands and feet?

Open new file while keeping the focus on the the current buffer

Deletion of copy-ctor & copy-assignment - public, private or protected?

Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?

Have the tides ever turned twice on any open problem?

Is it correct to say "which country do you like the most?"

Why did it take so long to abandon sail after steamships were demonstrated?

What can I do if I am asked to learn different programming languages very frequently?

How do I use long payment IDs in CLI v0.14 / GUI v0.14?

Why Choose Less Effective Armour Types?

While on vacation my taxi took a longer route, possibly to scam me out of money. How can I deal with this?

Brake pads destroying wheels

How to define limit operations in general topological spaces? Are nets able to do this?

How can my new character not be a role-playing handicap to the party?

Describing a chess game in a novel



Do I need to consider instance restrictions when showing a language is in P?


Decision problem and algorithmShowing a language is in co-NPCDo Turing machines assume something infinite at some point?Is deciding whether the language of a TM contains all strings of length 4 computable?Proving that a language is not RecursiveUndecidable vs Unsolvable?In which direction should I carry out a reduction when proving decidability/recognizability?The defining property of problems in NPIs there a polynomial time algorithm to determine whether an 'up down' language is 'emptible'?Define the following problem as a language and prove that it is undecidable with a reduction from the halting problem.













2












$begingroup$


I have already shown that 3-colorable for an unrestricted graph is in NP, but I was thinking about the similar language defined as the set of all acyclic $G$, where $G$ such that $G$ is 3-colorable. In my proposition of an algorithm in P, I wasn't sure if my algorithm needs to verify that $G$ indeed contains no cycle or if I assume all inputs are instances of this language (assume all inputs are acyclic graphs). In general, I was wondering if my algorithm has to decide whether the input is of the desired instance ON TOP OF actually showing the properties of the language can be done in polynomial time. I'm still learning so I am confused about this part and this has been bugging me for a while.



If this question is too confusing, consider 3SAT. Must I show that verifying the input is indeed a 3CNF is in P to conclude, or can I assume we are only considering inputs within an instance?










share|cite|improve this question









New contributor




Jahar Mehru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$
















    2












    $begingroup$


    I have already shown that 3-colorable for an unrestricted graph is in NP, but I was thinking about the similar language defined as the set of all acyclic $G$, where $G$ such that $G$ is 3-colorable. In my proposition of an algorithm in P, I wasn't sure if my algorithm needs to verify that $G$ indeed contains no cycle or if I assume all inputs are instances of this language (assume all inputs are acyclic graphs). In general, I was wondering if my algorithm has to decide whether the input is of the desired instance ON TOP OF actually showing the properties of the language can be done in polynomial time. I'm still learning so I am confused about this part and this has been bugging me for a while.



    If this question is too confusing, consider 3SAT. Must I show that verifying the input is indeed a 3CNF is in P to conclude, or can I assume we are only considering inputs within an instance?










    share|cite|improve this question









    New contributor




    Jahar Mehru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      2












      2








      2





      $begingroup$


      I have already shown that 3-colorable for an unrestricted graph is in NP, but I was thinking about the similar language defined as the set of all acyclic $G$, where $G$ such that $G$ is 3-colorable. In my proposition of an algorithm in P, I wasn't sure if my algorithm needs to verify that $G$ indeed contains no cycle or if I assume all inputs are instances of this language (assume all inputs are acyclic graphs). In general, I was wondering if my algorithm has to decide whether the input is of the desired instance ON TOP OF actually showing the properties of the language can be done in polynomial time. I'm still learning so I am confused about this part and this has been bugging me for a while.



      If this question is too confusing, consider 3SAT. Must I show that verifying the input is indeed a 3CNF is in P to conclude, or can I assume we are only considering inputs within an instance?










      share|cite|improve this question









      New contributor




      Jahar Mehru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I have already shown that 3-colorable for an unrestricted graph is in NP, but I was thinking about the similar language defined as the set of all acyclic $G$, where $G$ such that $G$ is 3-colorable. In my proposition of an algorithm in P, I wasn't sure if my algorithm needs to verify that $G$ indeed contains no cycle or if I assume all inputs are instances of this language (assume all inputs are acyclic graphs). In general, I was wondering if my algorithm has to decide whether the input is of the desired instance ON TOP OF actually showing the properties of the language can be done in polynomial time. I'm still learning so I am confused about this part and this has been bugging me for a while.



      If this question is too confusing, consider 3SAT. Must I show that verifying the input is indeed a 3CNF is in P to conclude, or can I assume we are only considering inputs within an instance?







      turing-machines time-complexity terminology






      share|cite|improve this question









      New contributor




      Jahar Mehru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|cite|improve this question









      New contributor




      Jahar Mehru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|cite|improve this question




      share|cite|improve this question








      edited 3 hours ago







      Jahar Mehru













      New contributor




      Jahar Mehru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      Jahar MehruJahar Mehru

      133




      133




      New contributor




      Jahar Mehru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Jahar Mehru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Jahar Mehru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes


















          2












          $begingroup$


          I was wondering if my algorithm has to decide whether the input is of the desired instance ON TOP OF actually showing the properties of the language can be done in polynomial time.




          Very nice question!



          What you are talking about is best characterized as promise problem, "a generalization of a decision problem where the input is promised to belong to a particular subset of all possible inputs". The convention way to handle promise problem is there are no requirements on the output if the input does not belong to the promise. In particular, if you want to show a promise problem is in P of promise problems, your algorithm do not need to check whether the input is valid or not and your algorithm can behave arbitrarily if the input is invalid.



          For an in-depth discussion on promise problems, you are encouraged to read Oded Goldreich's exposition [On Promise Problems], July 11, 2005.



          However, if you want to show a promise problem is in P, your algorithm must check whether the input is valid or not and, if the input is invalid, a.k.a as a noninstance, output 0. Here P stands for the complexity class that have been talked about the most, a.k.a. P of decision problems, i.e. PTIME or DTIME$(n^O(1))$ as defined at Wikipedia, or the complexity class P as defined in section 34.1 Polynomial time of the popular textbook introduction to algorithm by CLRS, version 3.



          Take 3SAT for an example. An algorithm that show 3SAT is in P (of decision problems) should check whether each clause is a conjunctive normal form with at most three literals and many other restrictions. The algorithm should output 0 if it finds the input is not a valid instance of 3SAT.



          It is easy to check whether a problem instance is a valid instance or not in almost all decision problems that have been discussed. It is so easy and so common that people have become so sloppy (or efficient) that this verification step is usually skipped or even forgotten in the specification of an algorithm. That might be the source of your confusion.



          I would recommend beginners to write clearly this verification steps for the first few occasions before joining the common practice.






          share|cite|improve this answer











          $endgroup$












          • $begingroup$
            This is EXACTLY what I was looking for. Thank you so much! My mind is now at ease.
            $endgroup$
            – Jahar Mehru
            2 hours ago


















          1












          $begingroup$

          The answer depends on exactly what problem you're solving.



          • If your goal is to produce an algorithm that correctly solves the problem on the restricted instances, then it's kind of up to you whether or not you check. It feels more robust to check the input but it's perfectly reasonable not to, and that puts you in the realm of promise problems. Here, the "user" promises that the input is valid, and you just have to determine whether the answer is yes or no.


          • If your goal is to produce an algorithm that decides whether the input is, e.g., a satisfiable 3CNF then, yes, you do need to check that the input has the properties it's supposed to have.


          Your example of 3-colourability for acyclic graphs shows that there can be a big difference between the two approaches. Every acyclic graph is 3-colourable (even 2-colourable) so the algorithm for the promise problem is just output "yes". For the non-promise version, you need to check that your input is a valid graph representation, then check that the graph is acyclic, and only say "yes" if the input passes both tests.



          In practical terms, most descriptions of graph algorithms tend to assume that the input is a valid encoding of a graph – it gets a bit tedious writing "Check the input is a valid encoding of a graph" as the first line of every algorithm!






          share|cite|improve this answer









          $endgroup$












          • $begingroup$
            I had almost finished adding more explanation when I clicked the link "there is an update to this answer ...". Oops, all my edit were gone. I had to write again. Of course, thanks for your update to my answer! (I will delete this comment shortly.)
            $endgroup$
            – Apass.Jack
            46 mins ago











          • $begingroup$
            @Apass.Jack Oh no! I hate it when that happens. I try to remember to copy everything to the clipboard before clicking that notification but I often forget. It really ougth to warn you that you'll lose all your edits if you click that appealing-looking link. I'm sorry I stepped on your toes!
            $endgroup$
            – David Richerby
            37 mins ago










          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "419"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Jahar Mehru is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f105692%2fdo-i-need-to-consider-instance-restrictions-when-showing-a-language-is-in-p%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2












          $begingroup$


          I was wondering if my algorithm has to decide whether the input is of the desired instance ON TOP OF actually showing the properties of the language can be done in polynomial time.




          Very nice question!



          What you are talking about is best characterized as promise problem, "a generalization of a decision problem where the input is promised to belong to a particular subset of all possible inputs". The convention way to handle promise problem is there are no requirements on the output if the input does not belong to the promise. In particular, if you want to show a promise problem is in P of promise problems, your algorithm do not need to check whether the input is valid or not and your algorithm can behave arbitrarily if the input is invalid.



          For an in-depth discussion on promise problems, you are encouraged to read Oded Goldreich's exposition [On Promise Problems], July 11, 2005.



          However, if you want to show a promise problem is in P, your algorithm must check whether the input is valid or not and, if the input is invalid, a.k.a as a noninstance, output 0. Here P stands for the complexity class that have been talked about the most, a.k.a. P of decision problems, i.e. PTIME or DTIME$(n^O(1))$ as defined at Wikipedia, or the complexity class P as defined in section 34.1 Polynomial time of the popular textbook introduction to algorithm by CLRS, version 3.



          Take 3SAT for an example. An algorithm that show 3SAT is in P (of decision problems) should check whether each clause is a conjunctive normal form with at most three literals and many other restrictions. The algorithm should output 0 if it finds the input is not a valid instance of 3SAT.



          It is easy to check whether a problem instance is a valid instance or not in almost all decision problems that have been discussed. It is so easy and so common that people have become so sloppy (or efficient) that this verification step is usually skipped or even forgotten in the specification of an algorithm. That might be the source of your confusion.



          I would recommend beginners to write clearly this verification steps for the first few occasions before joining the common practice.






          share|cite|improve this answer











          $endgroup$












          • $begingroup$
            This is EXACTLY what I was looking for. Thank you so much! My mind is now at ease.
            $endgroup$
            – Jahar Mehru
            2 hours ago















          2












          $begingroup$


          I was wondering if my algorithm has to decide whether the input is of the desired instance ON TOP OF actually showing the properties of the language can be done in polynomial time.




          Very nice question!



          What you are talking about is best characterized as promise problem, "a generalization of a decision problem where the input is promised to belong to a particular subset of all possible inputs". The convention way to handle promise problem is there are no requirements on the output if the input does not belong to the promise. In particular, if you want to show a promise problem is in P of promise problems, your algorithm do not need to check whether the input is valid or not and your algorithm can behave arbitrarily if the input is invalid.



          For an in-depth discussion on promise problems, you are encouraged to read Oded Goldreich's exposition [On Promise Problems], July 11, 2005.



          However, if you want to show a promise problem is in P, your algorithm must check whether the input is valid or not and, if the input is invalid, a.k.a as a noninstance, output 0. Here P stands for the complexity class that have been talked about the most, a.k.a. P of decision problems, i.e. PTIME or DTIME$(n^O(1))$ as defined at Wikipedia, or the complexity class P as defined in section 34.1 Polynomial time of the popular textbook introduction to algorithm by CLRS, version 3.



          Take 3SAT for an example. An algorithm that show 3SAT is in P (of decision problems) should check whether each clause is a conjunctive normal form with at most three literals and many other restrictions. The algorithm should output 0 if it finds the input is not a valid instance of 3SAT.



          It is easy to check whether a problem instance is a valid instance or not in almost all decision problems that have been discussed. It is so easy and so common that people have become so sloppy (or efficient) that this verification step is usually skipped or even forgotten in the specification of an algorithm. That might be the source of your confusion.



          I would recommend beginners to write clearly this verification steps for the first few occasions before joining the common practice.






          share|cite|improve this answer











          $endgroup$












          • $begingroup$
            This is EXACTLY what I was looking for. Thank you so much! My mind is now at ease.
            $endgroup$
            – Jahar Mehru
            2 hours ago













          2












          2








          2





          $begingroup$


          I was wondering if my algorithm has to decide whether the input is of the desired instance ON TOP OF actually showing the properties of the language can be done in polynomial time.




          Very nice question!



          What you are talking about is best characterized as promise problem, "a generalization of a decision problem where the input is promised to belong to a particular subset of all possible inputs". The convention way to handle promise problem is there are no requirements on the output if the input does not belong to the promise. In particular, if you want to show a promise problem is in P of promise problems, your algorithm do not need to check whether the input is valid or not and your algorithm can behave arbitrarily if the input is invalid.



          For an in-depth discussion on promise problems, you are encouraged to read Oded Goldreich's exposition [On Promise Problems], July 11, 2005.



          However, if you want to show a promise problem is in P, your algorithm must check whether the input is valid or not and, if the input is invalid, a.k.a as a noninstance, output 0. Here P stands for the complexity class that have been talked about the most, a.k.a. P of decision problems, i.e. PTIME or DTIME$(n^O(1))$ as defined at Wikipedia, or the complexity class P as defined in section 34.1 Polynomial time of the popular textbook introduction to algorithm by CLRS, version 3.



          Take 3SAT for an example. An algorithm that show 3SAT is in P (of decision problems) should check whether each clause is a conjunctive normal form with at most three literals and many other restrictions. The algorithm should output 0 if it finds the input is not a valid instance of 3SAT.



          It is easy to check whether a problem instance is a valid instance or not in almost all decision problems that have been discussed. It is so easy and so common that people have become so sloppy (or efficient) that this verification step is usually skipped or even forgotten in the specification of an algorithm. That might be the source of your confusion.



          I would recommend beginners to write clearly this verification steps for the first few occasions before joining the common practice.






          share|cite|improve this answer











          $endgroup$




          I was wondering if my algorithm has to decide whether the input is of the desired instance ON TOP OF actually showing the properties of the language can be done in polynomial time.




          Very nice question!



          What you are talking about is best characterized as promise problem, "a generalization of a decision problem where the input is promised to belong to a particular subset of all possible inputs". The convention way to handle promise problem is there are no requirements on the output if the input does not belong to the promise. In particular, if you want to show a promise problem is in P of promise problems, your algorithm do not need to check whether the input is valid or not and your algorithm can behave arbitrarily if the input is invalid.



          For an in-depth discussion on promise problems, you are encouraged to read Oded Goldreich's exposition [On Promise Problems], July 11, 2005.



          However, if you want to show a promise problem is in P, your algorithm must check whether the input is valid or not and, if the input is invalid, a.k.a as a noninstance, output 0. Here P stands for the complexity class that have been talked about the most, a.k.a. P of decision problems, i.e. PTIME or DTIME$(n^O(1))$ as defined at Wikipedia, or the complexity class P as defined in section 34.1 Polynomial time of the popular textbook introduction to algorithm by CLRS, version 3.



          Take 3SAT for an example. An algorithm that show 3SAT is in P (of decision problems) should check whether each clause is a conjunctive normal form with at most three literals and many other restrictions. The algorithm should output 0 if it finds the input is not a valid instance of 3SAT.



          It is easy to check whether a problem instance is a valid instance or not in almost all decision problems that have been discussed. It is so easy and so common that people have become so sloppy (or efficient) that this verification step is usually skipped or even forgotten in the specification of an algorithm. That might be the source of your confusion.



          I would recommend beginners to write clearly this verification steps for the first few occasions before joining the common practice.







          share|cite|improve this answer














          share|cite|improve this answer



          share|cite|improve this answer








          edited 56 mins ago

























          answered 3 hours ago









          Apass.JackApass.Jack

          12.8k1939




          12.8k1939











          • $begingroup$
            This is EXACTLY what I was looking for. Thank you so much! My mind is now at ease.
            $endgroup$
            – Jahar Mehru
            2 hours ago
















          • $begingroup$
            This is EXACTLY what I was looking for. Thank you so much! My mind is now at ease.
            $endgroup$
            – Jahar Mehru
            2 hours ago















          $begingroup$
          This is EXACTLY what I was looking for. Thank you so much! My mind is now at ease.
          $endgroup$
          – Jahar Mehru
          2 hours ago




          $begingroup$
          This is EXACTLY what I was looking for. Thank you so much! My mind is now at ease.
          $endgroup$
          – Jahar Mehru
          2 hours ago











          1












          $begingroup$

          The answer depends on exactly what problem you're solving.



          • If your goal is to produce an algorithm that correctly solves the problem on the restricted instances, then it's kind of up to you whether or not you check. It feels more robust to check the input but it's perfectly reasonable not to, and that puts you in the realm of promise problems. Here, the "user" promises that the input is valid, and you just have to determine whether the answer is yes or no.


          • If your goal is to produce an algorithm that decides whether the input is, e.g., a satisfiable 3CNF then, yes, you do need to check that the input has the properties it's supposed to have.


          Your example of 3-colourability for acyclic graphs shows that there can be a big difference between the two approaches. Every acyclic graph is 3-colourable (even 2-colourable) so the algorithm for the promise problem is just output "yes". For the non-promise version, you need to check that your input is a valid graph representation, then check that the graph is acyclic, and only say "yes" if the input passes both tests.



          In practical terms, most descriptions of graph algorithms tend to assume that the input is a valid encoding of a graph – it gets a bit tedious writing "Check the input is a valid encoding of a graph" as the first line of every algorithm!






          share|cite|improve this answer









          $endgroup$












          • $begingroup$
            I had almost finished adding more explanation when I clicked the link "there is an update to this answer ...". Oops, all my edit were gone. I had to write again. Of course, thanks for your update to my answer! (I will delete this comment shortly.)
            $endgroup$
            – Apass.Jack
            46 mins ago











          • $begingroup$
            @Apass.Jack Oh no! I hate it when that happens. I try to remember to copy everything to the clipboard before clicking that notification but I often forget. It really ougth to warn you that you'll lose all your edits if you click that appealing-looking link. I'm sorry I stepped on your toes!
            $endgroup$
            – David Richerby
            37 mins ago















          1












          $begingroup$

          The answer depends on exactly what problem you're solving.



          • If your goal is to produce an algorithm that correctly solves the problem on the restricted instances, then it's kind of up to you whether or not you check. It feels more robust to check the input but it's perfectly reasonable not to, and that puts you in the realm of promise problems. Here, the "user" promises that the input is valid, and you just have to determine whether the answer is yes or no.


          • If your goal is to produce an algorithm that decides whether the input is, e.g., a satisfiable 3CNF then, yes, you do need to check that the input has the properties it's supposed to have.


          Your example of 3-colourability for acyclic graphs shows that there can be a big difference between the two approaches. Every acyclic graph is 3-colourable (even 2-colourable) so the algorithm for the promise problem is just output "yes". For the non-promise version, you need to check that your input is a valid graph representation, then check that the graph is acyclic, and only say "yes" if the input passes both tests.



          In practical terms, most descriptions of graph algorithms tend to assume that the input is a valid encoding of a graph – it gets a bit tedious writing "Check the input is a valid encoding of a graph" as the first line of every algorithm!






          share|cite|improve this answer









          $endgroup$












          • $begingroup$
            I had almost finished adding more explanation when I clicked the link "there is an update to this answer ...". Oops, all my edit were gone. I had to write again. Of course, thanks for your update to my answer! (I will delete this comment shortly.)
            $endgroup$
            – Apass.Jack
            46 mins ago











          • $begingroup$
            @Apass.Jack Oh no! I hate it when that happens. I try to remember to copy everything to the clipboard before clicking that notification but I often forget. It really ougth to warn you that you'll lose all your edits if you click that appealing-looking link. I'm sorry I stepped on your toes!
            $endgroup$
            – David Richerby
            37 mins ago













          1












          1








          1





          $begingroup$

          The answer depends on exactly what problem you're solving.



          • If your goal is to produce an algorithm that correctly solves the problem on the restricted instances, then it's kind of up to you whether or not you check. It feels more robust to check the input but it's perfectly reasonable not to, and that puts you in the realm of promise problems. Here, the "user" promises that the input is valid, and you just have to determine whether the answer is yes or no.


          • If your goal is to produce an algorithm that decides whether the input is, e.g., a satisfiable 3CNF then, yes, you do need to check that the input has the properties it's supposed to have.


          Your example of 3-colourability for acyclic graphs shows that there can be a big difference between the two approaches. Every acyclic graph is 3-colourable (even 2-colourable) so the algorithm for the promise problem is just output "yes". For the non-promise version, you need to check that your input is a valid graph representation, then check that the graph is acyclic, and only say "yes" if the input passes both tests.



          In practical terms, most descriptions of graph algorithms tend to assume that the input is a valid encoding of a graph – it gets a bit tedious writing "Check the input is a valid encoding of a graph" as the first line of every algorithm!






          share|cite|improve this answer









          $endgroup$



          The answer depends on exactly what problem you're solving.



          • If your goal is to produce an algorithm that correctly solves the problem on the restricted instances, then it's kind of up to you whether or not you check. It feels more robust to check the input but it's perfectly reasonable not to, and that puts you in the realm of promise problems. Here, the "user" promises that the input is valid, and you just have to determine whether the answer is yes or no.


          • If your goal is to produce an algorithm that decides whether the input is, e.g., a satisfiable 3CNF then, yes, you do need to check that the input has the properties it's supposed to have.


          Your example of 3-colourability for acyclic graphs shows that there can be a big difference between the two approaches. Every acyclic graph is 3-colourable (even 2-colourable) so the algorithm for the promise problem is just output "yes". For the non-promise version, you need to check that your input is a valid graph representation, then check that the graph is acyclic, and only say "yes" if the input passes both tests.



          In practical terms, most descriptions of graph algorithms tend to assume that the input is a valid encoding of a graph – it gets a bit tedious writing "Check the input is a valid encoding of a graph" as the first line of every algorithm!







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered 1 hour ago









          David RicherbyDavid Richerby

          68.5k15103194




          68.5k15103194











          • $begingroup$
            I had almost finished adding more explanation when I clicked the link "there is an update to this answer ...". Oops, all my edit were gone. I had to write again. Of course, thanks for your update to my answer! (I will delete this comment shortly.)
            $endgroup$
            – Apass.Jack
            46 mins ago











          • $begingroup$
            @Apass.Jack Oh no! I hate it when that happens. I try to remember to copy everything to the clipboard before clicking that notification but I often forget. It really ougth to warn you that you'll lose all your edits if you click that appealing-looking link. I'm sorry I stepped on your toes!
            $endgroup$
            – David Richerby
            37 mins ago
















          • $begingroup$
            I had almost finished adding more explanation when I clicked the link "there is an update to this answer ...". Oops, all my edit were gone. I had to write again. Of course, thanks for your update to my answer! (I will delete this comment shortly.)
            $endgroup$
            – Apass.Jack
            46 mins ago











          • $begingroup$
            @Apass.Jack Oh no! I hate it when that happens. I try to remember to copy everything to the clipboard before clicking that notification but I often forget. It really ougth to warn you that you'll lose all your edits if you click that appealing-looking link. I'm sorry I stepped on your toes!
            $endgroup$
            – David Richerby
            37 mins ago















          $begingroup$
          I had almost finished adding more explanation when I clicked the link "there is an update to this answer ...". Oops, all my edit were gone. I had to write again. Of course, thanks for your update to my answer! (I will delete this comment shortly.)
          $endgroup$
          – Apass.Jack
          46 mins ago





          $begingroup$
          I had almost finished adding more explanation when I clicked the link "there is an update to this answer ...". Oops, all my edit were gone. I had to write again. Of course, thanks for your update to my answer! (I will delete this comment shortly.)
          $endgroup$
          – Apass.Jack
          46 mins ago













          $begingroup$
          @Apass.Jack Oh no! I hate it when that happens. I try to remember to copy everything to the clipboard before clicking that notification but I often forget. It really ougth to warn you that you'll lose all your edits if you click that appealing-looking link. I'm sorry I stepped on your toes!
          $endgroup$
          – David Richerby
          37 mins ago




          $begingroup$
          @Apass.Jack Oh no! I hate it when that happens. I try to remember to copy everything to the clipboard before clicking that notification but I often forget. It really ougth to warn you that you'll lose all your edits if you click that appealing-looking link. I'm sorry I stepped on your toes!
          $endgroup$
          – David Richerby
          37 mins ago










          Jahar Mehru is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          Jahar Mehru is a new contributor. Be nice, and check out our Code of Conduct.












          Jahar Mehru is a new contributor. Be nice, and check out our Code of Conduct.











          Jahar Mehru is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Computer Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f105692%2fdo-i-need-to-consider-instance-restrictions-when-showing-a-language-is-in-p%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Era Viking Índice Início da Era Viquingue | Cotidiano | Sociedade | Língua | Religião | A arte | As primeiras cidades | As viagens dos viquingues | Viquingues do Oeste e Leste | Fim da Era Viquingue | Fontes históricas | Referências Bibliografia | Ligações externas | Menu de navegação«Sverige då!»«Handel I vikingetid»«O que é Nórdico Antigo»Mito, magia e religião na volsunga saga Um olhar sobre a trajetória mítica do herói sigurd«Bonden var den verklige vikingen»«Vikingatiden»«Vikingatiden»«Vinland»«Guerreiras de Óðinn: As Valkyrjor na Mitologia Viking»1519-9053«Esculpindo símbolos e seres: A arte viking em pedras rúnicas»1679-9313Historia - Tema: VikingarnaAventura e Magia no Mundo das Sagas IslandesasEra Vikinge

          What's the metal clinking sound at the end of credits in Avengers: Endgame?What makes Thanos so strong in Avengers: Endgame?Who is the character that appears at the end of Endgame?What happens to Mjolnir (Thor's hammer) at the end of Endgame?The People's Ages in Avengers: EndgameWhat did Nebula do in Avengers: Endgame?Messing with time in the Avengers: Endgame climaxAvengers: Endgame timelineWhat are the time-travel rules in Avengers Endgame?Why use this song in Avengers: Endgame Opening Logo Sequence?Peggy's age in Avengers Endgame

          Are there legal definitions of ethnicities/races? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Legal definitions in the United StatesAre there truly legal limits on US interest rates?Are gender identity and sexual orientation federally protected?Why is there an apparent legal bias against digital services?What limits are there to the powers of individual judges in the United States legal system?Are women only scholarships legal under Irish / EU law?Is the term “race” defined by Public Law enacted by Congress of the United StatesIs there a legal definition of race in the US?Neighbors are spying for landlord on Renters is it legal?Are Protected Classes Bi-directional?