Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Array Operations: Decl., Address Calc., Traversal, Insert., Deletion, and Search, Slides of Computer Science

An overview of arrays, their declaration, address calculation, and various operations such as traversal, insertion, deletion, and search algorithms. It covers both one-dimensional and two-dimensional arrays, as well as sparse matrices and their efficient handling.

Typology: Slides

2018/2019

Uploaded on 04/11/2019

pranav-bhardwaj
pranav-bhardwaj 🇮🇳

1 document

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ARRAYS
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Array Operations: Decl., Address Calc., Traversal, Insert., Deletion, and Search and more Slides Computer Science in PDF only on Docsity!

ARRAYS

  • An array is a collection of similar data elements.
  • The elements of the array are stored in consecutive memory locations

and are referenced by an index (also known as the subscript).

  • Declaring an array means specifying three things:
    • Data Type
    • Array Name
    • Array Size
  • Arrays are declared using the following syntax.

type name[size];

ARRAYS

ARRAYS Operations:

  • (^) Traversing of Array
  • (^) Insertion in Arrays
    • (^) Insert at end
    • (^) Insert at front
    • (^) Insert after a given position
    • (^) Insert after a given value
  • (^) Deletion in Arrays
    • (^) Delete from end
    • (^) Delete from front
    • (^) Delete at a given position
    • (^) Delete a given value
  • (^) Linear Search
  • (^) Binary Search

Binary Search BINARY_SEARCH (A, LB, UB, VAL) Step 1. Set BEG = LB, END = UB, POS = -1. Step 2. Repeat While BEG <= END do MID = INT (BEG+END)/ If A[MID] = = VAL then PRINT “Element found at MID position” POS = MID Go to Step 4. Else If A[MID] > VAL then END = MID - 1 Else BEG = MID + 1 End If Done Step 3. If POS = = -1 then PRINT “VAL not found” End If Step 4. Exit

Operations:

  • (^) Traversing
  • (^) Transpose
  • (^) Creation
  • (^) Addition of two matrices
  • (^) Subtraction of two matrices
  • (^) Multiplication of two matrices 2-Dimensional Arrays

TRANSPOSE (A, M, N, B) Step 1. Repeat For I = 0 to M- Step 2. Repeat For J = 0 to N- Step 3. Set B[J][I] = A[I][J] [End Loop] [End Loop] Step 4. End 2-Dimensional Arrays

SPARSE MATRIX

  • (^) Sparse matrix is a matrix that has many elements with a value zero.
  • (^) In order to efficiently utilize the memory, specialized algorithms and data structures that take advantage of the sparse structure of the matrix should be used. Otherwise, execution will slow down and the matrix will consume large amounts of memory.
  • (^) Types-
    • (^) Lower Triangular matrix
    • (^) Upper Triangular matrix
    • (^) Diagonal matrix

SPARSE MATRIX

  • (^) In the second variant of a sparse matrix, elements with a non-zero value can appear only on the diagonal or immediately above or below the diagonal. This type of matrix is also called a tridiagonal matrix.
  • (^) In a tridiagonal matrix, Ai,j = 0 where | i – j| > 1. Therefore, if elements are present on
  • (^) The main diagonal the, it contains non-zero elements for i=j. In all there will be n elements
  • (^) Diagonal below the main diagonal, it contains non zero elements for i=j+1. In all there will be n-1 elements
  • (^) Diagonal above the main diagonal, it contains non zero elements for i=j-1. In all there will be n-1 elements