0% found this document useful (0 votes)
3 views

5_Linear Data Structures - part 1

This document covers linear data structures, focusing on linear arrays and multidimensional arrays, including their memory allocation and operations such as traversal, insertion, and deletion. It provides algorithms for traversing, inserting, and deleting elements in linear arrays. The lecture is presented by Dr. R. Ramanathan from the Amrita School of Engineering.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

5_Linear Data Structures - part 1

This document covers linear data structures, focusing on linear arrays and multidimensional arrays, including their memory allocation and operations such as traversal, insertion, and deletion. It provides algorithms for traversing, inserting, and deleting elements in linear arrays. The lecture is presented by Dr. R. Ramanathan from the Amrita School of Engineering.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

19CCE202 Data Structures and Algorithms

LECTURE 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.

Linked lists - Linear relationship


between the elements represented
by means of pointers or links.
Linear arrays Multidimensional arrays

A linear array (1-D) is a list of finite A two dimensional mxn array is a


number of n homogeneous data elements collection of m.n data elements such that
referred respectively by an index set each element is specified by a pair of
consisting of n consecutive numbers and integers (j,k) called subscripts
stored respectively in successive
memory locations
Stored in m.n sequential memory
locations, either row major order or
The number n of elements is called the column major order.
length or size of array
Can extend to n- dimensional array
Memory allocation can be static or
dynamic depending on programming
language
Memory allocation in
multidimensional arrays - illustration

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

Algorithm 3: Deletion in a Linear Array (deletes an element from kth position in LA


and assigns it to a variable ITEM )
LA : Linear array with N elements; k is a positive integer such that k <= N
1. Set ITEM = LA[k]
2. Repeat for j = k to N - 1
3. [Move j+1th element upward] Set LA [j] = LA [j + 1]
[End of loop]
4. [Reset the number of elements in LA] Set N=N - 1
5. Exit

You might also like