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

DS - Unit 1

Uploaded by

goraljid90
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

DS - Unit 1

Uploaded by

goraljid90
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

BCA SEM III

US03MABCA01 Fundamentals of Data Structures

UNIT – I: INTRODUCTION TO DATA


STRUCTURE

Unit-I: Topics
 Introduction to data structures - Definition, Types of Data Structure
Primitive and non-primitive data structures and operations on them
 Applications and advantages of Data structure
 Introduction to arrays
 Terminology: Size, Type, Base, Index, Range of Indices
 One dimensional arrays – declaration, initialization and accessing one dimensional array
elements
 Memory allocation and address calculation of one dimensional array
 Two dimensional arrays – declaration, initialization and accessing two dimensional array
elements
 Representation of arrays in memory : row-major and column-major Order, Address
calculation of elements of two-dimensional arrays
 Applications of Array
References:
1) D. Samanta - Classis Data Structures, 2nd Edition – PHI Publication
2) G. S. Baluja - Data Structures through C, 4th Edition – Dhanpat Rai & Co.

INTRODUCTION

There are a number of ways to write programs: they must run correctly and efficiently; be easy to
read and understand; be easy to debug and; be easy to modify.

Data is the basic fact or entity that is utilized in calculation or manipulation. There are two different
types of data such as numerical data and alphanumeric data. These two data type specify the nature of
data item that go through certain operations. Integers and floating point numbers are of numerical data type.
Data may be a single value or it may be a set of values. Whether it is a single value or a group of values to
be processed must be organized in a particular fashion. This organization leads to structuring of data.

The intimate relationship between data and programs can be traced to the beginning of computing. In
any area of application, the input data, (internally stored data) and output data may each have a unique
structure.

Definitions
Data structure is representation of the logical relationship existing between individual elements of
data.
OR
In other words, a data structure is a way of organizing all data items that considers not only the
elements stored but also their relationship to each other.
OR
We can also define it as a mathematical or logical model of particular organization of dataitems.
Data structure mainly specifies the following four things:
1. Organization of data.
2. Accessing methods.
3. Degree of associativity.
4. Processing alternatives for information.

Data structures are the building blocks of a program. And hence the selection of a particular data structure
Page 1 of 16
stresses on the following two things.
1. The data structures must be rich enough in structure to reflect the relationship existing between
the data.
2. And the structure should be simple so that we can process data effectively whenever required.
The identification of the inherent data structure is vital in nature. And the structure of input and output data
can be use to derive the structure of a program. Data structure affects the design of both structural and
functional aspects of a program.
Algorithm + Data structure = Program
An algorithm is a step-by-step procedure to solve a particular function. That is, it is a set of instructions
written to carry out certain tasks and the data structure is the way of organizing the data with their logical
relationship retained.
To develop a program of an algorithm, we should select an appropriate data structure for that algorithm.
Therefore, algorithm and its associated data structures form (creates) a program.

CLASSIFICATION OF DATA STRUCTURE (FAMILY OF D. S.)

Data structures are normally divided into two broad categories:


1. Primitive data structures.
2. Non-primitive data structures.

Classification of Data Structures

Primitive Data Structure:


The data structures that are directly operated by machine instruction are called primitive data
structure.
i.e. Integer, floating-point numbers, character constants, string constants, pointers etc.

Non – Primitive Data Structure:


The data structures that are not directly operated by machine instruction is called Non- Primitive
Data Structure.
These data structures are derived from the primitive data structures. The non-primitive data structures
emphasize on structuring of a group of homogeneous (same type) or heterogeneous (different type) data
items.
i.e. Arrays, Lists and Files.

Linear data structures


 A data structure is said to be Linear, if its elements are connected in linear fashion bymeans of
logically or in sequence memory locations.

Page 2 of 16
 There are two ways to represent a linear data structure in memory,
o Static memory allocation
o Dynamic memory allocation
 The possible operations on the linear data structure are: Traversal, Insertion, Deletion,
Searching, Sorting and Merging.
 Examples of Linear Data Structure are Stack and Queue.
 Stack: Stack is a data structure in which insertion and deletion operations are performed at one end
only.
o The insertion operation is referred to as ‘PUSH’ and deletion operation is referred to as ‘POP’
operation.
o Stack is also called as Last in First out (LIFO) data structure.
 Queue: The data structure which permits the insertion at one end and Deletion at another
end, known as Queue.
o End at which deletion is occurs is known as FRONT end and another end at whichinsertion
occurs is known as REAR end.
o Queue is also called as First in First out (FIFO) data structure.

