Reputation: 121
How to create all different combination undirected graphs with sum of any two adjacent vertices equal to prime numbers. The number set is [1….10]
example:- undirected graph for number set [1...4]
1------2 2) 3---2
| | |
| | |
4 3 4
|
|
1
appreciate your help.
Thanks.
Upvotes: 0
Views: 738
Reputation: 3002
As a general approach you can reform your problem as follows: find all possible prime numbers which can be generated as sum of values from [k..n]
(k<=n
). After finding all those combinations you have to take all possible subsets of those combinations. So your solution will be the set of all those subsets.
In pseudo code:
k
to (k+n+1)(k+n)/2
(sum of all numbers from k
to
n
)Upvotes: 0
Reputation: 58339
All possible (undirected) edges are:
1-2, 1-4, 1-6, 1-10, 2-3, 2-5, 2-9, 3-4, 3-8, 3-10, 4-7, 4-9, 5-6, 5-8, 6-7, 7-10, 8-9, 9-10
All possible graphs are subsets of this set of edges. There's 18 edges, so there's 218 possible graphs.
Upvotes: 0
Reputation: 155004
From a high level, your algorithm looks something like this:
Upvotes: 0