1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to order a set of real numbers?

  1. Feb 24, 2012 #1
    1. The problem statement, all variables and given/known data
    How to order a set of real numbers, from the smallest to the largest, without knowing any members of the set, but knowing that there are finite members, and that these members are all real numbers?


    2. Relevant equations
    -

    3. The attempt at a solution
    Tried Googling without any success.
     
  2. jcsd
  3. Feb 24, 2012 #2
    Is this for a computer science class? In other words are they after a sorting algorithm?

    Otherwise, what does the question mean? You go through the numbers and pick the smallest; then you go through the remaining numbers and pick the smallest; etc.

    If you're in an algorithms class they'll be interested in variations of that basic idea. Look up Bubble Sort if you're in a computer science class. But if it's a math class, I don't think I understand the question. Mathematically, the only aspect of this problem that's of interest is that if there are finitely many real numbers, there must be a smallest one. That's not necessarily true for an infinite collection.

    (edit)
    Is this a notation question? Something like {x_1, ..., x_n in R: i < j => x_i < x_j} ?

    I noticed you had another set notation question in a different thread.
     
    Last edited: Feb 24, 2012
  4. Feb 24, 2012 #3
    Thanks for your input.

    Let's say that A = {1, 7, 3, 5, 2}

    I'm searching for a mathematical operation which would allow me to sort A from the smallest to the largest:

    Asorted = {1, 2, 3, 5, 7}

    I need this to be able to apply the order statistics operation "max" and "min" on a set, which outputs maximum and minimum extremes of a set, in order to be able to find out the largest number of a set.

    To do this, I first need to sort the set, then to apply the max algorithm.

    So to find the largest value of the A set, one would write max Asorted, or max{1, 2, 3, 5, 7}.
     
  5. Feb 24, 2012 #4
    The max is the max no matter what order you present the elements of the set.

    max {1, 2, 3, 4} is the same number (namely 4) as max {3, 1, 4, 2}.

    And for that matter, the sets {1, 2, 3, 4} and {3, 1, 4, 2} are the same set. Set notation does not imply anything about the order of the elements.
     
  6. Feb 24, 2012 #5

    Mark44

    Staff: Mentor

    Unless the set of real numbers is a finite set, there is no smallest member and there is no largest member.

    You don't need to sort the set. You can make one pass through the unsorted set to pick out the largest. Here is some C code that would find the largest value of an array.
    Code (Text):

    #include <stdio.h>
    int A[] = {1, 7, 3, 5, 2};

    int findMax(int []);  // prototype for the findMax function

    int main(void)
    {
       int max = findMax(A, sizeof(A));
       printf("The largest value is %d", max);
       return 0;
    }

    int findMax(int [] list, int size)
    {
       // Choose a value that is certain to be smaller than any element in the list.
       int max = -1000000;  
       for (int i = 0; i < size; i++)
       {
          if (list[i] >= max)
          {
             max = list[i];
          }
       }
       return max;
    }
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: How to order a set of real numbers?
Loading...