Is finding a path with more red vertices than blue vertices NP-hard?Where's the flaw in my algorithm? (Linear program to solve NP-hard problem)Fastest algorithm for shortest path with atmost k edges on a DAG with non-negative edge weights?Algorithm to find whether there is a path (any path) above length X between two verticesLongest path in DAG or finding DAG diameterLongest path in a cyclic, directed and weighted graphFinding path that minimizes largest of the sum of weights of each group in a directed multigraphShortest path with minimal blue edgesColored cliques complexityFind shortest path that goes through at least 5 red edgesFloyd–Warshall algorithm on an undirected graph contains negative weight edgesFind a path from s to t using as few red nodes as possible

Why was the small council so happy for Tyrion to become the Master of Coin?

What defenses are there against being summoned by the Gate spell?

Test whether all array elements are factors of a number

TGV timetables / schedules?

How do I create uniquely male characters?

Finding angle with pure Geometry.

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

Which models of the Boeing 737 are still in production?

How old can references or sources in a thesis be?

What does it mean to describe someone as a butt steak?

Characters won't fit in table

Why do I get two different answers for this counting problem?

String Manipulation Interpreter

LaTeX closing $ signs makes cursor jump

In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?

How is it possible to have an ability score that is less than 3?

What is the word for reserving something for yourself before others do?

Voyeurism but not really

Dragon forelimb placement

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

Can a Warlock become Neutral Good?

How can I make my BBEG immortal short of making them a Lich or Vampire?

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?



Is finding a path with more red vertices than blue vertices NP-hard?


Where's the flaw in my algorithm? (Linear program to solve NP-hard problem)Fastest algorithm for shortest path with atmost k edges on a DAG with non-negative edge weights?Algorithm to find whether there is a path (any path) above length X between two verticesLongest path in DAG or finding DAG diameterLongest path in a cyclic, directed and weighted graphFinding path that minimizes largest of the sum of weights of each group in a directed multigraphShortest path with minimal blue edgesColored cliques complexityFind shortest path that goes through at least 5 red edgesFloyd–Warshall algorithm on an undirected graph contains negative weight edgesFind a path from s to t using as few red nodes as possible













6












$begingroup$


Given a connected, directed graph $G=(V,E)$, vertices $s,t in V$ and a coloring, s.t. $s$ and $t$ are black and all other vertices are either red or blue, is it possible to find a simple path from $s$ to $t$ with more red than blue vertices in polynomial time?



I think it should be possible but our TA said this was NP-hard.



Idea for a solution:



From $G$ create $G'=(V',E')$ as follows:



  • Split all $v in Vsetminus s,t$ in two vertices $v_in$ and $v_out$. $V'$ is made up of the split vertex pairs and $s$ and $t$.


  • For all $e=(u,v) in E$ introduce an edge $(u_out,v_in)$. (For edge $(x,v)$ or $(u,x)$ where $x in s,t$ create edge $(x,v_in)$ or $(u_out,x)$ resp.). Also, introduce an edge $(v_in,v_out)$ for any of the split vertices. So $E'$ contains two types of edges: the ones that correspond to edges from $E$ and the ones that correspond to vertices from $V$.


Now, we introduce weights as follows:




  • $w((v_in,v_out)) = -1$ if the corresponding vertex $v$ was red.


  • $w((v_in,v_out)) = +1$ if the corresponding vertex $v$ was blue.


  • $w(e) = 0$ for all other edges, i.e. the ones that correspond to edges of $G$ rather than vertices.

Now, conduct an algorithm for shortest paths of your choice like Dijkstra, Bellman-Ford,... , check whether the length of the given path is $<0$ and you are done.



Why does this not work? Is it because we may have negative cycles? We could detect those with Bellman Ford but then we'd have to find the desired path with non-efficient means rendering this decision problem NP-hard?
Is there an elegant reduction to show NP-hardness?










share|cite|improve this question









New contributor




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







