np-complete

Finding the maximum sum that can be formed from a set, by partitioning it into two subset

一世执手 提交于 2021-02-17 02:55:08
问题 Decription Given a set of numbers S. Find maximum sum such that Sum(A 1 ) = Sum(A 2 ) Where, A 1 ⊂S and A 2 ⊂S and A 1 ⋂A 2 =∅ And Sum(X), is the sum of all elements within the set X. Approach Brute Force The easiest approach is: print maximumSum(0,0,0) def maximumSum(index,sum1,sum2): ans=0 if sum1 == sum2: ans=sum1 if index >= len(S): return ans m1=maximumSum(index+1,sum1+S[index],sum2) m2=maximumSum(index+1,sum1,sum2+S[index]) m3=maximumSum(index+1,sum1,sum2) return max(m,m1,m2,m3) Time

Finding the maximum sum that can be formed from a set, by partitioning it into two subset

那年仲夏 提交于 2021-02-17 02:54:07
问题 Decription Given a set of numbers S. Find maximum sum such that Sum(A 1 ) = Sum(A 2 ) Where, A 1 ⊂S and A 2 ⊂S and A 1 ⋂A 2 =∅ And Sum(X), is the sum of all elements within the set X. Approach Brute Force The easiest approach is: print maximumSum(0,0,0) def maximumSum(index,sum1,sum2): ans=0 if sum1 == sum2: ans=sum1 if index >= len(S): return ans m1=maximumSum(index+1,sum1+S[index],sum2) m2=maximumSum(index+1,sum1,sum2+S[index]) m3=maximumSum(index+1,sum1,sum2) return max(m,m1,m2,m3) Time

set of vertex-disjoint cycles so that each vertex belongs to a cycle

徘徊边缘 提交于 2021-02-07 20:56:59
问题 Here I have a directed graph G. I need to to determine whether there exists a set of vertex-disjoint cycles so that each vertex belongs to a cycle. I'm not sure if this can be done in polynomial time or if its NP-Complete? Can anyone atleast point me in the right direction? 回答1: Split each vertex into an "in" vertex and an "out" vertex. Then a vertex-disjoint cycle cover corresponds to a perfect matching on this graph. You can find out the answer to your question as fast as you can find

Find least colorful path in a graph

限于喜欢 提交于 2021-01-29 03:09:27
问题 The problem i'm trying to solve is this: Given a graph G = (V,E) such that every edge is colored in one of 10 colors, and two vertices: s, t. I need to find an algorithm that produces a (shortest) path from s to t, that goes over a minimal amount of colors. My idea was to duplicate the graph 10 times: The first duplicate will include only edges of one color The second will include only edges of two colors... and so on. Also, I connect an outer node: s' to every "s" node in every duplicate.

Are all NP problems also NP-complete?

别等时光非礼了梦想. 提交于 2020-07-04 09:51:47
问题 The definition of NP-complete is A problem is NP-complete if it belongs to class NP all the other problems in NP polynomially transform to it So, if all other problems in NP transform to an NP-complete problem, then does that not also mean that all NP problems are also NP-complete? What is the point of classifying the two if they are the same? In other words, if we have an NP problem then through (2) this problem can transform into an NP-complete problem. Therefore, the NP problem is now NP

Divide list into two equal parts algorithm

≯℡__Kan透↙ 提交于 2020-06-27 04:07:10
问题 Related questions: Algorithm to Divide a list of numbers into 2 equal sum lists divide list in two parts that their sum closest to each other Let's assume I have a list, which contains exactly 2k elements. Now, I'm willing to split it into two parts, where each part has a length of k while trying to make the sum of the parts as equal as possible. Quick example: [3, 4, 4, 1, 2, 1] might be splitted to [1, 4, 3] and [1, 2, 4] and the sum difference will be 1 Now - if the parts can have

Factorial-time algorithms and P/NP

久未见 提交于 2020-01-22 05:57:50
问题 It's quite easy to see that n! grows slower than almost anything to the N power (say, 100^N) and so, if a problems is considered NP complete and one happened upon a n! algorithm that approximates the solution, one would do the Snoopy dance. I have 2 questions about this situation: Would the n! algorithm be considered a solution in polynomial time? A factorial certainly doesn't appear to be a term raised to a power. If finding a n! solution means we have a decently fast algorithm and since n!

Is this variant of the subset sum problem easier to solve?

落爺英雄遲暮 提交于 2020-01-19 07:39:11
问题 I have a problem related to the subset sum problem and am wondering if the differences make it easier, i.e. solvable in a reasonable amount of time. Given a value V, a set size L, and a sequence of numbers [1,N] S, how many size L subsets of S sum to less than V? This is different than the subset sum problem in three ways: I care how many subsets are less than a given value, not how many are equal . The subset sizes are fixed. I care how many sets sum to less than V, not just whether any

Is this variant of the subset sum problem easier to solve?

江枫思渺然 提交于 2020-01-19 07:38:13
问题 I have a problem related to the subset sum problem and am wondering if the differences make it easier, i.e. solvable in a reasonable amount of time. Given a value V, a set size L, and a sequence of numbers [1,N] S, how many size L subsets of S sum to less than V? This is different than the subset sum problem in three ways: I care how many subsets are less than a given value, not how many are equal . The subset sizes are fixed. I care how many sets sum to less than V, not just whether any

What is a good algorithm for compacting records in a blocked file?

旧巷老猫 提交于 2020-01-11 09:38:29
问题 Suppose you have a large file made up of a bunch of fixed size blocks. Each of these blocks contains some number of variable sized records. Each record must fit completely within a single block and then such records by definition are never larger than a full block. Over time, records are added to and deleted from these blocks as records come and go from this "database". At some point, especially after perhaps many records are added to the database and several are removed - many of the blocks