0% found this document useful (0 votes)
1 views2 pages

Array Algorithms With Explanation

Uploaded by

sakshimohit2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Array Algorithms With Explanation

Uploaded by

sakshimohit2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Structures – Chapter 1: Arrays

(with Explanation)
1. Traversal of Array
Algorithm Step Explanation

Start → Begin the algorithm

Set i = 0 → i is the index pointer (starts from 0)

Repeat step 3.1 while i < n → Loop through array until end

3.1) Print arr[i] → Show current element

3.2) i = i + 1 → Move to next index

end loop → End of loop

Exit → End of algorithm

2. Insertion at Position i
Algorithm Step Explanation

Start → Begin the algorithm

If n ≥ max then → If array is full

Print 'Array Full' → Cannot insert

Exit → Exit program

end if

If i < 0 or i > n then → Check valid index

Print 'Invalid Index' → Cannot insert at wrong position

Exit → Exit program

end if

Set j = n - 1 → Start shifting from last element

Repeat step 5.1 while j ≥ i → Keep shifting until position i


5.1) arr[j+1] = arr[j] → Shift element right

5.2) j = j - 1 → Move one step back

end loop

arr[i] = item → Place the new item at index i

n=n+1 → Increase array size

Exit → End of algorithm

You might also like