0% found this document useful (0 votes)
2K views

Algorithms For Array Traversal

The document describes algorithms for traversing, inserting, and deleting elements from a linear array. The traversing algorithm initializes a counter, prints each element by incrementing the counter until it exceeds the upper array bound. The insertion algorithm initializes a counter, shifts elements from the insertion point right by decreasing the counter, inserts the new item, and increments the number of elements. The deletion algorithm initializes a counter at the deletion point, shifts elements left by overwriting each element with the next and incrementing the counter, and decrements the number of elements.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Algorithms For Array Traversal

The document describes algorithms for traversing, inserting, and deleting elements from a linear array. The traversing algorithm initializes a counter, prints each element by incrementing the counter until it exceeds the upper array bound. The insertion algorithm initializes a counter, shifts elements from the insertion point right by decreasing the counter, inserts the new item, and increments the number of elements. The deletion algorithm initializes a counter at the deletion point, shifts elements left by overwriting each element with the next and incrementing the counter, and decrements the number of elements.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Algorithms for array traversal,insertion and deletion are shown below separately.

ALGORITHM : (Traversing of Linear Array) Here Arr is a linear array with lower bound L and upper bound
U

1.[Initialize Counter] Set K=L.


2.Repeat steps 3 and 4 while K<=U
3.Print Arr[K].
4.[Increase Counter] Set K=K+1.
5.Exit

ALGORITHM :(Inserting into a Linear Array) INSERT(Arr,N,K,ITEM)


Here Arr is a linear array with N elements ,K is positive integer such that K<=N and ITEM is the element
to be inserted.

1.[Initialize Counter] Set I=N.


2.Repeat steps 3 and 4 while I>=K.
3.Set Arr[I+1]=Arr[I].
4. [Decrease Counter] Set I=I-1.
5.[Inserting ITEM] Set Arr[K]=ITEM.
6.[Reset Number Of Elements].Set N=N+1.
7.Exit

ALGORITHM :(Deleting From Linear Array) DELETE(Arr,N,K)


Here Arr is a linear array with N elements ,K is positive integer such that K<=N and Kth element is to be
deleted.

1.[Initialize Counter] Set I=K.


2.Repeat steps 3 and 4 while I=N-1.
3.Arr[I]=Arr=[I+1].
4.[Increase Counter]Set I=I+1.
5.[Reset Number Of Elements].Set N=N-1.
6.Exit.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy