From a theorem to a reliable algorithm
A correct algorithm states its inputs, uses an unambiguous sequence and returns an output on every path. Test boundary and invalid cases, then justify the decisions mathematically
- Input contract Use three positive lengths in one unit. Reject a straight, zero-area shape
- All-three design Each pair of lengths must add to more than the third. Combine the three tests with AND \(\displaystyle \begin{gathered}a+b>c\\a+c>b\\b+c>a\end{gathered}\)
- Sorted design Sort so a ≤ b ≤ c. Only the two shortest lengths need to be added: require a + b > c.
- Test and justify Test a valid triangle, the equality boundary, an impossible triple and changed input orders. Explain why the rule works, not only that examples passed
Worked example
A draft reads (13, 5, 7) and tests only the first pair. Trace the error, refine the sequence and justify the new result
- \(\displaystyle 13+5=18>7\)The unsorted draft outputs YES
- \(\displaystyle 5+7=12<13\)The two shorter lengths cannot span 13, so that output is wrong
- \(\displaystyle a=5,\quad b=7,\quad c=13\)Refine the sequence: sort before the single decision
- \(\displaystyle a+b>c\quad\text{is false}\)Output NO. Recheck valid, equality and gap triples. Explain that positivity and sorting make the other two inequalities automatic
Common mistakes
Difficulty levels
Questions about this topic
Why must the inequality be strict?+
Equality places the three vertices on one straight line and gives zero area. A non-degenerate triangle needs the sum of the shorter sides to be greater than the longest
Why does sorting allow one comparison?+
For positive a ≤ b ≤ c, adding a positive length to c already exceeds either smaller side. Only the sum of the two shortest sides might fail to exceed c.
What should be in my test plan?+
Include a valid triangle, the equality boundary, an impossible triple and reordered versions. State the expected result before running the algorithm
Does this automatically mark my own pseudocode?+
No. The lab executes named designs, and practice marks specific tracing and reasoning tasks. Review your independent written design and report against the criteria, with a teacher if available
Do triangle algorithms always need integer lengths?+
No. The theorem applies to positive real lengths in one unit. The lab uses small whole numbers to make testing convenient
Can I use a calculator?+
No. This topic is practised without a calculator
Which year level and chapter is this?+
Year 9 Mathematics, chapter 7: Geometry and similarity