Started Big O Analysis.
This commit is contained in:
parent
456c003159
commit
9d87b9924f
@ -50,6 +50,19 @@ Algorithm Design Block
|
||||
|
||||
Big-O Analysis: (Based on Implementation)
|
||||
|
||||
n = the number of elements in the set.
|
||||
k = the number of elements in the subset.
|
||||
|
||||
| init Comps | init values | i | totalSum | generateSubsets | subset | value | subsetTotal | if(half) | asignSet | secondSubset | printResults |
|
||||
---------------------------------------------------------------------------------------------------------------------min--max---------------------
|
||||
| 1 | 1 | 1 | 1 | 2^n | 1 | 2^(n)+1 | 2^(n)+1 | 2^(n) | 0 1 |
|
||||
| | | 2 | 1 | | 2 | 2^(n)+2 | 2^(n)+2 | 2^(n) | |
|
||||
| | | 3 | 1 | | 3 | 2^(n)+3 | 2^(n)+3 | 2^(n) | |
|
||||
| | | 4 | 1 | | 4 | 2^(n)+4 | 2^(n)+4 | 2^(n) | |
|
||||
| | | ... | ... | | ... | ... | ... | 2^(n) | |
|
||||
| | | n | 1 | | 2^n | 2^(n)+k | 2^(n)+k | 2^(n) | |
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
| 1 | 1 | X | n | 2^n | X | X | | |
|
||||
Best-Case Scenario:
|
||||
Worse-Case Scenario:
|
||||
Average-Case:
|
||||
@ -239,6 +252,12 @@ public class Partition {
|
||||
List<Integer> firstSubset = null;
|
||||
List<Integer> secondSubset = null;
|
||||
|
||||
/* If the total is odd, there cannot be equal disjoint subsets. */
|
||||
if (totalSum % 2 == 1) {
|
||||
printResults(firstSubset, secondSubset);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks through every subset that was generated,
|
||||
* if a subset is found it sets the firstSubset to the found subset.
|
||||
|
Loading…
Reference in New Issue
Block a user