Results 1 to 7 of 7

Math Help - Set in an algorithm

  1. #1
    Newbie
    Joined
    Jul 2011
    Posts
    9

    Set in an algorithm

    Hello

    In part of an algorithm that I am working on, there are two sets, they both have the same elements, except that one has one element more than the other. For example:

    A={a,b,c}
    B={a,b}

    I have written two versions:

    H= A - B
    array1[h] = f (where h isMemberOf H)

    and (h is meant to be a variable)

    {h} = A - B
    array1[h] = f


    Is any of these notations correct? What do you advise?

    Thanks in advance
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,528
    Thanks
    773

    Re: Set in an algorithm

    My guess is that this is intended as a comment, not as an actual program code. In this case I would add some text, like "A - B is a singleton because ... Let {h} = A - B".
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jul 2011
    Posts
    9

    Re: Set in an algorithm

    Quote Originally Posted by emakarov View Post
    My guess is that this is intended as a comment, not as an actual program code. In this case I would add some text, like "A - B is a singleton because ... Let {h} = A - B".
    Thanks for your reply. This is meant to be as actual program code. Is it wrong to have sets in algorithms then?
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,528
    Thanks
    773

    Re: Set in an algorithm

    If it's an actual programming language (could you say which one?), then this depends on the language. If it's pseudocode, then there is not much difference. The first variant: "array1[h] = f (where h isMemberOf H)" does not look like a deterministic instruction because the computer may not know that there is a single element in H. The second variant resembles a pattern matching in functional languages. In general, the left-hand side of an assignment must be a variable, nor a construction like {h}. However, in functional languages you may say something like "let {h} = A in B". This means: "if A has the form {h}, then evaluate B with h assigned". The program may fail if the pattern in the left-hand side does not match the value in the right-hand side.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Jul 2011
    Posts
    9

    Re: Set in an algorithm

    Thank you for your reply.

    My apologies for the mistake made in my comment.

    I meant to say this algorithm is meant to used by an actual programmer to develop code.

    To increase efficiency, it would be best if we can use sets. What I am not sure of, is how to properly write an algorithm that includes sets and set operations.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Super Member ILikeSerena's Avatar
    Joined
    Dec 2011
    Posts
    733
    Thanks
    121

    Re: Set in an algorithm

    Hi suzanne!

    I recommend using mathematical language if it is about mathematics and leave it up to the programmer how to implement it.

    As it is, it is not clear to me what you mean by: array1[h] = f (where h isMemberOf H)

    What is array1 supposed to be?
    Is it a set? Or an array as its name seems to imply?
    What does it mean that you assign it a value of f?
    Is that intended to represent "false"?
    If so, then for clarity, you should name it "false" instead of "f".
    Follow Math Help Forum on Facebook and Google+

  7. #7
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,528
    Thanks
    773

    Re: Set in an algorithm

    Quote Originally Posted by ILikeSerena View Post
    I recommend using mathematical language if it is about mathematics and leave it up to the programmer how to implement it.
    I agree.

    Quote Originally Posted by suzanne View Post
    I meant to say this algorithm is meant to used by an actual programmer to develop code.
    If this algorithm is intended to be read by a person, not a computer, then there is not much difference. You could write

    array1[h] = f where h ∊ A - B

    or

    let {h} = A - B
    array1[h] = f

    The only thing that should be clear is why there is a unique h ∊ A - B at this point in the algorithm. A person who reads this should not have doubts about which elements of A - B to use and why this set is not empty. This may take a comment or an explanation.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. algorithm
    Posted in the Advanced Applied Math Forum
    Replies: 3
    Last Post: January 19th 2010, 02:46 AM
  2. Algorithm
    Posted in the Advanced Math Topics Forum
    Replies: 7
    Last Post: November 22nd 2009, 07:11 AM
  3. algorithm
    Posted in the Math Topics Forum
    Replies: 2
    Last Post: July 16th 2008, 01:29 PM
  4. Algorithm
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: February 27th 2008, 01:02 PM
  5. gcd algorithm
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: December 4th 2007, 11:47 PM

Search Tags


/mathhelpforum @mathhelpforum