Nonlinear data structures


 Nonlinear data structures are those data structure in which data items are not arranged in asequence.
 Examples of Non-linear Data Structure are Tree and Graph.
 Tree: A tree can be defined as finite set of data items (nodes) in which data items arearranged
in branches and sub branches according to requirement.
o Trees represent the hierarchical relationship between various elements.
o Tree consist of nodes connected by edge, the node represented by circle and edge lives
connecting to circle.
 Graph: Graph is a collection of nodes (Information) and connecting edges (Logical relation)between
nodes.
o A tree can be viewed as restricted graph.
o Graphs have many types:
 Un-directed Graph
 Directed Graph
 Mixed Graph
 Multi Graph
 Simple Graph
 Null Graph
 Weighted Graph

Difference between Linear and Non Linear Data Structure

Linear Data Structure Non-Linear Data Structure


Every item is related to its previous and next Every item is attached with many other
time. items.
Data is arranged in linear sequence. Data is not arranged in sequence.
Data items can be traversed in a single run. Data cannot be traversed in a single run.
Eg. Array, Stacks, linked list, queue. Eg. tree, graph.
Implementation is easy. Implementation is difficult.

Page 3 of 16
Difference between Primitive and Non-Primitive Data Structure

Primitive Data Structure Non-Primitive Data Structure


A primitive data type is one that fits the base A non-primitive data type is something else
architecture of the underlying computer such as an array structure or class is known as
the non-primitive data type.

Primitive data are only single values, they have not The non-primitive data types are used to
special capabilities. store the group of values.
The examples of Primitive data types are givenbyte, Examples of non-primitive data type are
short, int, long, float, double, char etc. Array, structure, union, link list, stacks,
queue etc.

The most commonly used operations on Data Structure are:


1. CREATE
2. DESTROY or DELETE
3. SELECTION
4. UPDATION

1. CREATE: This operation results in reserving memory for the program elements (variables). This can
be done by declaration statement. The creation of data structure may take place either during compile-
time or during run-time.
2. DESTROY: This operation destroys the memory space allocated for the specified data structure.
malloc( ) and free( ) function of C language are used for these two operations respectively (as far as
dynamic memory allocation and de-allocation is concerned).
3. SELECTION: This operation deals with accessing a particular data within a data structure.
4. UPDATE: This operation updates or modifies the data in the data structure. Probably new data
may be entered or previously data may be deleted.

Other operations performed on data structures include:

5. SEARCHING: This operation finds the presence of the desired data item in the list of dataitem. It
may also find the locations of all elements that satisfy certain conditions.
6. SORTING: This is the process of arranging all data items in a data structure in a particular order
say for example, either in ascending order or in descending order.
7. MERGING: This is a process of combining the data items of two different sorted lists into asingle
sorted list.

APPLICATIONS OF DATA STRUCTURE


 Applications of an Array: Implementation of other data structures, Execution of matrices and
vectors, Dynamic memory allocation, Pointer container, Control tables
 Applications of Stack: Evaluation of expressions, Backtracking, Runtime memory
management, Arrangement of books in a library
 Applications of Queue: Disk scheduling, CPU scheduling, File IO, Data transmission
 Applications of linked list: web crawling, Representation of sparse matrices, Non-
contiguous data storage, Implementation of non-binary tree or other data structures,
Dynamic memory management, Equalizing parenthesis, Symbol tables
 Applications of Graph: Computer networking, Problem solutions involving 'Depth-First' search or
'Breadth-First' search algorithms, Representation of matrices, Study of molecular interactions in
Chemistry

Page 4 of 16
 Applications of Tree: Representation of data lists, Quickly accessible data storage,
Representation of hierarchal data, Routing of algorithms
 Applications of Files: Implementation of computer programs, Data comparison, Storage of data
having varying data types

ADVANTAGES OF DATA STRUCTURE


1) Allows easier processing of data.
2) It allows information stored on disk very efficiently.
3) These are necessary for designing an efficient algorithm.
4) It provides management of databases like indexing with the help of hash tables and arrays.
5) We can access data anytime and anywhere.
6) It is secure way of storage of data.
7) Graphs models real life problems
8) It allows processing of data on software system

DISADVANTAGES OF DATA STRUCTURE


1) It is applicable only for advanced users.
2) If any issue occurs, it can be solved only by experts.
3) Slow access in case of some data types

INTRODUCTION TO ARRAYS

