CIS3590-G1B / GROUP-1B-Java

All Algorithms implemented in Java
MIT License
1 stars 0 forks source link

ISSUE#2.2 - LEO - ISSUE DEVELOPMENT #6

Closed ba-00001 closed 1 month ago

ba-00001 commented 1 month ago

`

Algorithm Development Template

ISSUE#: [Issue Number]
Title: [Issue Title]
Prepared by: [Developer Name]
Date: [MM/DD/YYYY]


1. Problem Definition and Clarification


2. Input/Output Specifications


3. Constraints and Requirements


4. Data Structures


5. Algorithm Design Approach


6. Edge Cases and Error Handling


7. Optimization


8. Testing and Debugging


9. Documentation and Maintenance


Comments/Notes

[Additional notes or comments regarding the issue development.]


Version History

Date Changes Made Version
MM/DD/YYYY Initial Draft 1.0
MM/DD/YYYY [Describe subsequent changes] X.X

`

leochirinos10 commented 1 month ago

ISSUE#: TheAlgorithms#5636 Title: Moore's Voting Algorithm Prepared by: Leonardo Chirinos Date: 10/23/2024

  1. Problem Definition and Clarification

Objective: Implement Moore's Voting Algorithm for finding the majority element in an array, where the majority element is defined as an element that appears more than half the time.

Key Questions: What is the problem to be solved?

What are the expected outcomes?

Sub-tasks: Break down the issue into smaller tasks. I: write the findMajorityElement() function which takes an int array as a parameter and returns an int candidate if there is a candidate found, otherwise return -1.

II: write the findCandidate() function which identifies a potential candidate for the majority element. It iterates through the array, adjusting the candidate's count based on matching elements.

III: write the isMajority() function which verifies whether the candidate occurs more than n/2 times in the array.

  1. Input/Output Specifications

Input Data: The input will be an array of ints.

Expected Output: The expected output will be the int candidate, which is the majority element in the array.

  1. Constraints and Requirements

Time Complexity: The time complexity of this implementation is O(n), where n is the number of elements in the array.

Space Complexity: The space complexity is O(1) since we only use a few extra variables.

Resource Constraints: There are no special CPU or memory constraints, as the algorithm efficiently operates in linear time and constant space.

Ethical Considerations (if applicable): No ethical considerations for this algorithm.

  1. Data Structures

Chosen Data Structures: The algorithm takes in an array and using an enhanced for loop it iterates through the array.

Justification: No additional data structures are needed for this algorithm.

  1. Edge Cases and Error Handling

Edge Cases:

Error Handling:

  1. Optimization

Initial Version: The initial version of the algorithm implements the algorithm that iterates through the array, with no further optimization required.

Optimization Techniques: No significant optimizations are needed, as this approach already achieves the best time and space complexity for the problem.

  1. Testing and Debugging

Test Cases:

Typical input cases.

Debugging Tools

  1. Documentation and Maintenance

Documentation:

Maintenance Plan:

Comments/Notes