0% found this document useful (0 votes)
8 views18 pages

DS Unit 1

The document provides an overview of data structures, including definitions, classifications, and operations. It distinguishes between primitive and non-primitive data structures, elaborating on linear and non-linear types such as arrays, stacks, queues, trees, and graphs. Additionally, it discusses various operations performed on data structures, such as creation, destruction, searching, and sorting.
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)
8 views18 pages

DS Unit 1

The document provides an overview of data structures, including definitions, classifications, and operations. It distinguishes between primitive and non-primitive data structures, elaborating on linear and non-linear types such as arrays, stacks, queues, trees, and graphs. Additionally, it discusses various operations performed on data structures, such as creation, destruction, searching, and sorting.
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/ 18

DATA

STRUCTURE
(1120501)
2
OUTLINE
> Data Management concepts
> Data types
Primitive
Non-primitive
> Types of Data Structures
Linear Data Structures
Non Linear Data Structures
> Operations on Data Structure
Introduction to Data
Structure
> What is Data?
• Data is the basic fact or entity that is utilized in calculation or
manipulation.(Real World Example: Tea Making)
• There are two different types of data Numeric(1,2,3..) data
and Alphanumeric(Aa,Bb,Cc..) data.
• When a programmer collects such type of data for processing,
he would require to store them in computer’s main
memory.
• The process of storing data items in computer’s main memory
is called representation.
• Data to be processed must be organized in a particular
fashion, these organization leads to structuring of data, and
hence the mission to study the Data Structures.
• Computer is an electronic machine which is used for data
processing and manipulation.(Real World example: Chrome:
Enter data(Search)-Processing-Manipulation(Result)) Basic
theory of Input and Output.
• In order to make computer work we need to know
o Representation of data in computer.
o Accessing of data.
o How to solve problem step by step.
For doing this task we use data structure.
> What is Data Structure?
• Data Structure is a representation of the logical relationship existing between
individual elements of data.(Ex: a represent 10, b represent 5/ Logic a+b=?)
• 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.
• We can also define data structure as a mathematical or logical model of a
particular organization of data items.(Ex: 2x+3xy)
• The representation of particular data structure in the main memory of a
computer is called as storage structure.
• The storage structure representation in auxiliary memory is called as file
structure.
• It is defined as the way of storing and manipulating data in organized form so
that it can be used efficiently.(Ex: /,*,+,-)
• Algorithm + Data Structure = Program
• Data structure study covers the following points
o Amount of memory require to store.
o Amount of time require to process.
o Representation of data in memory.
o Operations performed on that data.
• Data Structure mainly specifies the following four things
Organization of Data
Accessing Methods
Degree of Associativity
Processing alternatives for information
5

> Classification of Data Structure

Data Structures are normally classified into two broad categories


1. Primitive Data Structure
2. Non-primitive data Structure
Data Types : A particular kind of data item, as defined by the
values it can take, the programming language used, or
the operations that can be performed on it.
> Primitive / Non-primitive data structures

1) Primitive data structures


• Primitive data structures are basic structures and are directly operated upon by
machine instructions.
• Integers, floats, character and pointers are examples of primitive data structures.
• These data types are available in most programming languages as built in type.
o Integer: It is a data type which allows all values without fraction part.
We can use it for whole numbers.(Ex: 1,2,3,4,5…)
o Float: It is a data type which use for storing fractional numbers.(Ex: 3.14)
o Character: It is a data type which is used for character values.(Ex: Aa,Bb,Cc…)
o Pointer: A variable that holds memory address of another variable are called
pointer.(*ptr - declaration)
2) Non-primitive data structures
• These are derived from primitive data structures.
• The non-primitive data structures emphasize on structuring of a group of
homogeneous or heterogeneous
data items.
• Examples of Non-primitive data type are Array, List, and File.
• A Non-primitive data type is further divided into Linear and Non-Linear data
structure
o Array: An array is a fixed-size sequenced collection of elements of
the same data type.
o List: An ordered set containing variable number of elements is called as Lists.
o File: A file is a collection of logically related information. It can be viewed as a
large list of records consisting of various fields.

Class Task 1: Array explanation with matrices(row


major order and column major order)
> (List)-Linear / Non-Linear data structure
1) Linear data structures :

• A data structure is said to be Linear, if its elements are connected in linear fashion by
means of logically or in sequence memory locations.
• There are two ways to represent a linear data structure in memory,
o Static memory allocation Class Task 2 : What is static and dynamic 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.

1) 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.
2) 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 which insertion occurs is known as REAR end.
o Queue is also called as First in First out (FIFO) data structure.
1) Nonlinear data structures :

• Nonlinear data structures are those data structure in which data items are not arranged in
a sequence.
• Examples of Non-linear Data Structure are Tree and Graph.

