DS Unit - 1
DS Unit - 1
Data Structures
3. 4. Operations
Types of Data
Structures Linear and
on Data
Nonlinear Structures
Module 1
Introduction to
Data Structures
1. Introduction
to Data 2. Concept
Structures
of ADT
What is efficient program
Is easy to
Runs read and
Is easy to Is easy to Runs
correctly understand debug modify Fast
Data Structure=Organized data +Allowed operations
Need of
2. Stores data in data 5. Static and
systematic way structures dynamic
formats
Primitive DS Non-Primitive DS
Integer
Character
Linear DS Non-Linear DS
Boolean
Integer trees
Stack Graphs
Queue Sets
Linked list Tables
❑ Primitive and Non-Primitive Data Type
Applications
of DS
Solve real
DBMS world problems
Efficiency of Programs
The programs are written to solve
02
The programs efficiency is
based on the execution time
and memory space utilization.
03
on the data structure used to represent
data on which operations like search,
sort, insert, etc are performed.
❑ Types of Data Structures and its operations
Index 0 1 2 3 4 5 6 … 9
Marks[ 10 20 30 45 60 70 88 11
index]
Benefits?
Linked list is dynamic data structure in which
elements can be inserted and deleted anywhere
without shifting. In contract to fixed size in arrays,
linked list can allocate memory to data elements
during run time also.
12 56 89 29
Advantages
Disadvantages
❑ Linear DS- Stack
• A stack is an ordered collection of data elements into which
1 elements can be inserted or deleted only from one end, called the
top of the stack as shown in figure.
• Known as Last in First out(LIFO) Data structure.
2
58 Top of stack
98
16
21
❑ Examples on Stack
22
❑ Linear DS-Queue
24
A binary tree is another commonly used Nonlinear DS- Trees
data structure. It is organized like an
upside-down tree
02
The middle item from the list is stored in the root node,
with lesser items to the left and greater items to the
right.
03
A search begins at the root. The computer either find the
data, or moves left or right, depending on the value for
which you are searching
06
Telephone directory assistance information is
stored in a tree, so that a name and phone number
can be found quickly.
Nonlinear DS- Graphs
Graph is a collection of vertices(nodes)
and edges that connect these vertices.
29
❑ Abstract Data Type
• Solving a problem involves processing data, this requires that we identify-
• Such a collection of data items together with the operations on the data is
called an abstract data type (ADT).
• The word abstract refers to the fact that data and operations are defined
independent of its implementation.
• We just specify what can be done with the data, and not how it is done.
30
❑ Example of ADT
• Problem- Because of new government regulation, the university has to
keep records of all students currently receiving financial aid and submit
regular reports to government. Design the program for the same.
Data: Student_data: int id, string name, list of financial aid awarded <
source, amount>
Operation:
• Get_record(),Update_amount()
31
❑ Implementation of ADT
• An implementation of the ADT consists of storage structures to store
1 the data items and algorithms for the basic operations.
2 • For example:
We use structure in C to store student financial records and
algorithms are written for basic operations.
32
❑ Advantage of ADT
• Data abstraction: The idea of separating the definition of data
1 definition from implementation enables software designers to study
data types without being concerned about the details of its
implementation.
2 • Reuse: Programmers may reuse these data types and its operation
without worrying about its implementation.
• To manage complexity: To manage the complexity of problems and
3 the problem-solving process, computer scientists use abstractions to
allow them to focus on the “big picture” without getting lost in the
details.
33
❑ Reflection
1. Abstract data type represents –
1 A. Set of data types and operations defined on that data type.
B. The data types and operations implemented using
programming language
C. The data types and its values only
34
Software design –
Problems are often complex and ill-defined. Such
problem solving approaches
complex problems are solved by breaking the
problem into subproblems also known as
modularization.
36
❑ Modularization
37
❑ Solution design
38
CARATERISTICS OF AN ALGORITHM
OUTPUT EFFECTIVENESS
01 INPUTS
03 sequence of steps
to be processed
Languages like C follows top down Languages such as C++ and JAVA follows
approach bottom up approach
Usually begins with high level design Usually begin with low level degin or
and ends with low level design or development and ends with high level
development design
Main function is written at the Main function is written at the end and
beginning and remaining functions remaining function/classes are defined
are defined below main above main
02
AVERAGE CASE
01 03
WORST CASE BEST CASE
CASE TO
ANALYSE
ALGORITHM
❑ Algorithm complexity
43
❑ Big-O ‘O’ notation
44
❑ Big-O ‘O’ notation
• LIMITATIONS
1
• ITS COMPLEXITY OF AN ALGORITHM ONLY CONSIDERS LARGE INPUT
• IT GIVES ONLY WORST CASE BOUND
• IT IGNORED CONSTANTS WHETHER IT IS CONSTANT OVERHEAD
45
ORDERS OF GROWTH
O(N) N
O(2 )
01 02 03 04
2
O(1) O(N)
THANKYOU