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

Arrays

The document provides an overview of data structures, specifically focusing on linear structures such as arrays and linked lists. It explains the representation of linear arrays in memory, their operations, and introduces multidimensional arrays, including two-dimensional arrays and their memory representation. The document also references a source for further reading on data structures.

Uploaded by

bhavya agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Arrays

The document provides an overview of data structures, specifically focusing on linear structures such as arrays and linked lists. It explains the representation of linear arrays in memory, their operations, and introduces multidimensional arrays, including two-dimensional arrays and their memory representation. The document also references a source for further reading on data structures.

Uploaded by

bhavya agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Data Structures

Jasraj Meena
Assistant Professor
Department of Information Technology
Delhi Technological University

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 1


Arrays, Records and Pointers

• Data Structure are Classified as either linear or nonlinear.


A data structure is said to be linear if its elements form a sequence, or
in other words, a linear list.
There are two basic ways of representing such linear structures in
memory.

• One way is to have the linear relationship between the elements


represented by means of sequential memory locations. These
linear structures are called Arrays[1].

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 2


Arrays, Records and Pointers

• The other way is to have the linear relationship between the


elements represented by means of pointers or links.

• These linear structures are called linked lists.

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 3


Linear Array

• A linear array is a list of finite number n of homogeneous data elements (i. e.


data elements of the same type) such that:
• The elements of the array are referenced respectively by an index set
consisting of n consecutive numbers.
• The elements of the array are stored respectively in successive memory
locations [1].

• The number of n elements is called the length or size of the array.

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 4



Linear Array

❖ Representation of Linear Array in Memory:


❖ Let LA be a linear array in the memory of computer (A memory of a
computer is simply a sequence of addressed locations).

LA(LA[k])= address of the element LA[k] of the array LA.

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 5


Linear Array

❖ Operations on Linear Arrays:


❖ Traversing:
❖ Ex. Count number of elements on the array.
❖ Inserting and Deleting:
❖ Sorting:
❖ Searching:

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 6


Linear Array

❖ Multidimensional Arrays:
❖ The linear array discussed so far are also called one-dimensional
arrays, each elements in the array is referenced by a single
subscript [1].
❖ Most of the programming language allow two-dimensional and
three-dimensional arrays, i. e. arrays where elements are
referenced, respectively, by two and three subscripts.

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 7


Linear Array

❖ Two-dimensional Arrays:
❖ A two dimensional M×N array A is a collection of M.N data elements such
that each element is specified by pair of integers called subscript with a
property that: 1≤j≤N, 1≤k≤M [1].

❖ Denoted as A[j, k] or Aj,k

❖ Example: A[3,4]

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 8


Linear Array

❖ Two-dimensional Arrays: 2-D Array 2-D Array


❖ Example: A[3,3] Rep. Col. Rep. Row
Major Major
j/k 0 1 2
44 44
0 44 55 88 22 55
1 22 12 87 123 88
2 123 76 41 55 22
12 12
76 87
88 123
87 76
41 41
09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 9
Linear Array

❖ Two-dimensional Arrays: 2-D Array 2-D Array


❖ Example: A[3,3], now delete A[2,2] Rep. Col. Rep. Row
Major Major
j/k 0 1 2
44 44
0 44 55 88 22 55
1 22 12 87 123 88
2 123 76 41 55 22

76 87
88 123
87 76
41 41

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 10


Linear Array

❖ Representation of two-dimensional Arrays in memory [1]:


Column major order:
Row Major order:

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 11


Linear Array

❖ Representation of two-dimensional Arrays in memory [1]:


Direct formula to find the memory address of an element:

❖ Here, w is the number of words per memory cell for the LA .

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 12


Linear Array

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 13


Linear Array

❖ General Multidimensional Arrays [1]:


Ex.: B[2, 4, 3].

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 14


Linear Array [1]

Ex.: B[2, 4, 3].

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 15


Linear Array [1]

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 16


Linear Array [1]

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 17


Linear Array [1]

❖ Formula for finding the memory address of a General Multi-dimensional


Array:

OR

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 18


Linear Array [1]

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 19


Linear Array [1]

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 20


Linear Array [1]

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 21


References
1. Seymour Lipschutz, “Data Structures”, Schaum’s Series McGraw
Hill edition 2013.

09-08-2021 Data Structure, Jasraj Meena, Dept. of IT, DTU 22

You might also like