Class Median

java.lang.Object
topics.divideconquer.Median

public class Median extends Object
//DIVIDE AND CONQUER PROBLEM: THE MEDIAN OF n ELEMENTS
Author:
vicegd
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    median1(int[] v)
    This method sorts the vector O(nlogn) and then it is a very basic operation O(1), so its calculation is O(nlogn) + O(1) - O(nlogn)
    int
    median2(int[] v)
    This method is recursive and is based on the concept of partition seen for the Quicksort algorithm.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Median

      public Median()
  • Method Details

    • median1

      public int median1(int[] v)
      This method sorts the vector O(nlogn) and then it is a very basic operation O(1), so its calculation is O(nlogn) + O(1) - O(nlogn)
      Parameters:
      v - Array to calculate the median
      Returns:
      Median value in the array
    • median2

      public int median2(int[] v)
      This method is recursive and is based on the concept of partition seen for the Quicksort algorithm. It is DandC by division with a=1, b=2, k=1 - O(n)
      Parameters:
      v - Array to calculate the median
      Returns:
      Median value in the array