Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Discrete Structures Class

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Discrete Structures Class

    Write an algorithm that returns the index of the last occurrence of the value key in a sequence s1, …,sn. If key is not in the sequence, the algorithm returns 0. Example, if the sequence is 12 11 12 23 and key is 12, the algorithm returns 3.

    I need full explanation because I am not understanding this class just yet.


  2. #2
    Member Hikaros's Avatar
    Join Date
    Sep 2013
    Posts
    42
    My Mood
    Love
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Default Re: Discrete Structures Class

    You may find these quite useful List of Videos for Intermediate Java

    specially the first 2 and then starting from collections (they are short, like 5 minutes long each)

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Discrete Structures Class

    Quote Originally Posted by rharvell View Post
    Write an algorithm that returns the index of the last occurrence of the value key
    That means start at the end, or the last element, and work toward the front looking for the requested value. For example, in 12 11 12 23, it means start at 23, is 23 the key (12), no, keep looking. Move back to 12. Is 12 the key (12), yes. Return it. Note that it is in index 2 not index 0. Also beware that this is to return the key, not the positional index, and 0 represents "not found"
    Quote Originally Posted by rharvell View Post
    in a sequence s1, …,sn.
    This just means the set of elements can be any given length.
    Quote Originally Posted by rharvell View Post
    If key is not in the sequence, the algorithm returns 0.
    If the requested key (12 in the example) is not found, return 0.

Similar Threads

  1. Circular Queue Structures
    By LeeDD in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 14th, 2013, 01:34 PM
  2. File Structures and Format
    By sci4me in forum Java Theory & Questions
    Replies: 3
    Last Post: March 10th, 2013, 05:44 PM
  3. data structures question
    By hwoarang69 in forum Algorithms & Recursion
    Replies: 2
    Last Post: November 4th, 2012, 03:07 PM
  4. Please help about data structures.
    By bruce88 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 16th, 2012, 04:11 PM
  5. Discrete Cosine transform(dct)
    By skillet in forum AWT / Java Swing
    Replies: 0
    Last Post: April 7th, 2012, 11:52 PM