np

All possible path in a graph

折月煮酒 提交于 2020-01-25 08:18:05
问题 Given a graph G(V, E) , a source vertex s and destination vertex d , the problem is to find all possible paths from s to d where G may contain loops and cycles. I want to get all simple paths, no cycle is allowed. What would be the complexity of this problem? 回答1: This problem is NP-hard, since its output may have an exponential size w.r.t its input. Finding the longest path between two points is already NP-hard (reduction to hamiltonian path problem), so finding all of them is as well. You

NP verifier-based definition

让人想犯罪 __ 提交于 2020-01-16 08:13:01
问题 i'm a computer science student and i'm having some problem understanding the verifier based definition of NP problems. The definition says that a problem is in NP if can be verified in polinomial time by a deterministic turing machine, given a "certificate". But what happens, if the certificate is exactly the problem solution? It's only a bit, and it's obviuosly polinomially limited by the input size, and it's obviously verifiable in constant, thus polinomial time. Therefore, each decision

Pandas series case-insensitive matching and partial matching between values

◇◆丶佛笑我妖孽 提交于 2020-01-07 04:55:16
问题 I have the following operation to add a status showing where any string in a column of one dataframe column is present in a specified column of another dataframe. It looks like this: df_one['Status'] = np.where(df_one.A.isin(df_two.A), 'Matched','Unmatched') This won't match if the string case is different. Is it possible to perform this operation while being case insensitive? Also, is it possible return 'Matched' when a value in df_one.A ends with the full string from df_two.A ? e.g. df_one

Given a group of people, where each pair has a value, how can I find the configuration of pairings with the least total value?

我们两清 提交于 2020-01-04 05:15:12
问题 It's very much like the Assignment Problem, except with a complete undirected graph rather than a bipartite graph. The dumbest, most brute force-iest solution is something like this: Get all possible configurations of pairs... groups = people.combination(2).to_a.combination(people.size/2).to_a ...rejecting all of the configurations that contain the same person more than once. groups.reject! { |group| group.flatten.uniq.size < people.size } Then find the configuration with the minimum value.

NP-Complete VS NP-Hard

回眸只為那壹抹淺笑 提交于 2020-01-01 11:50:16
问题 I am trying to understand the difference between NP-Complete and NP-Hard. Below is my understanding An NP-Hard problem is one that is not solvable in polynomial time but can be verified in polynomial time. An NP-Complete problem is one that is in NP and is also NP-Hard. Is the above definition correct? If so, What about problems not In NP but NP-Hard. Wouldn't they be harder than NP-Complete problem, say they can only be solved and verified in exponential time? 回答1: A NP problem (not NP-Hard

Class Scheduling to Boolean satisfiability [Polynomial-time reduction] part 2

℡╲_俬逩灬. 提交于 2019-12-28 19:35:09
问题 I asked few days ago, a question about how to transform a University Class Scheduling Problem into a Boolean Satisfiability Problem. (Class Scheduling to Boolean satisfiability [Polynomial-time reduction]) I got an answer by @Amit who was very elegant and easy to code. Basically, his answer was like this : instead of considering courses, he considered time-intervals. So for the i-th course, he just indicted all the possible intervals for this course. And we obtain a solution when there is at

How to show that a prob is in NP and that it is NP-complete

只愿长相守 提交于 2019-12-25 03:36:11
问题 Longest Path We have a graph G=(V,E), lengths l(e) in Z^(+) for each e in E, a positive integer K and two nodes s,t in V. The question is if there is a simple path in G from s to t of length at least K ? Show that the problem Longest Path belongs to NP. Show that the problem Longest Path is NP-complete, reducing Hamiltonian Path to it. Show that if the graph is directed and acyclic then the problem can be solved in time O(|V|+|E|). Could you give me a hint how we could show that the problem

matrices are not aligned error message

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 03:44:08
问题 I have the following dataframe of returns ret Out[3]: Symbol FX OGDC PIB WTI Date 2010-03-02 0.000443 0.006928 0.000000 0.012375 2010-03-03 -0.000690 -0.007873 0.000171 0.014824 2010-03-04 -0.001354 0.001545 0.000007 -0.008195 2010-03-05 -0.001578 0.008796 -0.000164 0.015955 And the following weights for each symbol: df3 Out[4]: Symbol Weight 0 OGDC 0.182022 1 WTI 0.534814 2 FX 0.131243 3 PIB 0.151921 I am trying to get a weighted return for each day and tried: port_ret = ret.dot(df3) but I

Boolean formula encoding

会有一股神秘感。 提交于 2019-12-23 05:26:02
问题 i am wondering how many bits required to encode a boolean formula like @(x1,x2,x3,x4) = (x1 OR x2 OR NOT(x3) OR x4) AND ((NOT)x2 OR x3) AND (x1 OR (NOT)x4) @ is an instance of SAT. I think it is 4 bits since total number of possible combinations are 2(power4). Is that correct? Should i count OR, NOT, AND to calculate number of bits needed for encoding? I searched a lot but couldn't find anything on this. 回答1: You can always convert your expression into a logically equivalent CNF with

How to find pattern groups in boolean array?

与世无争的帅哥 提交于 2019-12-21 12:04:38
问题 Given a 2D array of Boolean values I want to find all patterns that consist of at least 2 columns and at least 2 rows. The problem is somewhat close to finding cliques in a graph. In the example below green cells represent "true" bits, greys are "false". Pattern 1 contains cols 1,3,4 and 5 and rows 1 and 2. Pattern 2 contains only columns 2 and 4, and rows 2,3,4. Business idea behind this is finding similarity patterns among various groups of social network users. In real world number of rows