Algorithm Of Traversal Of An Array

It is an operation in which element of the array is visited. The travel proceeds from first element to the last element of the array.

Example List[N] of N elements

Since the size of List is N , a count[ counter] will have to be maintained to keep track of the number of elements visited.

let C is a variable for count and initialize to 1 that is lower bound of LIST.

With every visit the count C is incremented and matched with upper bound N of LIST

if C is less than or equal N then the steps are repeated otherwise algorithm stops.

Algorithm step :
1. C=1
2. Process LIST[C]
3. C= C+1
4. if (C<=N) then repeat 2 and 3
5. End.

Example: An array MARKS[30] . Write an algorithm which adds value 10 to every element of array MARKS.
Steps:
1. C=1
2. Marks[C]=Marks[C]+10
3. C=C+1
4. If(C<=30) then repeat 2 and 3 steps.
5. end.

10- Array- Algorithm of Traversal of Array- DataStructure






    CLICK HERE TO Download This PDF NOTES




Facebook Likes

Youtube