2 Question 2 You are given an array A1n You are given that f
2. Question 2: You are given an array A[1..n]. You are given that for every A[i], A[i] is at most 20 places from its sorted position (for example, A[30] will be somewhere between A[10] and A[50] in the sorted array. A[5] will be somewhere between A[1] and A[25] in the sorted array.) Give an ecient algorithm to sort A.
Solution
Firt lets know about array in short.
Array will be same type it can hold the items which be fixed in number. Array asr mainly or mostly implemented in the data strucutres.
The two element of the ARRAY are as follows,
ELEMENT - THe each and every item stored in the array is called as Element.
INDEX - Index is mainly used to identify the element , were is the numerical address in the array. Were the items will be stored.
Mainly the * 0 will be starting address of the INDEX
* Array can store 8 elements were the length of the array is 8.
* Index is mainly used for fetching the data from the array.
Also, other operations that can be performed in the ARRAY are
Traverse , Insertion , Deletion, Search , Update.
If the array is the Linear Array(Unordered) , with K elements and N is the Positive integer , were N<=K .
Below is the algorithm where ITEM is insterted into the Nth position of the Linear Array.
1. Start
2. Set I=K
3. Set K=K+1
4. Repeat steps 5 and 6 while i >=N
5. Set LA[I+1] = LA [I]
6. Set I=I-1
7. Set LA [N] = ITEM
8. Stop.
![2. Question 2: You are given an array A[1..n]. You are given that for every A[i], A[i] is at most 20 places from its sorted position (for example, A[30] will be 2. Question 2: You are given an array A[1..n]. You are given that for every A[i], A[i] is at most 20 places from its sorted position (for example, A[30] will be](/WebImages/18/2-question-2-you-are-given-an-array-a1n-you-are-given-that-f-1036632-1761537954-0.webp)