The median is defined as the middle element of a sorted array, or the average of the middle two elements if the array has an even number of elements.