Skip to content

feat[probability]: add conditional probability algorithm - #3235

Merged
realstealthninja merged 6 commits into
TheAlgorithms:masterfrom
SomrajBanik:master
Oct 3, 2026
Merged

realstealthninja merged 6 commits into
TheAlgorithms:masterfrom
SomrajBanik:master

Conversation

@SomrajBanik

@SomrajBanik SomrajBanik commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

This PR adds an implementation of Conditional Probability to the probability section. It introduces a new file probability/conditional_probability.cpp that implements the mathematical formula for computing conditional probability P(A|B) = P(A ∩ B) / P(B).

It includes:

  • 7 tests covering normal, edge case as well as error conditions
  • All tests cases pass
  • Function conditional_compute() takes two arguments and returns the required probability

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:
add new file at probability/conditional_probability.cpp containing conditional probability implementation.

@realstealthninja realstealthninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

Comment thread probability/conditional_probability.cpp Outdated
Comment thread probability/conditional_probability.cpp
Comment thread probability/conditional_probability.cpp
@realstealthninja realstealthninja added requested changes changes have been requested dont-close This issue/pull request shouldn't be closed labels Sep 30, 2026
@realstealthninja realstealthninja self-assigned this Sep 30, 2026
@SomrajBanik

Copy link
Copy Markdown
Contributor Author

Done.
Added e.what() asserts to tests 5, 6 and 7 so each one now checks the exact error message.
Added newline at EOF
Minor changes: Added relevant mathematical terms to Tests 2 & 3
Thanks for the review!

Comment thread probability/conditional_probability.cpp Outdated
Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com>

@realstealthninja realstealthninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, could you disclose whether any LLM assistance was taken in the process of writing this pr?

@SomrajBanik

Copy link
Copy Markdown
Contributor Author

Thanks for asking. I did not use LLM assistance for the core logic or structure, I studied how the other probability algorithms were written like geometric_dist.cpp and structured like them. I did use an LLM briefly to review the Doxygen documentation formatting before submitting to make sure the comments matched the project's documentation style, but the implementation itself was my own work.

@realstealthninja realstealthninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use mid when denoting bars in latex

Comment thread probability/conditional_probability.cpp Outdated

@realstealthninja realstealthninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks will be merged soon.

@realstealthninja realstealthninja added approved Approved; waiting for merge and removed requested changes changes have been requested dont-close This issue/pull request shouldn't be closed labels Oct 2, 2026
@SomrajBanik

Copy link
Copy Markdown
Contributor Author

Thank You!!

@realstealthninja
realstealthninja merged commit fdcc29b into TheAlgorithms:master Oct 3, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Approved; waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants