Find The Most Frequent Value In An Array | C Programming Example

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024
  • How to find the most frequently occurring value in an array using C. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

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

  • @burstfireno1617
    @burstfireno1617 10 หลายเดือนก่อน +4

    What if we wanna find the most frequent number in an array and we don't now the numbers?

    • @enzozbestetti5992
      @enzozbestetti5992 3 หลายเดือนก่อน

      The algorithm is the same. You need to adjust the length variable to be: int length = sizeof(array)/sizeof(int);
      Other than that, nothing should need to change

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

    your videos are very helpful thanks a lot!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      You're very welcome, I'm glad you're finding them helpful! :-)

  • @adicodes11
    @adicodes11 ปีที่แล้ว +2

    I love watching your videos, I was just curious if we take this problem statement to a next level where .. what if a certain number occurs for the same number of time as that the other i.e., if arr[]={1,2,2,3,3} ; , if we go by the above mentioned algorithm, we will just get max_value as 2 and max_occurrence as 2 which will be unfair to 3 which too occurs for the maximum number of times that is 2 .
    What can we do to print all the most occurring number as well as their occurrences in such cases ? 😅, I tried but can't come up with an optimal solution .

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +2

      This is a great question but completely answering it might be too long for what I can cover in a TH-cam comment. :-)
      I think we would need to store each "max value" in an array. Whenever we find a max value with occurrences greater than the existing max value, we would wipe out whatever is in the array and this value would become the new and only max value. But if we find a new max value with a "tying / equal" amount of occurrences, we would add it to the array of values instead. And then when we're done checking all the elements in the array we could output whatever is in the "max values array". That would be the general idea.
      Another way would be to count the occurrences of "everything" and store the results into an array of structs where each struct stores the value and number of occurrences, and then sort that array of structs by the number of occurrences, and check using the sorted array to see if there are any values that share the maximum number of occurrences. :-)

    • @adicodes11
      @adicodes11 ปีที่แล้ว

      @@PortfolioCourses oh you actually corrected me there, tysm for the suggestion 😀

    • @Narang894
      @Narang894 ปีที่แล้ว

      ​@@PortfolioCoursescode dedijiye iska.please.

    • @Narang894
      @Narang894 ปีที่แล้ว

      I was thinking the same question and see I found your comment if you have find the code please share the same to me.

    • @Narang894
      @Narang894 ปีที่แล้ว

      ​@@adicodes11
      I was thinking the same question and see I found your comment if you have find the code please share it to me.🙏🏻🙏🏻

  • @AnandhuV-lu1io
    @AnandhuV-lu1io 3 หลายเดือนก่อน

    helpful video❤‍🔥

  • @FLUTTER_HUB
    @FLUTTER_HUB 3 หลายเดือนก่อน

    if in array two values are hold max occurance ,how to manage it

  • @rikohalim4972
    @rikohalim4972 10 หลายเดือนก่อน

    will it work the same if i put the “if (occurences > max_occurences)” inside the inner loop?
    Love your videos🙌🏻

    • @PortfolioCourses
      @PortfolioCourses  10 หลายเดือนก่อน

      Yes that should work the same. And I’m glad you enjoy the videos! :-)

  • @yangliu5727
    @yangliu5727 ปีที่แล้ว

    can you make a video about Heap Sort

  • @Vyom330
    @Vyom330 7 หลายเดือนก่อน

    what is the difference between max_value and max__occurenceis??

    • @PortfolioCourses
      @PortfolioCourses  7 หลายเดือนก่อน

      max_value is the value itself that occurs most frequently, and max_occurrences is the number of times that value occurs

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

    How to write this program?
    Write a c program to read a sentence from user and then remove all articles from it and display the updated sentence.
    Eg.
    Input:An apple a day.
    Output:apple day.

    • @gerdsfargen6687
      @gerdsfargen6687 ปีที่แล้ว

      What do you mean by articles....wouldn't you just make a list of the words to exclude and then check and remove them

    • @yogeshchauhan9401
      @yogeshchauhan9401 ปีที่แล้ว

      @@gerdsfargen6687 in c not python

    • @gerdsfargen6687
      @gerdsfargen6687 ปีที่แล้ว

      ​@yogeshchauhan9401 true..sorry I didn't check..yes lists can't be done in c. I wish I could help.

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

      I can give you some hints: look into strtok, strcmp and set a list of strings that contains all articles. You can set such a list like this: char mylist[NUMBER_OF_ARTICLES][MAX_LENGTH_OF_ARTICLES]

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

      @@Albertinio1994 u mean 2d array