If we want to store a group of data together in one place, then array is suitable data structure. This
data structure enables us to arrange more than one element that’s why it is known as composite data
structure.

In this data structure, all the elements are stored in contiguous location of memory. Figure shows an
array of data stored in a memory block starting at location 101.
101
102
103
104
105
106
107

Definition:
An array is a finite, ordered and collection of homogeneous data elements.

 Array is a finite because it contains only limited number of elements.

 Array is ordered because all the elements are stored one by one in contiguous location of
computer memory in a linear ordered fashion.

 Array is collection of homogeneous (identical) elements because all the elements of anarray are of
the same data type only.

Page 5 of 16
An array is known as linear data structure because all elements of the array are stored in a linear
order.

e.g. 1. an array of integer to store the age of all student in a class


2. an array of string of characters to store name of all villagers in village

Terminology:

1. Size: Number of elements in an array is called the size of the array. It is also known as
dimension or length.

2. Type: Type of an array represents the kind of data type for which it is meant
(designed). E.g. array of integer, array of character.

3. Base: Base of an array is the address of memory location where the first element in the array is
located.
E.g. 101 is the base address of the array mentioned in Figure.

4. Index: All the elements in an array can be referred by a subscript like Ai or A[i], this
subscript is known as index. An index is always an integer value.

5. Range of indices: Indices of an array element may change from lower bound (L) to an upper
bound (U). These bounds are called the boundaries of an array.

If the rage of index varies from L...U then size of the array can be calculated as:
Size (A) = U – L + 1

ONE DIMENSIONAL ARRAYS

A one dimensional array is one in which only one subscript specification is needed to specify a
particular element of the array.

Declaration of One dimensional array

One dimensional array can be declared as follows:

data_type var_name [expression];

 data_type is the type of elements to be stored in the array.


 var_name specifies the name of array. It may be given any name like other simple
variables.
 expression or subscript specifies the number of values to be stored in the array.

e.g. int n[5]; This array will store seven integer values, which is specified by n. It can be visualized as
below.

Index Data
n[0] 5
n[1] 48
N[2] 0
n[3] 80
n[4] 21

Page 6 of 16
Initializing one dimensional array

Array variables can be initialized in declarations by constant initializers.

These initializing expressions must be constant values. Expression with identifiers or function calls may
not be used in the identifiers. The initializers are specified within braces and separated by commas.

e.g. int n[10] = {2, 53, 19, 41, 46, 22};


char s[10] = {‘a’, ‘d’, ‘f’, ‘s’, ‘\0’};

String initializers may be written as string constants instead of character constants withinbraces.

e.g. char str[ ] = “This is a message”; char s[20] = “Hello World”;


In the case of str[ ], enough memory is allocated to accommodate the string plus a terminating
NULL character and we do not need to specify the size of the array.

Accessing one dimensional array elements

Individual elements of the array can be accessed using the following syntax:
array_name [ index or subscript ];

Example:

1. To access third element from array we write: n[2]

The subscript for third element is 2 because the lower bound of array in C is 0.

2. To assign a value to second location of the array, we write: n[1] = 20;

3. To read a particular value we write: scanf (“%d”, &n[2] ) ;

This statement reads a value from the keyboard and assigns it to third location of the array.

MEMORY ALLOCATION AND ADDRESS CALCULATION OF ELEMENTS OF


ONEDIMENSIONAL ARRAYS

Suppose an array A[100] is to be stored in a memory as in Figure. Let the memory location where the
first element can be stored is M.
1 M
2
3
4
5
.
.
i
.
100

An array can be written as A[L..U] where L denotes lower bound and U denotes the upper bound for
index.

Page 7 of 16
TO FIND ADDRESS OF AN ELEMENT IN ONE DIMENSIONAL ARRAY WITH LOWER
BOUND = 1

 If an element in one dimensional array occupy 1 word (byte):

If each element requires one word (byte) then the location for any element say A[ i ] in the array can be
obtained as:

Address ( A[ i ] ) = M + ( i – 1 ) [Note: Lower bound of array is assumed to be 1.]

M Base address of array


I Subscript of an element whose address is required to be calculated

 If an element in one dimensional array occupy w word (byte):

Address ( A[ i ] ) = M + ( i – 1 ) * w [Note: Lower bound of array is assumed to be 1]

M Base address of array


I Subscript of an element whose address is required to be calculated
C Size of an element

TO FIND ADDRESS OF AN ELEMENT IN ONE DIMENSIONAL ARRAY FOR ANY VALUE OF