1) Tree: A tree can be defined as finite set of data items (nodes) in which data items are arranged 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.

1) 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:
o Un-directed Graph
o Directed Graph
o Mixed Graph
o Multi Graph
o Simple Graph
o Null Graph
o Weighted Graph

Class Task 3 : Diff. between linear and nonlinear


DS
> Operation on Data Structures
1) Create : The create operation results in reserving memory for program elements. This can be done by
declaration statement. Creation of data structure may take place either during compile-time or run-
time. malloc() function of C language is used for creation.
2) Destroy : Destroy operation destroys memory space allocated for specified data structure. free()
function of C language is used to destroy data structure.
3) Selection : Selection operation deals with accessing a particular data within a data structure.
4) Updation : It updates or modifies the data in the data structure.
5) Searching : It finds the presence of desired data item in the list of data items; it may also find the
locations of all elements that satisfy certain conditions.
6) Sorting : Sorting is a 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 : Merging is a process of combining the data items of two different sorted list into a single
sorted list.
8) Splitting : Splitting is a process of partitioning single list to multiple list.
9) Traversal : Traversal is a process of visiting each and every node of a list in systematic manner.

Class Task 3 Answer Class Task 2 Answer


Class Task 1 Answer

1) Array : a collection of elements that are arranged in a fixed order.


Data : 1, 2,3,4,5
BA- Base Address
1 2 3 BL- Base Location
LB- Lower Bound(index- 0)
UB- Upper Bound(last index of array)
(i)- Row index
1 2 3 (j)- Column index

All elements locations is sequentially allocated to the vector. a vector size is fixed and therefore
requires a fixed number of memory locations.
A[2]row[3]column = {(1,2,3) , (4,5,6)}

}
j Junction Point : A[i][j]
0 1 2 i - row index : A[0][1]
i 0 j - column index :2
A= m - number of row
1 n – number of column Then 2 is junction point
2*3 BA – base address
m*n
BA – 50
Size – 4
1) Row Major Order(RMO): Compiler only consider row. It means data/elements compile/run in row order

Formula – [(i*n)+j] * size + base


index 00 01 02 10 11 12
[(1*3)+0] * 4 + 50
RMO = 1 2 3 4 5 6 [3] * 4 + 50
50 54 58 62 66 70
12 + 50
Size – 4 byte
62 Store num 4 in row array

2) Column Major Order(CMO): Compiler only consider column. It means data/elements compile/run in column order

00 10 01 11 02 12
Formula – [(j*m)+i] * size + base
CMO = 1 4 2 5 3 6
[(0*2)+1] * 4 + 50
50 54 58 62 66 70
[1] * 4 + 50
4 + 50
54 Store num 4 in column array
RMO CMO

Nested Loop

Output Elements

Indicate that moving


to the next row

Completion of the
Main function

Output :
Output :
> One dimensional and Two-dimensional array
1) ODA : Simplest data structure that makes use of computed address to locate its elements is the one-
dimensional array or vector. Number of memory locations is sequentially allocated to the vector.
2) TDA: Two dimensional arrays are also called table or matrix

> Applications of Array


1) Symbol Manipulation (matrix representation of polynomial equation) :
• We can use array for different kind of operations
in polynomial equation such as addition,
subtraction, division, differentiation etc…
• We are interested in finding suitable
representation for polynomial so that different
operations like addition, subtraction etc… can be
performed in efficient manner.
• Array can be used to represent Polynomial
equation.
2) Sparse matrix :
• An m x n matrix is said to be sparse if “many” of its elements are zero.
• A matrix that is not sparse is called a dense matrix.
• We can device a simple representation scheme whose space requirement equals the size of the non-zero elements.

c1 c2 c3 c4 c5 c6 c7 c8
r1
r2
r3
r4

Class Task 4 : Write liner representation of below matrix


Class Task 4 Answer

• Here from 6X7=42 elements, only 10 are non zero. A[1,3]=6, A[1,5]=9, A[2,1]=2, A[2,4]=7, A[2,5]=8,
A[2,7]=4, A[3,1]=10, A[4,3]=12, A[6,4]=3, A[6,7]=5.
• One basic method for storing such a sparse matrix is to store non-zero elements in one dimensional
array and to identify each array elements with row and column indices
> How to find array’s length

1 2 3 4 5
Index 0 1 2 3 4

Lower Bound(LB) Upper Bound(UB)

Formula : UB - LB + 1
4-0+1
5

Array’s Length : 5

Note : In array all data/elements are similar for example if you want to display int data then all stored data
are integer and if you want to display char data then all data in array is char types of data
THANK
YOU
Prof. Pandya Khushi

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