Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The problem is pretty self explanatory. However, I have included the tables needed to be used for the illustration of the comparison codes. The first
The problem is pretty self explanatory. However, I have included the tables needed to be used for the illustration of the comparison codes. The first image down below is the problem and then the ones following that would coincide with the illustration tables explained. Please answer all of the problem completely using the tables. There is no need to answer only half of the question! I will rate afterwards depending on the response!
Homework 2: due at 1230pm on Thu, Feb 13, 2020 Covered Material: Sections 3.1-3.6 of the zyBook for the course. Problems (55 pts): 1. (35 pts) Use figures 1-3 in the attached illustrations as models to show the operations of selection, insertion and shell sorts on the input array {1, 6, 7,5, 0, 9, 8, 4, 3, 2}. For shell sort, use the gap values 7, 3, and 1, in that order. 2. (10 pts) Use figure 4 in the attached illustrations as a model to show the operations of the algorithm partition used by quicksort on (A, 0, 9), where A = {1, 6, 7,5, 0, 9, 8, 4, 3, 2}. 3. (10 pts) Use figure 5 in the attached illustrations as a model to show the operations of the algorithm merge, used by merge sort on (A, 0, 4, 9), where A = {1, 6, 7, 5, 0, 9, 8, 4, 3, 2}. For your convenience, the editable word doc file that was used to produce the attached illustrations is also posted under Homework Assignments. You may use it if you wish. Illustration of operations: Comparison Sorts Legend: Solid lines indicate elements compared. Double arrows indicate elements moved. - Fig 1: Operation of selection sort on 019 | 8 | 1| 2 | 3 | 7 | 6 | 45 0|1 | 2 | 3 | 4 | 5 | 7 | 6819 0|1| 8 | 9 | 2 | 3 | 7|6|4|5] 0|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 [0|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0|1|2|3 | 8 | 9|716|4|5] Fig 2: Operation of insertion sort on 0|9|8||1|2|3 | 7 | 6 || 4 | 5 0|1|2|3 | 8 | 9 | 7 | 6|4|5 0 | 1 | 2 | 3 | 7 | 8 | 9 | 6|4|5] 0 | 8 | 9 | 1 | 2 | 3 | 7|6|4|5 0 | 1|2|3 | 6 | 7 | 8 | 9|4|5] 0 1 2 3 4 6 | 7 | 8 | 9 5 0 | 1 | 2 | 8 | 9 | 3|7|6|4|5 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Fig3:Operation of Shell sort on with gap values 5, 3 and 1. Pass 1, gap = 5 | 0 | 3 | 6. 1L4 Array after pass 1: | [[[6]|2|| || 4 || Pass 2, gap = 3 | 0 | 1 | 7 | 5 N | Array after pass 2: [[[2|| 1 | | | | |[] Pass 3, gap = 1 3 [[2|| [6] [5] []]| |[0][2] [5] [6] [] ] [[[1] 2|| 5 | 5 | 61 | | 9] Array after pass 3: | Fig 4:Operation of partition on (A, 0, 9), where A = {0, 9, 8, 1, 3, 2, 3, 6, 4, 5} and pivot = A[4] = 3. The value h = 3 is returned. =2 h=4 |||||||| ||| || [2 ] [3 ] Fig 5: Operation of merge on (numbers, 0, 4, 9), where numbers = {0, 2, 4, 5, 7, 1, 3, 6, 8, 9} and array indices start with 0. Initial values: leftPos = 0, rightPos = 5, mergePos = 0 numbers: mergeNumbers: 10|2|4|5|7| 1 3 1 61819 0124517| 1 3 1 61819 After Iteration 1: leftPos = 1, rightPos = 5, mergePos = 1 numbers: mergeNumbers: 10|12|4|5|7|| 1 | 3 | 6 | 8 |9 012101517| 1 | 3 | 6 | 8 | 9 After Iteration 2: leftPos = 1, rightPos = 6, mergePos = 2 numbers: After Iteration 3: leftPos = 2, rightPos = 6, mergePos = 3 numbers: mergeNumbers: 101214 | 5 | 7| 1 | 3 | 6 | 8 |9 01112|5|7| 1 | 3 | 6 | 8 9 After Iteration 4: leftPos = 2, rightPos = 7, mergePos = 4 numbers: mergeNumbers: After Iteration 5: leftPos = 3, rightPos = 7, mergePos = 5 numbers: mergeNumbers: 02| 4 | 5 7 1368 0|1|2|34 13 689|| After Iteration 6: leftPos = 4, rightPos = 7, mergePos = 6 numbers: mergeNumbers: 10|2|4|5|7| 1 3 1 61819 011|2|3|4|5| 3 | 61 819 After Iteration 7: leftPos = 4, rightPos = 8, mergePos = 7 numbers: mergeNumbers: 101214 5 7 1 3 16 819 711|2|3|4|5|6|6|89| After Iteration 8: leftPos = 5, rightPos = 8, mergePos = 8. The main loop ends here. numbers: mergeNumbers: 012 4 571 3 6 8 9 0 1 2 3 4 5 6 7 8 9 After the rest of merge is executed: leftPos = 5, rightPos = 10, mergePos = 10 numbers: mergeNumbers: 101 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 011|2|3|4|516171819 Homework 2: due at 1230pm on Thu, Feb 13, 2020 Covered Material: Sections 3.1-3.6 of the zyBook for the course. Problems (55 pts): 1. (35 pts) Use figures 1-3 in the attached illustrations as models to show the operations of selection, insertion and shell sorts on the input array {1, 6, 7,5, 0, 9, 8, 4, 3, 2}. For shell sort, use the gap values 7, 3, and 1, in that order. 2. (10 pts) Use figure 4 in the attached illustrations as a model to show the operations of the algorithm partition used by quicksort on (A, 0, 9), where A = {1, 6, 7,5, 0, 9, 8, 4, 3, 2}. 3. (10 pts) Use figure 5 in the attached illustrations as a model to show the operations of the algorithm merge, used by merge sort on (A, 0, 4, 9), where A = {1, 6, 7, 5, 0, 9, 8, 4, 3, 2}. For your convenience, the editable word doc file that was used to produce the attached illustrations is also posted under Homework Assignments. You may use it if you wish. Illustration of operations: Comparison Sorts Legend: Solid lines indicate elements compared. Double arrows indicate elements moved. - Fig 1: Operation of selection sort on 019 | 8 | 1| 2 | 3 | 7 | 6 | 45 0|1 | 2 | 3 | 4 | 5 | 7 | 6819 0|1| 8 | 9 | 2 | 3 | 7|6|4|5] 0|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 [0|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0|1|2|3 | 8 | 9|716|4|5] Fig 2: Operation of insertion sort on 0|9|8||1|2|3 | 7 | 6 || 4 | 5 0|1|2|3 | 8 | 9 | 7 | 6|4|5 0 | 1 | 2 | 3 | 7 | 8 | 9 | 6|4|5] 0 | 8 | 9 | 1 | 2 | 3 | 7|6|4|5 0 | 1|2|3 | 6 | 7 | 8 | 9|4|5] 0 1 2 3 4 6 | 7 | 8 | 9 5 0 | 1 | 2 | 8 | 9 | 3|7|6|4|5 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Fig3:Operation of Shell sort on with gap values 5, 3 and 1. Pass 1, gap = 5 | 0 | 3 | 6. 1L4 Array after pass 1: | [[[6]|2|| || 4 || Pass 2, gap = 3 | 0 | 1 | 7 | 5 N | Array after pass 2: [[[2|| 1 | | | | |[] Pass 3, gap = 1 3 [[2|| [6] [5] []]| |[0][2] [5] [6] [] ] [[[1] 2|| 5 | 5 | 61 | | 9] Array after pass 3: | Fig 4:Operation of partition on (A, 0, 9), where A = {0, 9, 8, 1, 3, 2, 3, 6, 4, 5} and pivot = A[4] = 3. The value h = 3 is returned. =2 h=4 |||||||| ||| || [2 ] [3 ] Fig 5: Operation of merge on (numbers, 0, 4, 9), where numbers = {0, 2, 4, 5, 7, 1, 3, 6, 8, 9} and array indices start with 0. Initial values: leftPos = 0, rightPos = 5, mergePos = 0 numbers: mergeNumbers: 10|2|4|5|7| 1 3 1 61819 0124517| 1 3 1 61819 After Iteration 1: leftPos = 1, rightPos = 5, mergePos = 1 numbers: mergeNumbers: 10|12|4|5|7|| 1 | 3 | 6 | 8 |9 012101517| 1 | 3 | 6 | 8 | 9 After Iteration 2: leftPos = 1, rightPos = 6, mergePos = 2 numbers: After Iteration 3: leftPos = 2, rightPos = 6, mergePos = 3 numbers: mergeNumbers: 101214 | 5 | 7| 1 | 3 | 6 | 8 |9 01112|5|7| 1 | 3 | 6 | 8 9 After Iteration 4: leftPos = 2, rightPos = 7, mergePos = 4 numbers: mergeNumbers: After Iteration 5: leftPos = 3, rightPos = 7, mergePos = 5 numbers: mergeNumbers: 02| 4 | 5 7 1368 0|1|2|34 13 689|| After Iteration 6: leftPos = 4, rightPos = 7, mergePos = 6 numbers: mergeNumbers: 10|2|4|5|7| 1 3 1 61819 011|2|3|4|5| 3 | 61 819 After Iteration 7: leftPos = 4, rightPos = 8, mergePos = 7 numbers: mergeNumbers: 101214 5 7 1 3 16 819 711|2|3|4|5|6|6|89| After Iteration 8: leftPos = 5, rightPos = 8, mergePos = 8. The main loop ends here. numbers: mergeNumbers: 012 4 571 3 6 8 9 0 1 2 3 4 5 6 7 8 9 After the rest of merge is executed: leftPos = 5, rightPos = 10, mergePos = 10 numbers: mergeNumbers: 101 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 011|2|3|4|516171819Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started