Open top menu
Tuesday, October 7, 2014

ARRAY Traversing ALGORITHM:
  This can be accomplished by traversing A, that is, by accessing and processing each element of A exactly once.

1. [Initialize counter] Set k: =LB.

2. Repeat steps 3 and 4 while k <=UB.

3. [Visit Element] Apply PROCESS to LA [k].

4. [Increase Counter] Set k: =k + 1.

[End of step 2 loop]

5. Exit.

 ARRAY Insertion

Inserting an element at end of linear array can be done easily if the array is large enough to accommodate new item.
If the element is to be inserted in the middle of array then half members must be moved downward to new location to accommodate new element by keeping the order of other elements
 
ARRAY INSERTION ALGORITHM



Algorithm for Insertion: (Inserting into Linear Array) INSERT (LA, N, K, ITEM)

1. [Initialize counter] Set J: = N.

2. Repeat Steps 3 and 4 while j >= k;

3. [Move jth element downward.] Set LA [J + 1]: =LA [J].

4. [Decrease counter] Set J: = J-1

[End of step 2 loop]

5. [Insert element] Set LA [K]:=ITEM.

6. [Reset N] Set N:=N+1

7. EXIT.

 ALGORITHM FOR DELETION IN ARRAY
  Algorithm for Deletion: (Deletion from a Linear Array) DELETE (LA, N, K, ITEM)
Here LA is a Linear Array with N elements and K is the positive integer such that K<=N. This algorithm deletes the Kth element from LA.

1. Set ITEM: = LA [k].

2. Repeat for J = K to N – 1.

[Move J + 1st element upward] Set LA [J]: = LA [J +1].

[End of loop]

3. [Reset the number N of elements in LA] Set N: = N-1

4. EXIT






Tagged
Different Themes
Written by Kcnewbie

Ikatlah ilmu dengan menuliskanya.

0 comments