Question: Please write an algorithm in Java that is going to print an answer after put random sequence. Given a sequence of numbers = 4 1

Please write an algorithm in Java that is going to print an answer after put random sequence.

Given a sequence of numbers = 4 1 17 18 1 8 7 15 7 1 2, if you are going to percolate down from the 2nd number , the sequence becomes = _?_

Answer: Given:

  1. Perforation starts at = 2nd number
  2. Sequence = 4 1 17 18 1 8 7 15 7 1 2

Process:

  1. Iteration parent at 2
    • --Children at 4 and 5: 4 1 17 18 1 8 7 15 7 1 2 *
    • --First child is bigger. Focused child is at 4
    • --Compare the bigger child and the parent
    • --Child is bigger, then swap: 4 18 17 1 1 8 7 15 7 1 2 *
  2. Iteration parent at 4
    • --Children at 8 and 9: 4 18 17 1 1 8 7 15 7 1 2 *
    • --First child is bigger. Focused child is at 8
    • --Compare the bigger child and the parent
    • --Child is bigger, then swap: 4 18 17 15 1 8 7 1 7 1 2 *
  3. --DONE2: because no more children: 4 18 17 15 1 8 7 1 7 1 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!