I want to find the highest number in a time series, in the most efficient way.To avoid iterating through all the look back periods, I'm only iterating in case the current high number has just been discarded. I'm avoiding enqueue dequeue for the same performance reasons.What would be a faster algorithm?class Program{    static Random r = new Random();    static int LookBackPeriods = 5; //(small to facilitate visual functional test). eventually could be 100 1000, but not more than 5000.    static double High=0;    static int HighLocation = 0;    static int CurrentLocation = 0;    static double[] arr = new double[LookBackPeriods];    static void Main(string[] args)    {        //functional test - generate 100 numbers and check them in as you go:        for (int i = 0; i < 100; i++)            CheckInCandidate(r.Next(10)); //in final application these will be real numbers        Console.ReadLine();    }    /// <summary>    /// A full iteration on all numbers (run only when the current high is overwritten)    /// </summary>    static void ReFindHighest()    {        High = arr[0];        HighLocation =0        for (int i = 1; i < LookBackPeriods; i++)            if (arr[i] > High)            {                High = arr[i];                HighLocation = i;            }    }    /// <summary>    /// minimized check that should run most of the time a new number arrives    /// </summary>    static void CheckInCandidate(double currentNum)    {        arr[CurrentLocation] = currentNum;        if (currentNum >= High)        {            HighLocation = CurrentLocation;            High = currentNum;        }        else if (CurrentLocation == HighLocation)            ReFindHighest();        CurrentLocation++;        //if (CurrentLocation == HistoryLength) CurrentLocation=0; //is this faster??        CurrentLocation = CurrentLocation % LookBackPeriods; //is this faster??        Console.WriteLine(Current: + currentNum + \tHighest of  + LookBackPeriods + last is  + High); //for validation purposes only.    }}
Track the highest high in a time series
c#;algorithm