Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
74 views

Data Structure & Algorithm

The document discusses data structures and algorithms. It defines key terms like data structure, cell, field, record, and array. It explains common operations on data structures like traversal, searching, insertion, deletion, sorting, and merging. It also distinguishes between primitive data structures like integers and non-primitive structures like arrays and linked lists. Linear data structures like arrays and linked lists are described as well as nonlinear structures like trees and graphs. The document concludes by explaining row-major and column-major ordering for storing two-dimensional arrays in memory.

Uploaded by

d_dhara
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Data Structure & Algorithm

The document discusses data structures and algorithms. It defines key terms like data structure, cell, field, record, and array. It explains common operations on data structures like traversal, searching, insertion, deletion, sorting, and merging. It also distinguishes between primitive data structures like integers and non-primitive structures like arrays and linked lists. Linear data structures like arrays and linked lists are described as well as nonlinear structures like trees and graphs. The document concludes by explaining row-major and column-major ordering for storing two-dimensional arrays in memory.

Uploaded by

d_dhara
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CE 504 DATA STRUCTURE & ALGORITHM

A. Cells
B. Fields
C. Arrays
D. Records
a. Explain various data structures with example.
b. List primitive and non-primitive data structure with example
c. What is data structure? What are the common operations performed on data
structure. Also explain types of data structure with their example.
d. Define the following term. (i) Array (ii) Field (iii) Cell (iv) Record
e. Explain row-major order of storage for an array.
f. Explain “Insertion and deletion operations are difficult and time consuming with
array”.
g. Define array and structure.
h. State the difference between a class and a structure.

Data Structure
Data may be organized in many different ways; the logical model of a particular
organization of data is called data structure. Data structure is a collection of data
elements whose organization is characterized by assessing operation that are
used to store and retrieve the individual data elements.

Alternative definitions: The different models used to organize data in the main
memory are collectively referred as data structures.

Common operations that can be performed on data structures:


Traversal: Accessing each element exactly once in order to process it.
Searching: Finding the location of a given element.
Insertion: Adding a new element to a structure.
Deletion: Removing existing element from the structure.
Sorting: Arranging the elements in some logical order.
Merging: Combining the elements of two similar sorted structures into a single
structure.

Cell: The smallest fundamental structural unit which represents a data entity.

Fields: A field can be considered to be the smallest piece of information that can
be referenced in programming language.

Record: A record is a collection of related data items. For example, students of a


class, employees of an organization, products manufactured by manufacturing
units etc, form an entity set.

Arrays: Definition 1: An array is an ordered set which consists of fixed number of


objects. Definition 2: An array is a list of finite number of elements of same data

………………………………………………………………………………………………
LDRP Institute of Technology and Research A.B.Patel

1 of 4 of Module 1
CE 504 DATA STRUCTURE & ALGORITHM

type, i.e. integers, real or string etc. The individual elements of the array are
accessed by an index or indices to the array.

Depending on the number of indices required to access an individual elements of


an array, arrays can be classified as:
• One dimensional array
• Two dimensional array
• Multidimensional array

Structures:
A structure is a collection of fields in which the fields may be same or of different
types. A structure declaration forms a template that can be used to create
structures. The fields that make up the structure are called members of structure.

Primitive and Non-Primitive Data Structures: (Brief explanation self as


explained in class)
• Primitive Data Structure:
Ø Integers
Ø Real Numbers
Ø Character information
Ø Logical information
Ø Pointer information
• Non-Primitive Data Structure:
Ø Array
Ø Linked List
Ø Files

The data structures are classified in the following categories.


1. Linear data structures
2. Nonlinear data structures

Linear Data Structures:


In linear data structures, processing of data items is possible in linear fashion,
i.e., data can be processed one by one sequentially. Linear data structure
contains following types of data structures..

• Array: This is simplest type of data structure. By linear data structure, we mean
a list of finite number n of similar data elements referenced, respectively by a set
of n consecutive numbers, usually 1,2,3, …, n If we choose name V for an array,
then the elements of V are denoted as follows. V[1], V[2], V[3], … ,V[n]

• Linked List: A linked list can be defined as collection of nodes. A node has two
fields; information field and address field (link) that contains address of next
node. Following figure shows diagrammatical representation of linked list.

………………………………………………………………………………………………
LDRP Institute of Technology and Research A.B.Patel

2 of 4 of Module 1
CE 504 DATA STRUCTURE & ALGORITHM

• Stacks: A stack, also called last-in first-out (LIFO) system, is a linear list in
which insertion and deletion can take place at one end the TOP. This structure is
similar in its operation to a stack of dishes on a peg system.

• Queues: A queue, also called first-in first-out (FIFO) system, is a linear list, in
which insertion can take place at one end, FRONT, and deletion can take place
at other end, REAR of the list. A line of people waiting for railway reservation
system is an example of queue.

Nonlinear data structures


• Tree: Data frequently contain a hierarchical relationship between various
elements. The data structure, which reflects this relationship, is called a tree.

• Graph: This data structure, sometimes contain relationship between pairs of


elements, which is not necessarily hierarchical in nature.

Representing two-dimensional array in memory


Let A be the two-dimensional m x n array. Though A is pictured as a rectangular
pattern with m rows and n columns, it is represented in memory by a block of m
x n sequential memory locations.

However, the elements can be stored in different ways-

• Column major order


The elements are stored column by column i.e. m elements of the first column
are stored in first m locations, elements of the second column are stored in next
m locations, and so on.

• Row major order


The elements are stored row by row i.e. n elements of the first row are stored in
first n locations, elements of the second row are stored in next n locations, and
so on.

Logical representation of two dimensional array A of size 3 x 3 in memory.

………………………………………………………………………………………………
LDRP Institute of Technology and Research A.B.Patel

3 of 4 of Module 1
CE 504 DATA STRUCTURE & ALGORITHM

Physical representation of two dimensional array A of size 3 x 3 in memory.


Like linear array, system keeps track of the address of first element only i.e. the
base address of the array. Further consider that the lower bound for the row
index is lbr and for column index is lbc.

Using this base address, the computer computes the address of the elements in
the ith row and jth column i.e. loc(a[i][j]), using the following formula.

Column major order:


loc(a[i][j])= base(a) + w[m(j-lbc) + (i-lbr)] IN GENERAL
loc(a[i][j])= base(a) + w[m x j + i] IN C/C++

Row major order:


loc(a[i][j])= base(a) + w[n(i-lbr) + (j-lbc)] IN GENERAL
loc(a[i][j])= base(a) + w[n x i + j] IN C/C++
where w is the number of bytes per storage location for one element of the array.

………………………………………………………………………………………………
LDRP Institute of Technology and Research A.B.Patel

4 of 4 of Module 1

You might also like