$endgroup$
















    6












    $begingroup$


    Given a connected, directed graph $G=(V,E)$, vertices $s,t in V$ and a coloring, s.t. $s$ and $t$ are black and all other vertices are either red or blue, is it possible to find a simple path from $s$ to $t$ with more red than blue vertices in polynomial time?



    I think it should be possible but our TA said this was NP-hard.



    Idea for a solution:



    From $G$ create $G'=(V',E')$ as follows:



    • Split all $v in Vsetminus s,t$ in two vertices $v_in$ and $v_out$. $V'$ is made up of the split vertex pairs and $s$ and $t$.


    • For all $e=(u,v) in E$ introduce an edge $(u_out,v_in)$. (For edge $(x,v)$ or $(u,x)$ where $x in s,t$ create edge $(x,v_in)$ or $(u_out,x)$ resp.). Also, introduce an edge $(v_in,v_out)$ for any of the split vertices. So $E'$ contains two types of edges: the ones that correspond to edges from $E$ and the ones that correspond to vertices from $V$.


    Now, we introduce weights as follows:




    • $w((v_in,v_out)) = -1$ if the corresponding vertex $v$ was red.


    • $w((v_in,v_out)) = +1$ if the corresponding vertex $v$ was blue.


    • $w(e) = 0$ for all other edges, i.e. the ones that correspond to edges of $G$ rather than vertices.

    Now, conduct an algorithm for shortest paths of your choice like Dijkstra, Bellman-Ford,... , check whether the length of the given path is $<0$ and you are done.



    Why does this not work? Is it because we may have negative cycles? We could detect those with Bellman Ford but then we'd have to find the desired path with non-efficient means rendering this decision problem NP-hard?
    Is there an elegant reduction to show NP-hardness?










    share|cite|improve this question









    New contributor




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







    $endgroup$














      6












      6








      6





      $begingroup$


      Given a connected, directed graph $G=(V,E)$, vertices $s,t in V$ and a coloring, s.t. $s$ and $t$ are black and all other vertices are either red or blue, is it possible to find a simple path from $s$ to $t$ with more red than blue vertices in polynomial time?



      I think it should be possible but our TA said this was NP-hard.



      Idea for a solution:



      From $G$ create $G'=(V',E')$ as follows:



      • Split all $v in Vsetminus s,t$ in two vertices $v_in$ and $v_out$. $V'$ is made up of the split vertex pairs and $s$ and $t$.


      • For all $e=(u,v) in E$ introduce an edge $(u_out,v_in)$. (For edge $(x,v)$ or $(u,x)$ where $x in s,t$ create edge $(x,v_in)$ or $(u_out,x)$ resp.). Also, introduce an edge $(v_in,v_out)$ for any of the split vertices. So $E'$ contains two types of edges: the ones that correspond to edges from $E$ and the ones that correspond to vertices from $V$.


      Now, we introduce weights as follows:




      • $w((v_in,v_out)) = -1$ if the corresponding vertex $v$ was red.


      • $w((v_in,v_out)) = +1$ if the corresponding vertex $v$ was blue.


      • $w(e) = 0$ for all other edges, i.e. the ones that correspond to edges of $G$ rather than vertices.

      Now, conduct an algorithm for shortest paths of your choice like Dijkstra, Bellman-Ford,... , check whether the length of the given path is $<0$ and you are done.



      Why does this not work? Is it because we may have negative cycles? We could detect those with Bellman Ford but then we'd have to find the desired path with non-efficient means rendering this decision problem NP-hard?
      Is there an elegant reduction to show NP-hardness?










      share|cite|improve this question









      New contributor




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







      $endgroup$




      Given a connected, directed graph $G=(V,E)$, vertices $s,t in V$ and a coloring, s.t. $s$ and $t$ are black and all other vertices are either red or blue, is it possible to find a simple path from $s$ to $t$ with more red than blue vertices in polynomial time?



      I think it should be possible but our TA said this was NP-hard.



      Idea for a solution:



      From $G$ create $G'=(V',E')$ as follows:



      • Split all $v in Vsetminus s,t$ in two vertices $v_in$ and $v_out$. $V'$ is made up of the split vertex pairs and $s$ and $t$.


      • For all $e=(u,v) in E$ introduce an edge $(u_out,v_in)$. (For edge $(x,v)$ or $(u,x)$ where $x in s,t$ create edge $(x,v_in)$ or $(u_out,x)$ resp.). Also, introduce an edge $(v_in,v_out)$ for any of the split vertices. So $E'$ contains two types of edges: the ones that correspond to edges from $E$ and the ones that correspond to vertices from $V$.


      Now, we introduce weights as follows:




      • $w((v_in,v_out)) = -1$ if the corresponding vertex $v$ was red.


      • $w((v_in,v_out)) = +1$ if the corresponding vertex $v$ was blue.


      • $w(e) = 0$ for all other edges, i.e. the ones that correspond to edges of $G$ rather than vertices.

      Now, conduct an algorithm for shortest paths of your choice like Dijkstra, Bellman-Ford,... , check whether the length of the given path is $<0$ and you are done.



      Why does this not work? Is it because we may have negative cycles? We could detect those with Bellman Ford but then we'd have to find the desired path with non-efficient means rendering this decision problem NP-hard?
      Is there an elegant reduction to show NP-hardness?







      complexity-theory graphs






      share|cite|improve this question









      New contributor




      Valerie Poulain 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




      Valerie Poulain 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 2 days ago









      xskxzr

      4,18921033




      4,18921033






      New contributor




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









      asked Apr 3 at 12:17









      Valerie PoulainValerie Poulain

      332




      332




      New contributor




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





      New contributor





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






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




















          1 Answer
          1






          active

          oldest

          votes


















          8












          $begingroup$

          Your solution does not work because Dijkstra and Bellman-Ford cannot interpret "simple path" feature. And they will indeed fall in any negative cycle.



          I think the best to show NP-completeness, is to use the Hamiltonian path problem. Let's take a graph $G'$ of $N$ red vertices.



          Then you build a graph $G$, adding $s$, $t$ and $N-1$ blue vertices to $G'$. You first chain with edges all the blues vertices from the source to the last blue one ($s$->$b_1$->$b_2$->...->$b_N-1$). Then you put edges from $b_N-1$ to every red vertex and an edge from every red vertex to $t$.



          So a single path from $s$ to $t$ passes necessarly through all blue nodes ($N-1$) and then have to pass to all red nodes ($N$) to answer to



          Is there a simple path in $G$ from $s$ to $t$ with more red than blue vertices ?



          which is thus like answer to:



          Is there an Hamiltonian path in $G'$



          So your problem is indeed NP-complete.






          share|cite|improve this answer











          $endgroup$








          • 1




            $begingroup$
            Neat, thanks. So if I wanted to formally prove $DHP preceq ProblemAbove$ where I have to start with an instance $G,s,t$ for the Hamiltonian Path and map it to an instance $G',s',t'$ of this problem, could I do the following: Color all existing vertices red, add $|Vsetminuss,t|-1$ blue vertices and connect them in a chain $(b_1)rightarrow ldots rightarrow(b_n)$. Add an edge $(s,b_1)$, and for each $(s,v)$ in $G$ an edge $(b_n,v)$ in $G'$, the rest stays as it is.
            $endgroup$
            – Valerie Poulain
            Apr 3 at 14:02






          • 1




            $begingroup$
            Yes I am not very familiar with NP-completeness demonstration but this way to present it is clearly better. I would nevertheless start with an instance of $G$ without $s$ & $t$ as initial Hamiltonian path problem has no specific vertex.
            $endgroup$
            – Vince
            Apr 3 at 14:26






          • 2




            $begingroup$
            Upvoted for (I think) correctness; but this argument would be WAY easier to understand if you STARTED with the arbitrary graph $G'$ and then embedded it within the specially constructed $G$. Right now the reduction is hiding entirely in the single sentence "Finally, you put any number of edges between red vertices," which I missed on my first reading. "Any number of edges" is code for "you pick any arbitrary graph $G'$ whose Hamiltonian path you'd like to discover, and embed it in there." That's what makes this a valid reduction.
            $endgroup$
            – Quuxplusone
            Apr 3 at 18:45







          • 1




            $begingroup$
            @Quuxplusone you are right I edit to make it clearer.
            $endgroup$
            – Vince
            2 days ago










          • $begingroup$
            @ValeriePoulain: Vince is right that starting and ending vertices are not given for the usual HP problem, but if they are given, your reduction needs a slight tweak: You must insert a chain of $|V setminus s, t|-1$ blue vertices in a line along each edge between $s$ and any other red vertex. This is to prevent, e.g., a single edge from $s$ to some red vertex from being a valid solution to the constructed instance.
            $endgroup$
            – j_random_hacker
            2 days 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
          );



          );






          Valerie Poulain 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%2f106420%2fis-finding-a-path-with-more-red-vertices-than-blue-vertices-np-hard%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          8












          $begingroup$

          Your solution does not work because Dijkstra and Bellman-Ford cannot interpret "simple path" feature. And they will indeed fall in any negative cycle.



          I think the best to show NP-completeness, is to use the Hamiltonian path problem. Let's take a graph $G'$ of $N$ red vertices.



          Then you build a graph $G$, adding $s$, $t$ and $N-1$ blue vertices to $G'$. You first chain with edges all the blues vertices from the source to the last blue one ($s$->$b_1$->$b_2$->...->$b_N-1$). Then you put edges from $b_N-1$ to every red vertex and an edge from every red vertex to $t$.



          So a single path from $s$ to $t$ passes necessarly through all blue nodes ($N-1$) and then have to pass to all red nodes ($N$) to answer to



          Is there a simple path in $G$ from $s$ to $t$ with more red than blue vertices ?



          which is thus like answer to:



          Is there an Hamiltonian path in $G'$



          So your problem is indeed NP-complete.






          share|cite|improve this answer











          $endgroup$








          • 1




            $begingroup$
            Neat, thanks. So if I wanted to formally prove $DHP preceq ProblemAbove$ where I have to start with an instance $G,s,t$ for the Hamiltonian Path and map it to an instance $G',s',t'$ of this problem, could I do the following: Color all existing vertices red, add $|Vsetminuss,t|-1$ blue vertices and connect them in a chain $(b_1)rightarrow ldots rightarrow(b_n)$. Add an edge $(s,b_1)$, and for each $(s,v)$ in $G$ an edge $(b_n,v)$ in $G'$, the rest stays as it is.
            $endgroup$
            – Valerie Poulain
            Apr 3 at 14:02






          • 1




            $begingroup$
            Yes I am not very familiar with NP-completeness demonstration but this way to present it is clearly better. I would nevertheless start with an instance of $G$ without $s$ & $t$ as initial Hamiltonian path problem has no specific vertex.
            $endgroup$
            – Vince
            Apr 3 at 14:26






          • 2




            $begingroup$
            Upvoted for (I think) correctness; but this argument would be WAY easier to understand if you STARTED with the arbitrary graph $G'$ and then embedded it within the specially constructed $G$. Right now the reduction is hiding entirely in the single sentence "Finally, you put any number of edges between red vertices," which I missed on my first reading. "Any number of edges" is code for "you pick any arbitrary graph $G'$ whose Hamiltonian path you'd like to discover, and embed it in there." That's what makes this a valid reduction.
            $endgroup$
            – Quuxplusone
            Apr 3 at 18:45







          • 1




            $begingroup$
            @Quuxplusone you are right I edit to make it clearer.
            $endgroup$
            – Vince
            2 days ago










          • $begingroup$
            @ValeriePoulain: Vince is right that starting and ending vertices are not given for the usual HP problem, but if they are given, your reduction needs a slight tweak: You must insert a chain of $|V setminus s, t|-1$ blue vertices in a line along each edge between $s$ and any other red vertex. This is to prevent, e.g., a single edge from $s$ to some red vertex from being a valid solution to the constructed instance.
            $endgroup$
            – j_random_hacker
            2 days ago















          8












          $begingroup$

          Your solution does not work because Dijkstra and Bellman-Ford cannot interpret "simple path" feature. And they will indeed fall in any negative cycle.



          I think the best to show NP-completeness, is to use the Hamiltonian path problem. Let's take a graph $G'$ of $N$ red vertices.



          Then you build a graph $G$, adding $s$, $t$ and $N-1$ blue vertices to $G'$. You first chain with edges all the blues vertices from the source to the last blue one ($s$->$b_1$->$b_2$->...->$b_N-1$). Then you put edges from $b_N-1$ to every red vertex and an edge from every red vertex to $t$.



          So a single path from $s$ to $t$ passes necessarly through all blue nodes ($N-1$) and then have to pass to all red nodes ($N$) to answer to



          Is there a simple path in $G$ from $s$ to $t$ with more red than blue vertices ?



          which is thus like answer to:



          Is there an Hamiltonian path in $G'$



          So your problem is indeed NP-complete.






          share|cite|improve this answer











          $endgroup$








          • 1




            $begingroup$
            Neat, thanks. So if I wanted to formally prove $DHP preceq ProblemAbove$ where I have to start with an instance $G,s,t$ for the Hamiltonian Path and map it to an instance $G',s',t'$ of this problem, could I do the following: Color all existing vertices red, add $|Vsetminuss,t|-1$ blue vertices and connect them in a chain $(b_1)rightarrow ldots rightarrow(b_n)$. Add an edge $(s,b_1)$, and for each $(s,v)$ in $G$ an edge $(b_n,v)$ in $G'$, the rest stays as it is.
            $endgroup$
            – Valerie Poulain
            Apr 3 at 14:02






          • 1




            $begingroup$
            Yes I am not very familiar with NP-completeness demonstration but this way to present it is clearly better. I would nevertheless start with an instance of $G$ without $s$ & $t$ as initial Hamiltonian path problem has no specific vertex.
            $endgroup$
            – Vince
            Apr 3 at 14:26






          • 2




            $begingroup$
            Upvoted for (I think) correctness; but this argument would be WAY easier to understand if you STARTED with the arbitrary graph $G'$ and then embedded it within the specially constructed $G$. Right now the reduction is hiding entirely in the single sentence "Finally, you put any number of edges between red vertices," which I missed on my first reading. "Any number of edges" is code for "you pick any arbitrary graph $G'$ whose Hamiltonian path you'd like to discover, and embed it in there." That's what makes this a valid reduction.
            $endgroup$
            – Quuxplusone
            Apr 3 at 18:45







          • 1




            $begingroup$
            @Quuxplusone you are right I edit to make it clearer.
            $endgroup$
            – Vince
            2 days ago










          • $begingroup$
            @ValeriePoulain: Vince is right that starting and ending vertices are not given for the usual HP problem, but if they are given, your reduction needs a slight tweak: You must insert a chain of $|V setminus s, t|-1$ blue vertices in a line along each edge between $s$ and any other red vertex. This is to prevent, e.g., a single edge from $s$ to some red vertex from being a valid solution to the constructed instance.
            $endgroup$
            – j_random_hacker
            2 days ago













          8












          8








          8





          $begingroup$

          Your solution does not work because Dijkstra and Bellman-Ford cannot interpret "simple path" feature. And they will indeed fall in any negative cycle.



          I think the best to show NP-completeness, is to use the Hamiltonian path problem. Let's take a graph $G'$ of $N$ red vertices.



          Then you build a graph $G$, adding $s$, $t$ and $N-1$ blue vertices to $G'$. You first chain with edges all the blues vertices from the source to the last blue one ($s$->$b_1$->$b_2$->...->$b_N-1$). Then you put edges from $b_N-1$ to every red vertex and an edge from every red vertex to $t$.



          So a single path from $s$ to $t$ passes necessarly through all blue nodes ($N-1$) and then have to pass to all red nodes ($N$) to answer to



          Is there a simple path in $G$ from $s$ to $t$ with more red than blue vertices ?



          which is thus like answer to:



          Is there an Hamiltonian path in $G'$



          So your problem is indeed NP-complete.






          share|cite|improve this answer











          $endgroup$



          Your solution does not work because Dijkstra and Bellman-Ford cannot interpret "simple path" feature. And they will indeed fall in any negative cycle.



          I think the best to show NP-completeness, is to use the Hamiltonian path problem. Let's take a graph $G'$ of $N$ red vertices.



          Then you build a graph $G$, adding $s$, $t$ and $N-1$ blue vertices to $G'$. You first chain with edges all the blues vertices from the source to the last blue one ($s$->$b_1$->$b_2$->...->$b_N-1$). Then you put edges from $b_N-1$ to every red vertex and an edge from every red vertex to $t$.



          So a single path from $s$ to $t$ passes necessarly through all blue nodes ($N-1$) and then have to pass to all red nodes ($N$) to answer to



          Is there a simple path in $G$ from $s$ to $t$ with more red than blue vertices ?



          which is thus like answer to:



          Is there an Hamiltonian path in $G'$



          So your problem is indeed NP-complete.







          share|cite|improve this answer














          share|cite|improve this answer



          share|cite|improve this answer








          edited 2 days ago

























          answered Apr 3 at 12:56









          VinceVince

          71328




          71328







          • 1




            $begingroup$
            Neat, thanks. So if I wanted to formally prove $DHP preceq ProblemAbove$ where I have to start with an instance $G,s,t$ for the Hamiltonian Path and map it to an instance $G',s',t'$ of this problem, could I do the following: Color all existing vertices red, add $|Vsetminuss,t|-1$ blue vertices and connect them in a chain $(b_1)rightarrow ldots rightarrow(b_n)$. Add an edge $(s,b_1)$, and for each $(s,v)$ in $G$ an edge $(b_n,v)$ in $G'$, the rest stays as it is.
            $endgroup$
            – Valerie Poulain
            Apr 3 at 14:02






          • 1




            $begingroup$
            Yes I am not very familiar with NP-completeness demonstration but this way to present it is clearly better. I would nevertheless start with an instance of $G$ without $s$ & $t$ as initial Hamiltonian path problem has no specific vertex.
            $endgroup$
            – Vince
            Apr 3 at 14:26






          • 2




            $begingroup$
            Upvoted for (I think) correctness; but this argument would be WAY easier to understand if you STARTED with the arbitrary graph $G'$ and then embedded it within the specially constructed $G$. Right now the reduction is hiding entirely in the single sentence "Finally, you put any number of edges between red vertices," which I missed on my first reading. "Any number of edges" is code for "you pick any arbitrary graph $G'$ whose Hamiltonian path you'd like to discover, and embed it in there." That's what makes this a valid reduction.
            $endgroup$
            – Quuxplusone
            Apr 3 at 18:45







          • 1




            $begingroup$
            @Quuxplusone you are right I edit to make it clearer.
            $endgroup$
            – Vince
            2 days ago










          • $begingroup$
            @ValeriePoulain: Vince is right that starting and ending vertices are not given for the usual HP problem, but if they are given, your reduction needs a slight tweak: You must insert a chain of $|V setminus s, t|-1$ blue vertices in a line along each edge between $s$ and any other red vertex. This is to prevent, e.g., a single edge from $s$ to some red vertex from being a valid solution to the constructed instance.
            $endgroup$
            – j_random_hacker
            2 days ago












          • 1




            $begingroup$
            Neat, thanks. So if I wanted to formally prove $DHP preceq ProblemAbove$ where I have to start with an instance $G,s,t$ for the Hamiltonian Path and map it to an instance $G',s',t'$ of this problem, could I do the following: Color all existing vertices red, add $|Vsetminuss,t|-1$ blue vertices and connect them in a chain $(b_1)rightarrow ldots rightarrow(b_n)$. Add an edge $(s,b_1)$, and for each $(s,v)$ in $G$ an edge $(b_n,v)$ in $G'$, the rest stays as it is.
            $endgroup$
            – Valerie Poulain
            Apr 3 at 14:02






          • 1




            $begingroup$
            Yes I am not very familiar with NP-completeness demonstration but this way to present it is clearly better. I would nevertheless start with an instance of $G$ without $s$ & $t$ as initial Hamiltonian path problem has no specific vertex.
            $endgroup$
            – Vince
            Apr 3 at 14:26






          • 2




            $begingroup$
            Upvoted for (I think) correctness; but this argument would be WAY easier to understand if you STARTED with the arbitrary graph $G'$ and then embedded it within the specially constructed $G$. Right now the reduction is hiding entirely in the single sentence "Finally, you put any number of edges between red vertices," which I missed on my first reading. "Any number of edges" is code for "you pick any arbitrary graph $G'$ whose Hamiltonian path you'd like to discover, and embed it in there." That's what makes this a valid reduction.
            $endgroup$
            – Quuxplusone
            Apr 3 at 18:45







          • 1




            $begingroup$
            @Quuxplusone you are right I edit to make it clearer.
            $endgroup$
            – Vince
            2 days ago










          • $begingroup$
            @ValeriePoulain: Vince is right that starting and ending vertices are not given for the usual HP problem, but if they are given, your reduction needs a slight tweak: You must insert a chain of $|V setminus s, t|-1$ blue vertices in a line along each edge between $s$ and any other red vertex. This is to prevent, e.g., a single edge from $s$ to some red vertex from being a valid solution to the constructed instance.
            $endgroup$
            – j_random_hacker
            2 days ago







          1




          1




          $begingroup$
          Neat, thanks. So if I wanted to formally prove $DHP preceq ProblemAbove$ where I have to start with an instance $G,s,t$ for the Hamiltonian Path and map it to an instance $G',s',t'$ of this problem, could I do the following: Color all existing vertices red, add $|Vsetminuss,t|-1$ blue vertices and connect them in a chain $(b_1)rightarrow ldots rightarrow(b_n)$. Add an edge $(s,b_1)$, and for each $(s,v)$ in $G$ an edge $(b_n,v)$ in $G'$, the rest stays as it is.
          $endgroup$
          – Valerie Poulain
          Apr 3 at 14:02




          $begingroup$
          Neat, thanks. So if I wanted to formally prove $DHP preceq ProblemAbove$ where I have to start with an instance $G,s,t$ for the Hamiltonian Path and map it to an instance $G',s',t'$ of this problem, could I do the following: Color all existing vertices red, add $|Vsetminuss,t|-1$ blue vertices and connect them in a chain $(b_1)rightarrow ldots rightarrow(b_n)$. Add an edge $(s,b_1)$, and for each $(s,v)$ in $G$ an edge $(b_n,v)$ in $G'$, the rest stays as it is.
          $endgroup$
          – Valerie Poulain
          Apr 3 at 14:02




          1




          1




          $begingroup$
          Yes I am not very familiar with NP-completeness demonstration but this way to present it is clearly better. I would nevertheless start with an instance of $G$ without $s$ & $t$ as initial Hamiltonian path problem has no specific vertex.
          $endgroup$
          – Vince
          Apr 3 at 14:26




          $begingroup$
          Yes I am not very familiar with NP-completeness demonstration but this way to present it is clearly better. I would nevertheless start with an instance of $G$ without $s$ & $t$ as initial Hamiltonian path problem has no specific vertex.
          $endgroup$
          – Vince
          Apr 3 at 14:26




          2




          2




          $begingroup$
          Upvoted for (I think) correctness; but this argument would be WAY easier to understand if you STARTED with the arbitrary graph $G'$ and then embedded it within the specially constructed $G$. Right now the reduction is hiding entirely in the single sentence "Finally, you put any number of edges between red vertices," which I missed on my first reading. "Any number of edges" is code for "you pick any arbitrary graph $G'$ whose Hamiltonian path you'd like to discover, and embed it in there." That's what makes this a valid reduction.
          $endgroup$
          – Quuxplusone
          Apr 3 at 18:45





          $begingroup$
          Upvoted for (I think) correctness; but this argument would be WAY easier to understand if you STARTED with the arbitrary graph $G'$ and then embedded it within the specially constructed $G$. Right now the reduction is hiding entirely in the single sentence "Finally, you put any number of edges between red vertices," which I missed on my first reading. "Any number of edges" is code for "you pick any arbitrary graph $G'$ whose Hamiltonian path you'd like to discover, and embed it in there." That's what makes this a valid reduction.
          $endgroup$
          – Quuxplusone
          Apr 3 at 18:45





          1




          1




          $begingroup$
          @Quuxplusone you are right I edit to make it clearer.
          $endgroup$
          – Vince
          2 days ago




          $begingroup$
          @Quuxplusone you are right I edit to make it clearer.
          $endgroup$
          – Vince
          2 days ago












          $begingroup$
          @ValeriePoulain: Vince is right that starting and ending vertices are not given for the usual HP problem, but if they are given, your reduction needs a slight tweak: You must insert a chain of $|V setminus s, t|-1$ blue vertices in a line along each edge between $s$ and any other red vertex. This is to prevent, e.g., a single edge from $s$ to some red vertex from being a valid solution to the constructed instance.
          $endgroup$
          – j_random_hacker
          2 days ago




          $begingroup$
          @ValeriePoulain: Vince is right that starting and ending vertices are not given for the usual HP problem, but if they are given, your reduction needs a slight tweak: You must insert a chain of $|V setminus s, t|-1$ blue vertices in a line along each edge between $s$ and any other red vertex. This is to prevent, e.g., a single edge from $s$ to some red vertex from being a valid solution to the constructed instance.
          $endgroup$
          – j_random_hacker
          2 days ago










          Valerie Poulain is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          Valerie Poulain is a new contributor. Be nice, and check out our Code of Conduct.












          Valerie Poulain is a new contributor. Be nice, and check out our Code of Conduct.











          Valerie Poulain 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%2f106420%2fis-finding-a-path-with-more-red-vertices-than-blue-vertices-np-hard%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

          Bulk add to cart function issuecart vs. mini cart issue … rwd themeRedirect Add to cart button to cart pageAdd to cart issue - Magento 2.1The requested Payment Method is not available When creating an orderM2: reason add-to-cart might not function in production modeAdd to cart issue in some android devicesMagento 2 - custom price can not add to subtotal and grand total after add to cartAdd to cart codeIssue with my cart module on pdp and cart pages, just keeps spinningBulk price and quantity update using rest api

          Magento2 - How to hide price filter only in specific categories?Multiselect price filter attribute in layered navigationhide only some categories from layered navigation in magentoRemove Price Filter on certain categoriescustomize layered price filter?Hide Price for a particular customer groupPrice filter in layered navigation not working correctly with price including tax in magento 2.2.3Magento 2 how to hide attribute at Layered navigation?Magento 2. how to hide price only for specific categoriesMagento 2 How can I hide the price and total from cart and checkout summary?Magento2: Can we add navigation layered filter like price filter for other attribute?