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

Поділитися
Вставка
  • Опубліковано 25 січ 2025

КОМЕНТАРІ • 30

  • @burstfireno1617
    @burstfireno1617 Рік тому +6

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

    • @enzozbestetti5992
      @enzozbestetti5992 7 місяців тому

      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

    • @subha2816
      @subha2816 15 днів тому +1

      You can obtain the length of an array so it's possible to determine the frequency of any number

  • @FLUTTER_HUB
    @FLUTTER_HUB 7 місяців тому +1

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

  • @WezardWez-lee
    @WezardWez-lee 2 місяці тому

    THANK YOU VERY MUCH SIR.
    I REALLY LOVE TGE WAY U EXPLAINED.
    I'M DEFINITELY SUBSCRIBING TO THIS

  • @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 UA-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.🙏🏻🙏🏻

  • @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! :-)

  • @yangliu5727
    @yangliu5727 Рік тому

    can you make a video about Heap Sort

  • @Vyom330
    @Vyom330 11 місяців тому

    what is the difference between max_value and max__occurenceis??

    • @PortfolioCourses
      @PortfolioCourses  11 місяців тому

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

  • @kaarthiksai1089
    @kaarthiksai1089 Місяць тому

    Thank you so much

  • @AnandhuV-lu1io
    @AnandhuV-lu1io 8 місяців тому

    helpful video❤‍🔥

  • @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

  • @rikohalim4972
    @rikohalim4972 Рік тому

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

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

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