Given the length of all three sides of a triangle as a, b and c. The task is to calculate the length of the median of the triangle.
A median of a triangle is a line segment joining a vertex to the midpoint of the opposite side, thus bisecting that side.
Input: a = 8, b = 10, c = 13
Input: a = 4, b = 3, c = 5
Approach: The idea is to use Apollonius’s theorem to solve this problem.
Apollonius’s Theorem states that “the sum of the squares of any two sides of a triangle equals twice the square on half the third side and twice the square on the median bisecting the third side”.
From the above figure, According to Apollonius’s Theorm we have:
where a, b, and c are the length of sides of the triangle
and m is the length of median of the triangle on side 2*a
Therefore, the length of the median of a triangle from the above equation is given by:
Below is the implementation of the above approach:
Time Complexity: O(1)
Space Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Length of remaining two sides of a Triangle from a given side and its adjacent angles
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Find area of triangle if two vectors of two adjacent sides are given
- Find the hypotenuse of a right angled triangle with given two sides
- Find the type of triangle from the given sides
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Find other two sides of a right angle triangle
- Find other two sides and angles of a right angle triangle
- Check whether triangle is valid or not if sides are given
- Check whether right angled triangle is valid or not for large sides
- Probability of cutting a rope into three pieces such that the sides form a triangle
- Length of Diagonals of a Cyclic Quadrilateral using the length of Sides.
- Length of a Diagonal of a Parallelogram using the length of Sides and the other Diagonal
- Area of Circumcircle of an Equilateral Triangle using Median
- Find area of parallelogram if vectors of two adjacent sides are given
- Length of diagonal of a parallelogram using adjacent sides and angle between them
- Circumradius of a Cyclic Quadrilateral using the length of Sides
- Count number of triangles possible with length of sides not exceeding N
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.