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: Traversing a min heap to get sorted

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Traversing a min heap to get sorted

    Hi there,

    Is it possible to traverse a min heap to get a sorted list? Using pre/post/in traversal.?

    Just need to clear some concept issues.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Traversing a min heap to get sorted

    Quote Originally Posted by derek View Post
    Hi there,

    Is it possible to traverse a min heap to get a sorted list? Using pre/post/in traversal.?

    Just need to clear some concept issues.
    In the traditional sense of the word traversal, I don't think you can do this. I believe the tree must first be sorted (for example with a heapsort) and then traversed.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Traversing a min heap to get sorted

    Traversing through a heap has little meaning in terms of sorted order (either min heap or max heap). You must remove the top item from the heap and re-validate the heap to get the items back into a sorted order.

    Traversing through a binary search tree using "in-order" traversal (left, node, right) will give you the sorted order of the items.

Similar Threads

  1. Sorted Doubly linked List
    By student in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 15th, 2010, 09:52 PM
  2. Replies: 1
    Last Post: March 15th, 2010, 10:03 PM
  3. How to create a sorted set from the contents of an array
    By davie in forum Collections and Generics
    Replies: 1
    Last Post: March 11th, 2010, 03:44 PM
  4. Merge 2 Sorted Text Files into a Third
    By Epyllion in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 10th, 2010, 08:24 PM
  5. traversing multiple jTabbedPane?
    By dewboy3d in forum AWT / Java Swing
    Replies: 3
    Last Post: October 2nd, 2009, 07:26 PM