Lec01 (Week 1) - CS 232 - Data Structure
Lec01 (Week 1) - CS 232 - Data Structure
TO DATA
STRUCTURES
Instructor: Abid Ali
WHAT IS DATA?
Data is defined as facts or figures, or information that's stored in or used by
a computer.
OR
Statistics or other information represented in a form, that is suitable for
processing by computer.
DATA TYPE
What data types mean?
A data type is a organization of data which tells the compiler or interpreter how
the programmer aims to use the data
Examples
Int
Float
Char
Bool
String
WHAT IS DATA STRUCTURE?
Data Structure can be defined as the collection of data elements which
provides an well-organized way of storing and forming data in the
computer so that it can be used competently.
OR
A data structure is a specific way of forming data in a computer so that it
can be used efficiently.
OR
A data structure is an arrangement of data in a computer’s memory or disc
storage.
WHY WE NEED DATA
STRUCTURE?
Processor speed:
To handle very large amount of data, a very high speed processing is needed, but
as the data is growing day by day to the billions of files, processor may fail to deal
with that much amount of data.
Data Search:
Let us consider an inventory that has 106 items in a store, If our application needs
to search for a particular item, it needs to pass through 106 items each time,
results in slowing down the search process.
Multiple requests:
If thousands of users are searching the data simultaneously on a web server, then
there are the chances that a very large server can be failed during that process.
In order to overcome the these problems, data structures are used. Data is
organized to form a data structure in such a way that all items are not required
to be searched and required data can be searched immediately.
ADVANTAGES OF DATA
STRUCTURE
Data structure helps in effective storage of data in the storage device.
Data structure usage provides ease while accessing the data from storage
device.
Data structure provides effective and well-organized processing of small as
well as large amount of data.
Usage of proper data structure, can help programmer save lots of time or
processing time while using operations such as storage, retrieval or
processing of data.
Handling of large amount of data can be carried out easily with the use of
good data structure approach.
Most of the well organized data structures like Array, stack, queues, graph,
tree, linked list has well built and pre-planned approach for operations like
storage, addition, accessing, handling, deletion, etc.
While using them, programmer can be completely rely on these data
structures.
Data structures are reusable.
Data structure like array, linked list, tree, graph, stack, etc. are well tested
and proven one.
So any one can easily use them directly without need to research and
development on them.
CLASSIFICATION OF DATA
STRUCTURE
Data structure can be classified as
Integer
The integer is defined as a whole number.
Any number with no decimal points.
It can be positive, negative or 0.
Float
It can be defined as a variable with fractional value.
Any variable is said to be float variable if it has decimal or no decimal.
It means fractional and non fractional values both are involved in float variables.
Character
Character in the data structure represents letter and symbol such as a, B, f, R, “.” ,
“-” and whitespace.
It can store the basic character set. it can hold one letter/symbol like n, F,d, etc.
Pointer
A pointer represents a storage location in memory (RAM).
In the RAM contains many cells and the values are stored in these cells.
Each cell in memory is 1 byte and the memory address is always an unsigned
integer.
Therefore, each cell has a unique address to identify it.
NON PRIMITIVE DATA
STRUCTURE
A way of defining our own data type is known as Non Primitive Data Structure.
o Array
Dynamic
o Linked List
o Stack
o Queue
Graph
ARRAY
An array is a collection of items stored at contiguous memory locations.
Array is a container which can hold a fix number of items and these items
should be of the same type.
Mostly Array are used for implementation of certain algorithms.
In the above Graph, the set of vertices V = {0,1,2,3,4} and the set of edges E =
{01, 12, 23, 34, 04, 14, 13}.
TREE
Tree also comes in non primitive and non linear category of data structure.
Trees are multilevel data structures with a hierarchical relationship among
its elements known as nodes.
A tree is a hierarchical representation/relation between set of elements.
A tree is a hierarchical data structure defined as a collection of
nodes.
Nodes represent value and nodes are connected by edges.
Each node has one parent only but can have multiple children.
Each node is connected to its children via edge.
OPERATIONS ON DATA
STRUCTURE
Few operations can be performed for designing an efficient data structure.
The most commonly used operations on data structures are following:
1. Create
2. Destroy
3. Selection
4. Updating
5. Searching
6. Sorting
7. Merging
8. Splitting
9. Traversal
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.
Destroy
Destroy operation destroys memory space allocated for specified data structure.
In C language free() function used to destroy data structure.
Selection
Selection operation is used for opening a particular data within a data structure.
Updating
Update operation updates or modifies/changes a data in the data structure.
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.
Sorting
Sorting is a process of arranging all data items in a data structure in a particular
order
It can be either in ascending order or in descending order.
Merging
Merging is a process of combining the data items of two different sorted list into a
single sorted list.
Splitting
Splitting is a process of partitioning single list to multiple list.
Traversal
Traversal is a process of visiting each and every node of a list in systematic
manner.