- Introduction to Challenges
- Insertion Sort 1
- Insertion Sort Itself
- Correctness and the Loop Invariant
- Running Time
-
Counting Sort 1 - Simple Counting Sort
- Prepare for Full Counting Sort
- The Full Counting Sort
-
QuickSort1 - Simple Quick Sort
- Quick-Sort Advanced
- Quick Sort Running Time
Input Format for standard Sorting Challenges:
- t - the number of test cases
- s - the size of the array
- ar - the list of integers
Insertion Sort 1
Goal: Before sorting entire lists, sort one element in a list.
Given a sorted list of numbers with an unsorted number V in the right-most spot, can you write some simple code to insert V into the list so it remains sorted?
Print the list every time a value is shifted, until the list is fully sorted. The goal of this challenge is to follow the correct order of insertion sort.
How to Solve: Use the standard boilerplate to process the numbers into an array. You can then copy the right-most value (V) to a variable, and consider its cell “empty”. Since this leaves an extra cell empty on the right, you can shift every number over until V can be inserted. This will create a duplicate of each value, but when you reach the right spot, you can replace a value with V.
Output Format On each line, output the entire array every time an item is shifted in it. This will include duplicate values.
Challenge
Given a sorted list with an unsorted number V in the right-most cell, can you write some simple code to insert V into the array so it remains sorted?
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
David
Jun 18, 3:02 PMDear Admin,
As what i can see from the "Your Output" it is the same as "Correct Output", however the last array is not displayed so im not sure if im getting "Incorrect" due to the last array or something else.
Could the ''Your Output' output be increased to all results? I want to make sure i'm not getting "Incorrect" due to the last array.
Thanks
Learneroo
Jun 18, 3:09 PM@David, it displays all the output. Make sure you're printing the final steps too.
David
Jun 18, 4:12 PMThanks Admin, i noticed just now... double checking on my end needs to be improved.