64 lines
2.3 KiB
Java
64 lines
2.3 KiB
Java
// Name: Jonathan Turner
|
|
// Class: CS 4306/01
|
|
// Term: Spring 2024
|
|
// Instructor: Dr. Haddad
|
|
// Assignment: 2
|
|
// IDE Name: IntelliJ
|
|
/*
|
|
Algorithm Design Block
|
|
Algorithm title: Finding Equal Disjoint Sets
|
|
|
|
Logical steps:
|
|
Step 1: Get the number of items in the set as user input.
|
|
Step 2: Get the elements in the set as user input.
|
|
Step 3: Add all the elements to the list and save it to a variable.
|
|
Step 4: If the sum is odd, there is no disjoint sets and it is not possible.
|
|
Step 5: Set a variable that will hold the first set and second set representing the disjoint and initialize it to null.
|
|
Step 6: Create a List that holds a list of elements which represent each subset.
|
|
Step 7: Generate the subsets using a subset generation method. (Ex. Bit Shift Counting)
|
|
Step 8: Iterate through all the subsets that were generate.
|
|
Step 9: If the current iteration's sum is equal to half of the total sum, move to step 11. Otherwise, continue iterating.
|
|
Step 10: If the value is not found, then there is no disjoint equal subsets. End algorithm.
|
|
Step 11: Assign the first set's variable to the current iteration's values.
|
|
Step 12: Assign the second set's variable to the values of the original set that are not in the first set.
|
|
Step 13: Return the results of the two equal disjoint sets that were found.
|
|
|
|
Pseudocode Syntax:
|
|
count <- input
|
|
elements <- input
|
|
first_set, second_set <- empty
|
|
|
|
sum <- 0
|
|
for each number in elements:
|
|
sum <- sum + number
|
|
|
|
if sum % 2 is 0:
|
|
subsets <- generate_subsets(elements)
|
|
for each subset in subsets:
|
|
current_sum <- 0
|
|
for each value in subset:
|
|
current_sum <- current_sum + value
|
|
if sum / 2 is current_sum:
|
|
first_set <- subset
|
|
|
|
if first_set is not empty:
|
|
second_set <- elements - first_set
|
|
else
|
|
return "no equal disjoint subsets"
|
|
|
|
return first_set, second_set
|
|
|
|
Big-O Analysis: (Based on Implementation)
|
|
|
|
Best-Case Scenario:
|
|
Worse-Case Scenario:
|
|
Average-Case:
|
|
|
|
Big O =>
|
|
*/
|
|
package Assignments.A2;
|
|
|
|
public class Partition {
|
|
|
|
}
|