Unit-3 Introduction to Data Structures
Unit-3 Introduction to Data Structures
Data Structure is a way of collecting and organising data in such a way that we can
perform operations on these data in an effective way. Data Structures is about
rendering data elements in terms of some relationship, for better organization and
storage. For example, we have some data which has, player's name "Virat" and age 26.
Here "Virat" is of String data type and 26 is of integer data type.
We can organize this data as a record like Player record, which will have both player's
name and age in it. Now we can collect and store player's records in a file or database
as a data structure. For example: "Dhoni" 30, "Gambhir" 31, "Sehwag" 33
In simple language, Data Structures are structures programmed to store ordered data,
so that various operations can be performed on it easily. It represents the knowledge of
data to be organized in memory. It should be designed and implemented in such a way
that it reduces the complexity and increases the efficiency.
Primitive data structures are basic structures and are directly operated upon by machine
instructions.
Primitive data structures have different representations on different computers.
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.
o Float: It is a data type which use for storing fractional numbers.
o Character: It is a data type which is used for character values.
Pointer: A variable that holds memory address of another variable are called pointer.
Non primitive Data Type
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
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
which insertion occurs is known as REAR end.
o Queue is also called as First in First out (FIFO) data structure.
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.
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.
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