#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13

    Calculating the statistical mode


    how do i find the mode of a list?

    by this i mean the value that appears the most in a particular list.

    for example:
    List (array): 1, 2, 3, 3, 3, 5, 5, 10
    Mode : 3

    or

    List (array): 1, 2, 3, 3, 3, 5, 5, 5
    Mode: 3 and 5

    thank you.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    10
    Rep Power
    0

    Red face


    :rolleyes:
    Perhaps you should create a list (i mean the data structure where every element has a pointer to the next element) which will contain two numbers - first is the value of an item in your original list, and second is the number of times you have encountered that value in your original list.

    I hope my bad English and too complex phrase construction will not be a barrier between out developing minds %-[]

    :rolleyes:
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    10
    Rep Power
    0
    as for your example - you'll have 4 nodes in your generated list, with values
    1 1
    2 1
    3 3
    5 3
    respectively (pointers included).
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13
    !

    I wrote a program that found the mean, median, mode and range =) here is the part where it finds the mode:

    Code:
    void mode(double* nums, unsigned int choice)
    {
    	unsigned int index;
    	int count=0;
    	int max =0;
    	for(index=0; index<choice; index++)
    	{
    		if(nums[index]==nums[index+1])
    			count++;
    		else
    		{
    			if(count>max)
    				max=count;
    			count=0;
    		}
    	}
    	count=0;
    	for(index=0; index<choice; index++)
    	{
    		if(nums[index]==nums[index+1])
    			count++;
    		else
    		{
    			if(count==max)
    				cout<<"Mode(s):\t" <<nums[index]<<"\n";
    			count=0;
    		}
    	}
    }
    :] hope this helps
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    10
    Rep Power
    0

    Unhappy nonono


    It will return only the count of the longest sequence of identical numbers.
    But as I understand, you need to return the VALUE which is the most frequently appears in the whole sequence.
    e.g. for a sequence

    1, 2, 3, 4, 2, 4, 4, 2

    your function will return THE COUNT 2 (of a value 4)
    but the modes are THE VALUES 2 and 4 (appear 3 times both)
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13
    i am not really sure what u are tryin to say :(

IMN logo majestic logo threadwatch logo seochat tools logo