5_Linear Data Structures - part 1
5_Linear Data Structures - part 1
Dr. R. Ramanathan
Associate Professor
Department of Electronics and Communication Engineering
Amrita School of Engineering, Coimbatore
[email protected]
Objective
To familiarize with linear data structures, understand the concept of linear arrays,
multidimensional arrays, memory allocation; to conceptualize and understand the operations
on linear array
Key concepts
• Linear data structure [CO01]
• Linear arrays [CO01]
• Multidimensional arrays [CO01]
• Memory allocation in arrays [CO01]
• Operations on linear arrays [CO01, CO02]
o Traversal
o Insertion
o Deletion
Linear data structure Operations
Traversal: Processing each element in the list
A data structure is said to be Search: Finding the location of the element with a
linear, if its elements form a
given value or key
sequence.
Sorting: Arranging the values in a specific order
Array - Linear relationship Insertion: Adding a new element to the list
between the elements represented Deletion: Removing a new element to the list
by means of sequential memory Merging: Combining two lists into a single list
locations.
3-D arrays
2-D arrays
Operations on Linear arrays - Traversal
Algorithm 1a: Traversing a Linear Array Algorithm 1b: Traversing a Linear Array
LA : Linear array with lower bound LB and LA : Linear array with lower bound LB and
upper bound UB upper bound UB
PROCESS: any process applied on the PROCESS: any process applied on the
array eg. Visit array eg. Visit
1. [Initialize counter] Set k = LB 1. Repeat for K = LB to UB
2. Repeat steps 3 and 4 while K <= UB 2. [Visit element] Apply PROCESS to
3. [Visit element] Apply PROCESS to LA[k]
LA[k] [End of step 2 loop]
4. [Increase counter]Set k = k + 1 3. Exit
[End of step 2 loop]
5. Exit
Operations on Linear arrays - Insertion
Algorithm 2: Inserting into a Linear Array (inserts an element ITEM at kth position in
LA )
LA : Linear array with N elements; k is a positive integer such that k <= N
1. [Initialize counter] Set j = N
2. Repeat steps 3 and 4 while j <= k
3. [Move jth element downward] Set LA [j + 1] = LA [j]
4. [Decrease counter] Set j = j - 1
[End of step 2 loop]
5. [Insert element] Set LA[k] = ITEM
6. [Reset N] Set N = N + 1
7. Exit
Operations on Linear arrays - Deletion