Professional Documents
Culture Documents
02 DS and Algorithm Session 02
02 DS and Algorithm Session 02
Exercise 1
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1. Accept two arrays, A1 and A2, each of size 10, from the
user.
2. Declare an array, result, of size 20.
3. Set i = j = k = 0.
4. If (A1 [i] <= A2 [j]): // Insert the smaller element in the
// result array
a. result [k] = A1 [i]
b. Set k = k + 1
c. Set i = i + 1
5. If (A1[i] > A2[j]): // Insert the smaller element in the
// result array
a. result [k] = A2 [j]
b. Set k = k + 1
c. Set j = j + 1
7. Set i = i – 1.
8. Go to step 6.