Moving Average from Data Stream

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ธ.ค. 2024

ความคิดเห็น • 20

  • @Sanjeev.Network
    @Sanjeev.Network 6 ปีที่แล้ว +3

    Thank you Kevin, same format question were asked on HACKER EARTH HIRING CONTEST 1 month ago.

  • @letslearnjava1753
    @letslearnjava1753 5 ปีที่แล้ว +5

    Exactly same can be used to smooth data also...this is actually a concept of Digital Image Processing....to remove the noise this idea is used

  • @galanoth17
    @galanoth17 2 ปีที่แล้ว

    I had no idea what the question and example was asking me to do. They need better clarification on the question. Thaks for the clarification.

  • @craigdubable
    @craigdubable 4 ปีที่แล้ว +3

    Hey this is great! A more memory efficient way of doing this is using a circular buffer :)

    • @adi_sekar
      @adi_sekar 3 ปีที่แล้ว

      How is circular buffer better? Can you explain @craig williams

    • @harigovind11
      @harigovind11 2 ปีที่แล้ว

      With circular buffer one can use a simple array with that window size and once it's full keep replacing elements from beginning of array with new elements using an additional index. Once that index reaches the end simply reset it. So not much overhead of a queue.

    • @leotaozeng
      @leotaozeng 2 หลายเดือนก่อน

      Do you mean a circular queue?

  • @nwokolobueze7291
    @nwokolobueze7291 2 ปีที่แล้ว

    I had to clap for you after watching this video. Great thoughts right there.

  • @deepaligarg2978
    @deepaligarg2978 2 ปีที่แล้ว

    Good Explanation. Thanks for making this video.

  • @budguesor9222
    @budguesor9222 3 ปีที่แล้ว

    If I use an ArrayList instead of a Queue, and keep removing the 0th element each time, using list.remove(0), will that be equally efficient as using a Queue? or would that be slower?

    • @johnuckele1922
      @johnuckele1922 3 ปีที่แล้ว

      ArrayList will be much slower. Removing the first element of an array is usually done by making a new array and copying all of the values minus the first one over, or by moving every element but the first one to the left. Either way, this takes O(n) operations where n is the size of the array. Java's ArrayDequeue will optimize this specific case if you use the poll() method, but will still be O(n) if you use the remove(0) method. LinkedList's .remove(0) and poll() methods are both O(1) time.

  • @sindhujachandran1334
    @sindhujachandran1334 5 ปีที่แล้ว

    Hi can you solve more OO design questions?

  • @rogerwhite8061
    @rogerwhite8061 6 ปีที่แล้ว +1

    Fantastic thank you so much

  • @sanjeevdiitm
    @sanjeevdiitm 4 ปีที่แล้ว

    Thanks!

  • @yili9725
    @yili9725 2 ปีที่แล้ว

    better solution:
    int[] buff;
    int size;
    int total = 0;
    int count = 0;
    public MovingAveragefromDataStream (int size) {
    this.size=size;
    buff = new int[size];
    }
    public double next (int val) {
    int minus = buff[count];
    buff[count] = val;
    total = total - minus + val;
    count++;
    if (count==size)
    count=0;
    return (double)total/(double)size;
    }
    you don't need a queue, just a buffer with a pointer of count%size.

  • @CORCODING
    @CORCODING 4 ปีที่แล้ว

    Subbed !

  • @rahuldabas8233
    @rahuldabas8233 4 ปีที่แล้ว

    great code