Finished Assignment 2.

This commit is contained in:
Jonathan Turner 2024-02-23 22:26:14 -05:00
parent 9d87b9924f
commit 726af6ba4b

View File

@ -51,23 +51,24 @@ 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.
k = the number of elements in the current 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:
| init Comps | init values | i | totalSum | generateSubsets | subset | value | subsetTotal | if(half) | asignSet | secondSubset | printResults
-------------------------------------------------------------------------------------------min-------max-------------------------min--max---------------------------------
| 1 | 1 | 1 | 1 | 2^n | 1 | 2^(n)+1 | 1 2^(n)+1 | 2^(n) | 0 1 | 1 | 1
| | | 2 | 1 | | 2 | 2^(n)+2 | 1 2^(n)+2 | 2^(n) | 0 1 | 2 | 1
| | | 3 | 1 | | 3 | 2^(n)+3 | 1 2^(n)+3 | 2^(n) | 0 1 | 3 | 1
| | | 4 | 1 | | 4 | 2^(n)+4 | 1 2^(n)+4 | 2^(n) | 0 1 | 4 | 1
| | | ... | ... | | ... | ... | 1 ... | ... |... ... |... | 1
| | | n | 1 | | 2^n | 2^(n)+k | 1 2^(n)+k | 2^(n) | 0 1 | k | 1
--------------------------------------------------------------------------------------------------------------------------------------------------------------
| 1 | 1 | X | n | 2^n | X | X | 1 k*2^(n) + | n*2^(n) | 0 2^n | k | 1
(k^(2)+k)/2 |
Best-Case Scenario: 1 + 1 + n + 2^n + 1 + (n*2^(n)) + 0 + k + 1 = n + 2^n + (n*2^(n)) + k + 4
Worse-Case Scenario: 1 + 1 + n + 2^n + k*2^n+(k*2^(n))/2 + n*2^(n) + 2^n + k + 1 = 2^n + k*2^n + (k*2^(n))/2 + n*2^(n) + k + 4
Average-Case: (n*2^(n) + 2^n + k + 4 + 2^n + k*2^n + (k*2^(n))/2 + n*2^(n) + k + 4)/2
Big O =>
Big O => O(2^n)
*/
package Assignments.A2;
@ -201,6 +202,14 @@ public class Partition {
}
}
/**
* Gets the values for the set. If the input is invalid, it will prompt the user again.
*
* @precondition none
* @postcondition the values are gathered.
*
* @return the values of the set.
*/
private int[] getValues() {
Scanner sc = new Scanner(System.in);
String input = null;
@ -231,8 +240,6 @@ public class Partition {
System.out.println("Please enter a valid list of " + this.set.length + " positive values. (Ex. 34 35 21 23)");
}
}
return values;
}
@ -287,8 +294,8 @@ public class Partition {
}
/**
* Prints the results of the algorithm based on the two subsets. Prints the setsize, the original set.
* If the subsets were null (No match found) print output associated, else print the both lists.
* Prints the results of the algorithm based on the two subsets. Prints the setsize and the original set.
* If the subsets were null (No match found) print output associated, otherwise print the both lists.
*
* @precondition none
* @postcondition the output is displayed.
@ -327,7 +334,7 @@ public class Partition {
/**
* Generates the list of subsets using Bit Shift Counting by iterating over all combinations of 1 to n.
* After shifting the counter, the current subset is created initialized and if 1 shifted by j is logically
* ANDed with the i is not 0, it adds the value j represents to the subset.
* ANDed with the i and is not equal to 0, it adds the value j represents to the subset.
*
* @precondition none
* @postcondition the subsets are generated and added to the field.
@ -347,5 +354,4 @@ public class Partition {
}
this.subsets = subsets;
}
}