Python Sorting Shell help🙏🙏🙏 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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, . . . ).

17th Dec 2022, 8:20 AM
Daniel Alexis
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.
17th Dec 2022, 7:10 PM
Sadaam Linux
Sadaam Linux - avatar
+ 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.
17th Dec 2022, 1:06 PM
Emerson Prado
Emerson Prado - avatar
0
thanks I will try.
17th Dec 2022, 8:18 PM
Daniel Alexis