Skip to content

Commit

Permalink
implement regularity condition on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
DrCBeatz committed Mar 26, 2024
1 parent 1c1d9f7 commit 84cca90
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 52 deletions.
30 changes: 21 additions & 9 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ import {
MDBSelect,
} from "mdb-react-ui-kit";

// const CASE_1 = "Case 1: Θ(n<sup>log<sub>b</sub>(a)</sup>)";
// const CASE_2 = "Case 2: Θ(n<sup>k</sup> log n)";
const CASE_3 = "Case 3: Θ(n<sup>k</sup>)";

interface ResultType {
complexity: string;
case: string;
recurrence_relation: string;
regularity_condition_met?: boolean;
plot_data: {
n: number[];
n_log_b_a: number[];
Expand Down Expand Up @@ -338,6 +343,14 @@ function App() {
<span dangerouslySetInnerHTML={{ __html: result.case }}></span>
</MDBCardText>

{result.case.includes(CASE_3) && ( // Check if the case includes the string for Case 3
<MDBCardText>
<strong>Regularity Condition Met:</strong>{" "}
{result.regularity_condition_met !== undefined && // Check if regularity_condition_met is defined
(result.regularity_condition_met ? "Yes" : "No")}
</MDBCardText>
)}

<MDBCardText>
<strong>Time Complexity: </strong>
<span
Expand Down Expand Up @@ -525,7 +538,12 @@ function App() {
<sup>
log<sub>b</sub>(a)
</sup>{" "}
(and also fulfills the regularity condition<sup>*</sup>) :
(and must also fulfill the{" "}
<strong>
regularity condition
<sup>*</sup>)
</strong>{" "}
:
</p>
<p className="text-center">
<strong>
Expand Down Expand Up @@ -557,14 +575,8 @@ function App() {
</ul>
<p>
<small>
<strong>*</strong> Please note that this app evaluates n
<sup>
log<sub>b</sub>(a)
</sup>
and f(n<sup>k</sup>) using their exponents and does not assess
the regularity condition in Case 3, or whether the difference
in growth between these two functions is polynomial. The
regularity condition ensures that the work done at the
<strong>* </strong>
The regularity condition ensures that the work done at the
recursive levels does not grow too quickly compared to the
work done to divide the problem and combine the results. This
condition helps maintain the integrity of the complexity
Expand Down
10 changes: 5 additions & 5 deletions mastertheorem/tests/test_master_theorem.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ def test_recurrence_relation_output(a: int, b: int, k: int, expected_recurrence_
assert recurrence_relation == expected_recurrence_relation, f"Recurrence relation does not expected output for parameters a={a}, b={b}, k={k}"

@pytest.mark.parametrize("a,b,k,expected_regularity", [
(4, 2, 3, True), # Regular condition met
(10, 2, 3, False), # Regular condition not met
(8, 2, 3, False), # Case 3 but does not satisfy the regularity condition.
(9, 2, 3, False), # Just over the edge, regularity condition not met
(4, 2, 3, True), # Case 3, Regularity condition met.
(10, 2, 3, False), # Case 1, regularity condition not applicable.
(8, 2, 3, False), # Case 2, regularity condition not applicable.
(9, 2, 3, False), # Case 1, regularity condition not applicable.
(2, 2, 1, False), # Case 2, regularity condition not applicable.
(1000, 10, 3, False), # Large numbers, regularity condition not met
(1000, 10, 3, False), # Case 3 with large values, testing the function's ability to correctly evaluate the regularity condition despite the significant value of 'a'. Regularity condition not met, demonstrating the function's robustness in handling extreme or non-intuitive scenarios within Case 3's criteria.
])
def test_regularity_condition(a: int, b: int, k: int, expected_regularity: bool):
_, _, _, regularity_condition_met = evaluate_master_theorem(a, b, k)
Expand Down
Loading

0 comments on commit 84cca90

Please sign in to comment.