+ 1
Python Sorting Shell helpššš
Sorting Shell In the input.txt text file is an array of N integers. Sort the data in ascending order using Shell's sort for the following offset values: 1) shift values āāare hs, where hs + 1 = 2hs + 1, h0 = 1, with 0 6 s < ālog2 nā (sequence 1, 3, 7, 15, 31, 63, . . . ); 2) shift values āāare hs, where hs+1 = 3HS + 1, h0 = 1, with 0 6 s < ālog3 (2N + 1)ā ā 1 (sequence 1, 4, 13, 40, 121, . . . ).
3 Answers
+ 5
-First Define a function for Shell sort, and pass it the array and the shift values as arguments.
-Initialize a variable h to the first shift value in the sequence.
While h is greater than 0, do the following:
-Iterate over the array, starting at index h and ending at the last element. For each element, insert it into its correct position in the subarray formed by the elements preceding it, using insertion sort.
-Divide h by 2 (for the first sequence of shift values) or 3 (for the second sequence of shift values), and round down to the nearest integer.
-Return the sorted array.
+ 2
Daniel Alexis Pls edit your question description and add a link to your code in Code Playground and an explanation of your difficulties.
We have to see your attempt and understand where you got stuck to know what help you need.
0
thanks I will try.