VOOZH about

URL: https://www.geeksforgeeks.org/dsa/interquartile-range-iqr/

⇱ Interquartile Range (IQR) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Interquartile Range (IQR)

Last Updated : 4 Nov, 2025

The quartiles of a ranked set of data values are three points that divide the data into exactly four equal parts, each part comprising quarter data. 

  1. Q1 is defined as the middle number between the smallest number and the median of the data set.
  2. Q2 is the median of the data.
  3. Q3 is the middle value between the median and the highest value of the data set.
The interquartile range IQR tells us the range 
where the bulk of the values lie. The interquartile
range is calculated by subtracting the first quartile
from the third quartile.
IQR = Q3 - Q1

Uses
1. Unlike range, IQR tells where the majority of data lies and is thus preferred over range. 
2. IQR can be used to identify outliers in a data set. 
3. Gives the central tendency of the data. 

Examples:

Input : 1, 19, 7, 6, 5, 9, 12, 27, 18, 2, 15
Output : 13
The data set after being sorted is
1, 2, 5, 6, 7, 9, 12, 15, 18, 19, 27
As mentioned above Q2 is the median of the data.
Hence Q2 = 9
Q1 is the median of lower half, taking Q2 as pivot.
So Q1 = 5
Q3 is the median of upper half talking Q2 as pivot.
So Q3 = 18
Therefore IQR for given data=Q3-Q1=18-5=13

Input : 1, 3, 4, 5, 5, 6, 7, 11
Output : 3

Below is the implementation of the above approach:


Output
13

Time Complexity: O(n * log(n)), due to sorting of array.
Auxiliary Space: O(1)


Comment
Article Tags: