Embed presentation
Downloaded 16 times


![Insertion into an array Insert(A,N,K, item)
• A is array with N elements and K is a +ve integer such that
K<=N. This algorithm inserts an item into kth location in
array A
1 Set J=N
2 Repeat steps 3 and 4 while J>=K
3 Set A[J+1]= A[j]
4 Set J=J-1
5 Set A[k]= item
6 Set N=N+1
7 Exit](https://image.slidesharecdn.com/dsgr2-140910080854-phpapp02/85/Introduction-to-Algorithm-3-320.jpg)
![Deletion from array Delete(A, N, K, item)
1 Set item =A[K]
2 Repeat for j= K to N-1
Set A[j]= A[J+1]
3 Set N=N-1
4 Exit
Matrix Multiplication(A,B,C, M, N, P)
1 Repeat steps 2 to 4 for i = 1 to M
2 Repeat steps 3 to 4 for j= 1 to N
3 Set C[i][j]= 0
4 Repeat for k= 1 to P
Set C[i][j]= C[i][j]+ A[i][k] * B[k][j]
5 Exit](https://image.slidesharecdn.com/dsgr2-140910080854-phpapp02/85/Introduction-to-Algorithm-4-320.jpg)


The document introduces algorithms and provides examples of algorithms for insertion and deletion from an array, as well as matrix multiplication. It also provides the definition of a magic square and asks to write an algorithm to read integers for a square matrix and determine if it represents a magic square.


![Insertion into an array Insert(A,N,K, item)
• A is array with N elements and K is a +ve integer such that
K<=N. This algorithm inserts an item into kth location in
array A
1 Set J=N
2 Repeat steps 3 and 4 while J>=K
3 Set A[J+1]= A[j]
4 Set J=J-1
5 Set A[k]= item
6 Set N=N+1
7 Exit](https://image.slidesharecdn.com/dsgr2-140910080854-phpapp02/85/Introduction-to-Algorithm-3-320.jpg)
![Deletion from array Delete(A, N, K, item)
1 Set item =A[K]
2 Repeat for j= K to N-1
Set A[j]= A[J+1]
3 Set N=N-1
4 Exit
Matrix Multiplication(A,B,C, M, N, P)
1 Repeat steps 2 to 4 for i = 1 to M
2 Repeat steps 3 to 4 for j= 1 to N
3 Set C[i][j]= 0
4 Repeat for k= 1 to P
Set C[i][j]= C[i][j]+ A[i][k] * B[k][j]
5 Exit](https://image.slidesharecdn.com/dsgr2-140910080854-phpapp02/85/Introduction-to-Algorithm-4-320.jpg)
