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

Linear Data Structures Using Sequential Organization, Study notes of Computer Science

Sequential Organization, Linear Data Structure Using Sequential Organization, Array as an Abstract Data Type, Memory Representation and Address Calculation, Inserting an element into an array, Deleting an element, Multidimensional Arrays, Two-dimensional arrays, n- dimensional arrays, Concept of Ordered List, Single Variable Polynomial, Representation using arrays, Polynomial as array of structure, Polynomial addition, Polynomial multiplication, Sparse Matrix, Sparse matrix representation.

Typology: Study notes

2019/2020

Available from 03/23/2023

raj-paliwal-1
raj-paliwal-1 🇮🇳

5 documents

1 / 48

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Unit II
Linear Data Structures Using
Sequential Organization
Sequential Organization, Linear Data Structure Using Sequential Organization, Array as
an Abstract Data Type, Memory Representation and Address Calculation, Inserting an
element into an array, Deleting an element, Multidimensional Arrays, Two-dimensional
arrays, n- dimensional arrays, Concept of Ordered List, Single Variable Polynomial,
Representation using arrays, Polynomial as array of structure, Polynomial addition,
Polynomial multiplication, Sparse Matrix, Sparse matrix representation, Sparse matrix
addition, Transpose of sparse matrix, String Manipulation Using Array.
(
Case Study- Use of sparse matrix in Social Networks and Maps
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30

Partial preview of the text

Download Linear Data Structures Using Sequential Organization and more Study notes Computer Science in PDF only on Docsity!

Unit II

Linear Data Structures Using

Sequential Organization

Sequential Organization, Linear Data Structure Using Sequential Organization, Array as an Abstract Data Type, Memory Representation and Address Calculation, Inserting an element into an array, Deleting an element, Multidimensional Arrays, Two-dimensional arrays, n- dimensional arrays, Concept of Ordered List, Single Variable Polynomial, Representation using arrays, Polynomial as array of structure, Polynomial addition, Polynomial multiplication, Sparse Matrix, Sparse matrix representation, Sparse matrix addition, Transpose of sparse matrix, String Manipulation Using Array. Case Study- Use of sparse matrix in Social Networks and Maps

Linear data structure

• The term “linear” means “belonging to a line”

• A Linear data structure consists of elements

which are ordered i.e. in a line.

• The elements form a sequence such that there is

a first element, second, …… and last element.

• Thus, the elements of a linear data structure

have a one-one relationship.

• Examples : array, list.

Sequential Organization

• Example : Arrays

• Array is an ordered set of objects.

• data structure that stores data of similar type at

consecutive memory locations.

• e.g. int A[5]; // A is an array of size 5

• It will allocate 5 consecutive memory

locations for the array A. Each element of

array can be accessed by referring to its index.

Arrays

• An array is a finite ordered set of homogenous elements.

  • (^) Finite : There are a specific number of elements in the array.
  • (^) Ordered : The elements are arranged so that there is a first

element, second, and so on.

  • (^) Homogenous : All the elements are of the same type.

• Mathematically, an array can be considered as a set of

pairs- (index, value). For each index, there is an

associated value. This means that, there is a one-to-one

mapping or correspondence between the set of indices

and the set of values.

Primitive Operations on Arrays

1. Create : Creating a new array : This needs the

information regarding the type of data objects and the

number of data objects to be stored.

2. Store(array, index, value) : Store a value at particular

position : This needs the name of the array, the position

in the array and the value to be stored at that position.

3. Retrieve ( array, index ) : Retrieve a value at a

particular position : This operation requires the array

name and an index and it returns the corresponding

value.

Array Implementation

  • (^) A single dimension array is created as :
    • (^) [size] ;
  • (^) Example
    • (^) int A[5];
  • (^) The array is implemented as a constant pointer to the array elements.
  • (^) The elements are stored in consecutive memory locations. The address of the first element is called the base address.

Address Calculation

  • (^) Address of A[i] = Base Address + i * element size
  • (^) E.g.
  • (^) Address of A[3] = 2000 + 3 * sizeof(int) = 2000 + 3 * 4 = 2012

Float a[5]

Useful Array Operations

  • (^) Finding the Highest Value int [] numbers = new int[50]; int highest = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] > highest) highest = numbers[i]; }
  • Finding the Lowest Value int lowest = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < lowest) lowest = numbers[i]; }

Useful Array Operations

• Summing Array Elements:

int total = 0; // Initialize accumulator
for (int i = 0; i < units.length; i++)
total += units[i];

• Averaging Array Elements:

double total = 0; // Initialize accumulator
double average; // Will hold the average
for (int i = 0; i < scores.length; i++)
total += scores[i];
average = total / scores.length;

Multidimensional Arrays

  • (^) An array can have more than two dimensions.

For example, a three dimensional array may be

declared as :

  • (^) int M[2][3][4];
  • (^) M is an array containing 2 two-dimensional arrays, each having 3 rows and 4 columns.

Representation of Multidimensional arrays

  • (^) A two-dimensional array is a logical data structure that is useful

in describing an object that is physically two-dimensional such

as a matrix or a check board. This is the logical view of data.

  • (^) However, computer memory is linear, i.e. it is essentially a one-

dimensional array. Thus, the elements of a two-dimensional

array have to be stored linearly in memory.

  • (^) They can be represented in two ways.
    • (^) Row-major representation : In this representation, the elements are arranged row-wise i.e. the 0th^ row elements are stored first, the next row elements after them and so on.
    • (^) Column-major representation : Elements are arranged columnwise i.e. all elements of the 0th column occupy the first set of memory locations, elements of the first column come next and so on.