You are on page 1of 17

UNIVERSITY INSTITUTE OF COMPUTING

Bachelor of Computer Application


Subject Name: Data Structure
Code:CAT-201

Array DISCOVER . LEARN . EMPOWER


Font size 24
• Array representation
• Insertion into array

Array • Deletion into array


• Searching
Course Outcome
CO Title Level
Number

CO1 Explain the algorithm and it’s terms related to Understand


array
CO2 Explain the basic concepts of searching Understand

CO3 Explain the different types of Linear Data Understand


structure
CO4 Explain the stack data structure Understand

CO5 Analyse the algorithms Understand


Arrays
A linear array is a list of finite number n of homogeneous data elements such that :
a) Array elements are referenced respectively by an index set consisting of n consecutive numbers.
b)Array elements are stored respectively in successive memory locations.
• The number n of elements is called the length or size of the array.
• Three elements define an array : lower bound, upper bound, size.
• The lower bound define the smallest subscript.
• The upper bound is the largest subscript .
• The size / length of the array refers to the number of elements in the array ,we can calculate as
upper bound - lower bound + 1
Arrays

Example :
• A linear array named as DATA consisting of six elements:

Fig 1 array representation

Reference: Chapter 3 Seymour Lipschutz, Schaum's Outlines Series Data structures TMH
Arrays

Example :
• An automobile company uses an array AUTO to record the number of auto mobile sold each year
from 1932 through 1984.
• AUTO[k] = Number of auto mobiles sold in the year K
• Lower Bound = 1932
• Upper Bound = 1984
• Length = UB – LB+1 = 1984 – 1930+1 =55
Representation of linear array in memory

Reference: http://www.xpode.com/ShowArticle.aspx?
ArticleId=137http://www.xpode.com/ShowArticle.aspx?ArticleId=137
Arrays Traversing

Traversing is a process to print the each element of an array . This can be accomplished by
traversing an array, That is, by accessing and processing (visiting) each element of an array
exactly once.
Algorithm 2.3: Given DATA is a linear array with lower bound LB and upper bound UB . This
algorithm traverses DATA applying an operation PROCESS to each element of DATA.
• Set K:=LB.
• Repeat step 3 and 4 while k<=UB;
• Apply PROCESS to DATA[K]
• Set :=K+1
• Exit
Array Insertion

INSERTING AN ELEMENT INTO AN ARRAY:


Insert (LA, N, K, ITEM)
Here LA is linear array with N elements and K is a positive integer such that K<=N. This algorithm inserts an element
ITEM into the Kth position in LA.
ALGORITHM
Step 1.          [Initialize counter] Set J:=N
Step 2.          Repeat Steps 3 and 4] while J>=K
Step 3.          [Move Jth element downward] Set LA [J+1]: =LA [J]
Step 4.          [Decrease counter] Set J:=J-1
[End of step 2 loop]
Step 5           [Insert element] Set LA [K]: =ITEM
Step 6.          [Reset N] Set N:=N+1
Step 7.          Exit
Arrays Deletion

DELETING AN ELEMENT FROM A LINEAR ARRAY


Delete (LA, N, K, ITEM)
ALGORITHM
Step 1.          Set ITEM: = LA [K]
Step 2.          Repeat for J=K to N-1
[Move J+1st element upward] Set LA [J]: =LA [J+1]
[End of loop]
Step 3           [Reset the number N of elements in LA] Set N:=N-1
Step 4.          Exit
Linear Search

Example : Linear Search :


• Algorithm 2.4 : A linear array DATA with N elements and a specific ITEM of information are given. This
algorithm finds the location LOC of ITEM in the array DATA or sets LOC = 0.
Set K : = 1, LOC : =0.
Repeat steps 3 and 4 while LOC = 0 and K<=N:
If ITEM = DATA[K], then : Set LOC : =K .
Set K : = K+1.
[End of step 2 loop]
[Successful?]
If LOC = 0, then :
Write : ITEM is not in the array DATA.
Else :
Write : LOC is the location of ITEM.
[End of if structure]
Exit.
Binary Search
• Binary search works on sorted array
elements.
• if array elements are not in sorted the first
we need to sort the list.
• After sorting we find our the mid point by
adding first anf last index of array and
divide by 2.
• then compare the element that you want to
search with mid point element .
• if item is greater than mid element then
iore left side of mid element and vice
versa. References:
https://www.hackerearth.com/practice/algorithms/s
earching/binary-search/tutorial/
Self Referential Structures
• Self Referential structures are those structures
that have one or more pointers which point to
the same type of structure, as their member.

Reference: https://www.geeksforgeeks.org/self-
referential-structures/
Polynomial
• A polynomial p(x) is the expression in variable x which is in the form (axn + bxn-1 + …. + jx+ k),
where a, b, c …., k are real numbers and 'n' is non negative integer, which is called the degree of
polynomial.
• An essential characteristic of the polynomial is that each term in the polynomial expression
consists of two parts:

• coefficient
• exponent
Polynomial

Example:
• 10x2 + 26x, here 10 and 26 are coefficients
and 2, 1 is its exponential value.
• The sign of each coefficient and exponent is
stored within the coefficient and the exponent
itself

Reference: https://www.w3schools.in/data-
structures-tutorial/polynomials-using-linked-list-and-
arrays/
ARRAY APPLICATIONS
• Arrays are used to implement mathematical vectors and matrices
• it is used in rectangular tables,databases consist of one-dimensional arrays .
• Arrays are used to implement other data structures, like lists, heaps, hash tables, deques, queues
and stacks.
REFERENCES
Reference Books:
• Seymour Lipschutz, Schaum's Outlines Series Data structures TMH
• Introduction to Data Structures Applications, Trembley&Soreson, Second Edition, Pearson Education

Reference websites:
• https://www.tutorialspoint.com/data_structures_algorithms/array_data_structure.htm
• https://www.tutorialspoint.com/data_structures_algorithms/array_data_structure.htm
THANK YOU

For queries
Email: gurpreetkaur.uic@cumail.in

You might also like