Overview of Data Structures
Overview of Data Structures
Structures
Chittaranjan Pradhan
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
1.1
Introduction to Data
Problem Solving Structures
Chittaranjan Pradhan
Algorithm
Problem Solving
Dynamic Memory
Flowchart Allocation
Algorithms
• Flowchart is the pictorial representation of an algorithm Recursive Algorithm
Algorithm Analysis
Pseudocode
1.2
Introduction to Data
Problem Solving... Structures
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.3
Introduction to Data
Problem Solving... Structures
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.4
Introduction to Data
Data structure Structures
Chittaranjan Pradhan
Data structure
Problem Solving
Pointer
Pointer Operations
• It as the mathematical or logical model of particular
Function
organization of data items Structure vs. Union
• It is a storage that is used to store and organize data Dynamic Memory
Allocation
• Data structures are essential and responsible for Algorithms
efficiently
• By using data structure, one can organize and process a
very large amount of data in a relatively short period
1.5
Introduction to Data
Classification of Data structure Structures
Chittaranjan Pradhan
Problem Solving
Data structure
Pointer
• Linear Data Structure: data elements are arranged Pointer Operations
1.6
Introduction to Data
Classification of Data structure... Structures
Chittaranjan Pradhan
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.7
Introduction to Data
Classification of Data structure... Structures
Chittaranjan Pradhan
Function
• SELECTION - deals with accessing a particular data Structure vs. Union
within a data structure Dynamic Memory
Allocation
• UPDATION - updates or modifies the data in the data Algorithms
structure Recursive Algorithm
Algorithm Analysis
1.8
Introduction to Data
Abstract Data Type (ADT) Structures
Chittaranjan Pradhan
Abstract Data Type (ADT)
Data structure
objects that make up a data type as well as the functions
Abstract Data Type
that operate on these objects (ADT)
order. All operations takes place at a single end that is top of Abstract Data Type
(ADT)
the stack and following operations can be performed: Pointer
Pointer Operations
• push() - Inserts an element at one end of the stack called
Function
top Structure vs. Union
• pop() - Removes and return the element at the top of the Dynamic Memory
Allocation
stack, if it is not empty Algorithms
• peek() - Returns the element at the top of the stack Recursive Algorithm
Algorithm Analysis
1.10
Introduction to Data
Pointer Structures
Chittaranjan Pradhan
Pointer
Dynamic Memory
• void * is considered as generic pointer Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.11
Introduction to Data
Pointer Operations Structures
Chittaranjan Pradhan
Pointer Operations
Data structure
8 bytes for 64-bit system and 4 bytes for 32-bit system
Abstract Data Type
• %d - signed integer (ADT)
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.12
Introduction to Data
Pointer Operations... Structures
Chittaranjan Pradhan
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.13
Introduction to Data
Function Structures
Chittaranjan Pradhan
Function
Data structure
• Actual parameter vs. formal parameter
Abstract Data Type
• Pass by value vs pass by reference (ADT)
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.14
Introduction to Data
Array, Pointer, Function Structures
Chittaranjan Pradhan
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.15
Introduction to Data
Structure vs. Union Structures
Chittaranjan Pradhan
Structure
Function
Dynamic Memory
Allocation
• It combines various objects of different sorts and sizes
Algorithms
together Recursive Algorithm
Algorithm Analysis
• It allows storing different types in the same memory
location. It provides an efficient way of using the same
memory location for multiple purposes
1.16
Introduction to Data
Structure vs. Union... Structures
Chittaranjan Pradhan
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.17
Introduction to Data
Structure vs. Union... Structures
Chittaranjan Pradhan
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.18
Introduction to Data
Structure vs. Union... Structures
Chittaranjan Pradhan
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.19
Introduction to Data
Dynamic Memory Allocation Structures
Chittaranjan Pradhan
Problem Solving
Dynamic Memory Allocation Data structure
1.20
Introduction to Data
Dynamic Memory Allocation... Structures
Chittaranjan Pradhan
malloc()
Problem Solving
• It allocates a block of memory in bytes. User should
Data structure
explicitly give the block size it requires for the use Abstract Data Type
(ADT)
• The malloc() is like a request to RAM to allocate memory,
Pointer
if the request is granted, returns a pointer to the first block Pointer Operations
Algorithms
• The type of the pointer it returns is void Recursive Algorithm
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.22
Introduction to Data
Dynamic Memory Allocation... Structures
Chittaranjan Pradhan
calloc()
Data structure
initializes the allocated memory to zero
Abstract Data Type
• It needs two arguments (ADT)
Dynamic Memory
free() Allocation
Algorithms
• It is used to dynamically de-allocate the memory Recursive Algorithm
Algorithm Analysis
free(ptr);
realloc()
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.24
Introduction to Data
realloc(), free()... Structures
Chittaranjan Pradhan
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.25
Introduction to Data
Algorithms Structures
Chittaranjan Pradhan
Data structure
Function
• It is a finite set of instructions which takes some value or
Structure vs. Union
set of values as input; and produces some value or set of Dynamic Memory
values as output to accomplish a particular task Allocation
Algorithms
• Every algorithm must satisfy the following properties: Recursive Algorithm
Algorithm Analysis
• Input: input data supplied externally
• Output: output that has to be obtained
• Definiteness: each step should be clear and unambiguous
• Finiteness: must terminate after a finite number of steps
• Effectiveness: each step must be sufficiently basic and
simple
1.26
Introduction to Data
Recursive Algorithm Structures
Chittaranjan Pradhan
Recursive Algorithm
Data structure
• It is powerful and expresses an complex process very Abstract Data Type
clearly (ADT)
Pointer
• Two properties a recursive function must have: Pointer Operations
1.27
Introduction to Data
Algorithm Analysis Structures
Chittaranjan Pradhan
Data structure
• In designing algorithms, methodologies are required to Abstract Data Type
find the most effective approach for the problems (ADT)
Pointer
• First approach to analyze an algorithm is to check the Pointer Operations
1.28
Introduction to Data
Algorithm Analysis... Structures
Chittaranjan Pradhan
Space Complexity
Problem Solving
of memory space required by the algorithm in its life cycle Abstract Data Type
(ADT)
Function
• A fixed part (FP) that is a space required to store certain
Structure vs. Union
data and variables, that are independent of the size of the Dynamic Memory
problem. Ex: variables, constant, program size etc Allocation
1.29
Introduction to Data
Algorithm Analysis... Structures
Chittaranjan Pradhan
Problem Solving
Time Complexity Data structure
Pointer
time required by te algorithm to run to completion Pointer Operations
Dynamic Memory
number of steps * time taken by each step Allocation
1.30
Introduction to Data
Algorithm Analysis... Structures
Chittaranjan Pradhan
Problem Solving
Asymptotic Analysis Data structure
• O Notation - Big Oh: O(n) is the formal way to express the Function
upper bound of an algorithm’s running time. It measures the Structure vs. Union
1.31
Introduction to Data
Algorithm Analysis... Structures
Chittaranjan Pradhan
Problem Solving
Data structure
Time Complexity... Abstract Data Type
(ADT)
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.32
Introduction to Data
Algorithm Analysis... Structures
Chittaranjan Pradhan
Time Complexity...
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
Data structure
n/c. Thus, complexity T(n)=O(n)
Abstract Data Type
• In the for index updation by *c or ÷c, number of (ADT)
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.34
Introduction to Data
Algorithm Analysis... Structures
Chittaranjan Pradhan
Problem Solving
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
1.35
Introduction to Data
Algorithm Analysis... Structures
Chittaranjan Pradhan
Time Complexity...
If the loop variable is reduced or increased exponentially in a Problem Solving
constant amount, then complexity of the loop is considered as Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis
√
The time complexity of loop is considered O( n) if the loop
variable is multiplied by itself
The time complexity of loop is considered O(1) if the loop
contains break statement 1.36
Introduction to Data
Algorithm Analysis... Structures
Chittaranjan Pradhan
Time Complexity...
Problem Solving
Data structure
Pointer
Pointer Operations
Function
Dynamic Memory
Allocation
Algorithms
Recursive Algorithm
Algorithm Analysis