LOWER BOUND

If array is stored starting from memory location M and for each element it requires w numberof words
then the address for A[ i ] will be

Address ( A[ i ]) = M + ( i – L ) * w
Here Lower bound of array can be any arbitrary value denoted by L.

M Base address of array


I Subscript of an element whose address is required to be calculated
L Lower bound of array
W Size of an element

Above formula is known as indexing formula, which is used to map the logical
presentation of an array to physical presentation.

By knowing the starting address of array M, the location of the ith element can be
calculated instead of moving towards i from M.

Page 8 of 16
Example
Suppose that each element requires 2 word (byte), the base address of the array a[10] is 100and the lower
bound of the array is 1. Find out the address of following elements:
1. Find address of a[4].
2. Find address of a[7].
Answer
We are given that: Base address of the array is 100. So M=100
Lower bound of the array is 1. So L=1.
Each element requires 2 word (byte). So w=2.

Formula: Address (A[ i ] ) = M + ( i – L ) * w

1. To find address of a[4]


Address (a[4] ) = 100 + (4 – 1) * 2
= 106
2. To find address of a[7]
Address (a[7] ) = 100 + (7 – 1) * 2
= 112

MULTIDIMENSIONAL / TWO DIMENSIONAL ARRAY

Definition:

A Two-Dimensional array (commonly called a matrix) consists of elements of the same type arranged in
rows and columns. The rows and columns of a matrix are numbered starting from 0. Thus, for an array of
size rows x cols, the row subscripts are in the range 0 to rows - 1 and the column subscripts are in the range
0 to cols - 1.

An m X n matrix where m denotes the number of rows and n denotes number of


columns is as follows:

mxn

The subscripts of any arbitrary element say Aij represent ith row and jth column. Declaration

of two dimensional array

The declaration of a two-dimensional array takes the following form:


data_type var_name [ row_exp ] [ col_exp ] ;
where var_name is the name of the array being declared, each element of which is of type
data_type. The expressions rows and cols enclosed in square brackets are constant integral expressions (or
integral constants) that specify the number of rows and columns in the array. When a compiler comes
across the declaration of an array, it reserves memory for the specified

Page 9 of 16
number of array elements. For a two-dimensional array, the memory required is given as rows* cols*
sizeof(arr_type).

Initializing two dimensional array

A matrix can be initialized using a syntax similar to that used for the initialization of vectors. Thus, the
declaration
int mat [3] [4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

C language allows the initialization list for each row to be enclosed within a pair of braces. Thus, the
declaration of array mat given above can alternatively be written as follows:
int mat[3] [4] = {{l, 2, 3, 4), {5, 6, 7, 8), {9, 10, 11, 12}};

Accessing two dimensional array elements

An element of a matrix can be accessed by writing the array name followed by row and column subscript
expressions within separate array subscript operators as shown below.
var_ name [ row_expr ] [ col_expr ]
where row_ expr and col_ expr are integral expressions that specify the row and column positions,
respectively, of an element in the array. As mentioned earlier, for an element access to be valid, the values
of row_ expr should be in the range 0 to rows - 1 and the values of col_ expr should be in the range 0
to cols – 1.

Example:

1. a[0][0]=10; //Assigns 10 to element at first row and first column


2. a[0][1]=3; //Assign 3 element at first row and second column

MEMORY REPRESENTATION OF A MATRIX

Like one dimensional array, matrices are also stored in continuous memory location. There are two
conventions of storing any matrix in memory:

1. Row major order


2. Column major order

In row major order, elements of matrix are stored on a row by row basis. i.e. all the elements of
the first row, then all the elements of second row and so on.

In column major order, elements of matrix are stored column by column. i.e. all the elements of the
first column are stored in their order of rows, then in second column and so on.

E.g Consider the representation of a Matrix of 3 x 4

Page 10 of 16
Reference of elements in a matrix

Logically a matrix appears as two dimensional but physically it is stored in a linear fashion. So in
order to map from logical view to physical structure, we need indexing formula. Obviously, the
indexing formula for different order will be different.

ROW MAJOR ORDER – ADDRESS CALCULATION


Assume that the base address is 1 (the first location of the memory). So the address of Aij will be obtained
as -

Storing all the elements in first ( i -1 )th rows + Number of elements in the ith row upto the jth column” i.e.
Address ( Aij ) = ( i – 1 ) * n + j

So for the matrix A3X4, the location of A32 will be calculated as 10.

TO FIND ADDRESS OF AN ELEMENT IN TWO DIMENSIONAL ARRAY WITH LOWER


BOUND = 1 and UPPER BOUND = 1

Note: This formula assumes that lower bound for i (row) and j (column) will be 1.

Address ( Aij ) = M + ( ( i – 1 ) * n + j – 1 ) * w where n is total number of columns

M Base address of array


I Row subscript of an element whose address is required to be calculated.
N Number of columns
J Column subscript of an element whose address is required to be calculated.
W Size of an element

TO FIND ADDRESS OF AN ELEMENT IN TWO DIMENSIONAL ARRAY FOR ANY VALUEOF


LOWER BOUND and UPPER BOUND)

Address ( Aij ) = M + ( ( i – L1 ) * n + j – L2 ) * w where n is no. of columns

M Base address of array


I Row subscript of an element whose address is required to be calculated.
L1 Lower bound of i (row)
N Number of columns
J Column subscript of an element whose address is required to be calculated.
Page 11 of 16
L2 Lower bound of j (column).
W Size of an element

COLUMN MAJOR ORDER – ADDRESS CALCULATION

Assume that the base address is 1 (the first location of the memory). So the address of Aij will beobtained as-

Storing all the elements in first ( j - 1)th columns + Number of elements in the jth columnupto the
ith row i.e. Address ( Aij ) = ( j – 1 ) * m + i

So for the matrix A3X4, the location of A32 will be calculated as 6.

TO FIND ADDRESS OF AN ELEMENT IN TWO DIMENSIONAL ARRAY WITH LOWER


BOUND = 1 and UPPER BOUND = 1

Note: This formula assumes that lower bound for i (row) and j (column) will be 1.

Address ( Aij ) = M + ( ( j – 1 ) * m + i – 1 ) * w where m is total number of rows

M Base address of array


J Column subscript of an element whose address is required to be calculated.
M Number of rows
I Row subscript of an element whose address is required to be calculated.
W Size of an element

TO FIND ADDRESS OF AN ELEMENT IN TWO DIMENSIONAL ARRAY FOR ANY VALUE


OF LOWER BOUND and UPPER BOUND

Address ( Aij ) = M + ( ( j – L2 ) * m + i – L1 ) * w where m is no. of rows

M Base address of array


J Column subscript of an element whose address is required to be calculated.
L2 Lower bound of j (column).
M Number of rows
I Row subscript of an element whose address is required to be calculated.
L1 Lower bound of i (row)
W Size of an element

Example:

Assume that the base address of the two dimensional array A[3][3] is 100, each element requires 2 byte
(word). Find the address of the element A[3][2] using
1. Row major order
2. Column major order

Solution
We are given that: Base address of the array is 100. So M=100
Each element requires 2 word (byte). So w=2.
Number of rows are 3. So m=3.

Page 12 of 16
Number of columns are 3. So n=3.
Lower bound of i (row) L1 = 1
Lower bound of j (column) L2 = 1

1. Row major

To find address of the A[3][2] element of the array. So i = 3 and j = 2 Address

(A[3][2] ) = M + ( ( i – L1 ) * n + j – L2 ) * w
= 100 + ( ( 3 – 1 ) * 3 + 2 – 1 ) * 2
= 114

2. Column major

To find address of the A[3][2] element of the array. So i = 3 and j = 2 Address (


A[3][2] ) = M + ( ( j – L2 ) * m + i – L1 ) * w
= 100 + ( ( 2 – 1 ) * 3 + 3 – 1 ) * 2
= 110

APPLICATION OF ARRAYS

1. Arrays are used to implement mathematical vectors and matrices, as well as other kinds of
rectangular tables. Many databases, small and large, consist of (or include) one- dimensional arrays
whose elements are records.
2. Arrays are used to implement other data structures, such as heaps, hash tables, deques, queues,
stacks, strings, and VLists.
3. There are wide applications of arrays in computation. That is why almost every programming
language includes this data type as a built in data type.
4. Suppose you want to store records of all students in a class. The record structure is givenby

STUDENT
Roll No. Mark1 Mark2 Mark3 Total Grade
Alpha Numeric Numeric Numeric Numeric Numeric Character

If sequential storage of record is not objection, then we can store the records by maintaining 6 array
whose size is specified by the total number of students in the class as in Figure.
5. Arrays can be used to represent polynomials so that mathematical operations can be
performed in an efficient manner.

Page 13 of 16
QUESTION BANK

MULTIPLE CHOICE QUESTIONS

1. is the basic fact or entity that is utilized in calculation.


a. Data c. Information
b. Fact d. All of these
2. are the building blocks of program.
a. Information c. Data
b. Data Structure d. Data Types
3. The data structure directly operated by machine instruction are called data structure.
a. Structured c. Non-Primitive
b. Primitive d. None
4. The data structure that are not directly operated by machine instruction are called
data structure.
a. Structured c. Non-Primitive
b. Primitive d. None
5. Index of an array is always an value.
a. String c. Integer
b. Float d. Stack
6. array is also known as matrix.
a. One Dimensional c. Both
b. Two Dimensional d. None of these
7. operation finds the presence of data items in the list of data items
a. Sorting c. Merging
b. Updating d. Searching
8. An array is a data structure.
a. Composite c. Non-composite
b. Unordered d. Heterogeneous
9. An array is a data structure.
a. Unordered c. Non-composite
b. Linear d. Heterogeneous
10. An array is a data structure.
a. Heterogeneous c. Unordered
b. Non- Linear d. Homogeneous
11. An array is called finite data structure because .
a. It contains infinite number of elements.
b. It contains unlimited elements.
c. It contains limited number of elements.
d. It does not contain limited number of elements.
12. An array is called homogeneous data structure because .
a. All the elements of an array have same data type.
b. All the elements of an array do not have same data type.
c. It contains infinite number of elements.
d. It contains unlimited elements.
13. All elements of array are stored in fashion.
a. Non-linear ordered c. Linear unordered.
b. Non-linear unordered d. Linear ordered
14. The number of elements in an array is called the of the array.
a. Size c. Base
b. Type d. Index
15. of the array represents the kind of data type.
a. Size c. Base
b. Type d. Index
16. of an array is the address of memory location where the first element of thearray is
located.
Page 14 of 16
a. Size c. Base
b. Type d. Index
17. is a value or variable or expression which is used to refer the element of anarray.
a. Size c. Base
b. Type d. Index
18. Index is also known as .
a. Subscript c. Non-subscript
b. Base d. Type
19. If the range of index varies from L.............. U then size of the array is .
a. U – L + 1 c. L – U + 1
b. U / L – 1 d. L / U – 1
20. In row major order, elements of matrix are stored on a basis.
a. Row by Column c. Column by Column
b. Column by Row d. Row by Row
21. In column major order, elements of matrix are stored on a basis.
a. Row by Column c. Column by Column
b. Column by Row d. Row by Row

SHORT QUESTIONS
1) Define Data Structure.
2) What is Primitive Data structure and list out commonly used Primitive data structure.
3) What is Linear Data structure and list out linear data structure.
4) What is Non-Linear Data structure and list out Non-linear data structure.
5) Draw the diagram of classification of Data structure.
6) Differentiate Primitive data structure and Non-Primitive Data Structure.
7) Differentiate Linear data structure and Non Linear Data Structure.
8) List out application of Data Structure.
9) List out advantages of Data Structure.
10) Define Array with suitable example.
11) Define Array and explain its terminologies: Size, Type, Base, Index, Range of Indices (Any Two).
12) What is the upper bound and lower bound of an array?
13) Write the formula for address calculation of 1-D array element and explain it.
14) Write the formula for address calculation of 2-D array element and explain it.
15) List out applications of an array.
16) Suppose that each element requires 2 word (byte), the base address of the array a[10] is 250 and
lower bound of the array is 0. (Each of 2 Marks)
(a) Find the address of a[4].
(b) Find the address of a[7].
(c) Find the address of a[9].

LONG QUESTIONS

1) Explain in brief Classification of Data Structure


2) List out operations used on Data Structure. Explain any three.
3) Define array. Explain 1-D array with declaration and initialization.
4) Explain 2-D array with declaration and initialization.
5) Explain the representation of 1-D array in the memory.
6) Explain address calculation of 1-D array element with example.
7) List the representation of 2-D array in the memory.
8) Explain address calculation of 2-D array element with example.
9) Explain applications of an array.
10) Assume that the base address of the two dimensional array a[10][10] is 1, each
element requires 1 byte (word). Find the address of the element a[3][2] using

Page 15 of 16
(a) Row-major order
(b) Column-major order
11) Assume that the base address of the two dimensional array a[10][10] is 250, each
element requires 2 byte (word). Find the address of the element a[2][3] using
(a) Row-major order
(b) Column-major order

Page 16 of 16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy