Indian Institute of Information Technology Una
Introduction to the course
Ms. Nisha
School of Computing
IIIT Una.
1
Outline
PRESENTATION DO’S 0 INTRO TO SLIDE
0
AND DON’T BUILDING
1 2
0 FONT TYPE AND SIZE 0 WORD LIMIT PER SLIDE AND
3 4 OTHER
2
01 Introduction to the course
3
Course Flow
Data structure
Arrays and link list Stack , Queues
Basics
Searching / sorting
Trees and Graphs
and hashing
Need Of Data Structures
• Data is a collection of facts and figures or a set of values or
values of a specific format that refers to a single set of item
values.
• Information: The term "information" is sometimes utilized for
data with given attributes of meaningful or processed data.
• Field
• Record
• File
• Knowledge
Basics
• Need of Data structure: Data structures provide an easy way of
organizing, retrieving, managing, and storing data.
• Here is a list of the needs for data.
• Data structure modification is easy.
• It requires less time.
• Save storage memory space.
• Data representation is easy.
• Easy access to the large database
• Data Structure is a branch of Computer Science that allows us to
understand the organization of data and the management of the data
flow in order to increase the efficiency of any process or program.
• Data Structure is a particular way of storing and organizing data
in the memory of the computer so that these data can easily be
retrieved and efficiently utilized in the future when required.
• The data can be managed in various ways, like the logical or
mathematical model for a specific organization of data is known
as a data structure.
• The scope of a particular data model depends on two factors:
• First, it must be loaded enough into the structure to reflect the definite
correlation of the data with a real-world object.
• Second, the formation should be so straightforward that one can adapt
to process the data efficiently whenever necessary.
• The data structure is not any programming language like C, C++,
java, etc. It is a set of algorithms that we can use in any
programming language to structure the data in the memory.
• To structure the data in memory, 'n' number of algorithms were
proposed, and all these algorithms are known as Abstract data
types. These abstract data types are the set of rules.
Classification of Data Structure
• DS is broadly classified as Primitive data structure and
Non-primitive data structure.
• The primitive data structures are primitive data types. The int, char,
float, double, and pointer are the primitive data structures that can hold
a single value.
• The non-primitive data structure is divided into two types:
• Linear Data Structure: Elements are arranged in one dimension , also known as
linear dimension.
Example: lists, stack, queue, etc.
• Non-Linear Data Structure: Elements are arranged in one-many, many-one and
many-many dimensions.
Example: tree, graph, table, etc.
Array
• An array is a collection of data items stored at contiguous
memory locations. The idea is to store multiple items of the
same type together. This makes it easier to calculate the position
of each element by simply adding an offset to a base value, i.e.,
the memory location of the first element of the array.
Link Lists
• Like arrays, Linked List is a linear data structure. Unlike arrays,
linked list elements are not stored at a contiguous location; the
elements are linked using pointers.
Stacks
• Stack is a linear data structure which follows a particular order
in which the operations are performed. The order may be
LIFO(Last In First Out) or FILO(First In Last Out). In stack, all
insertion and deletion are permitted at only one end of the list.
Queues
• Queue is a linear structure which follows a particular order in
which the operations are performed. The order is First In First
Out (FIFO). Example of the queue is any queue of consumers for
a resource where the consumer that came first is served first.
Trees
• Trees are hierarchical data structures, in which a node is
connected with multiple nodes creating parent child
relationship. Tree is represented by a pointer to the topmost
node in the tree. If the tree is empty, then the value of root is
NULL.
Graphs
• Graph is a data structure that consists of a collection of nodes
(vertices) connected by edges. Graphs are used to represent
relationships between objects and are widely used in computer
science, mathematics, and other fields. Graphs can be used to
model a wide variety of real-world systems, such as social
networks, transportation networks, and computer networks.
Major Operations
• Searching: We can search for any element in a data structure.
• Sorting: We can sort the elements of a data structure either in
an ascending or descending order.
• Insertion: We can also insert the new element in a data
structure.
• Updation: We can also update the element, i.e., we can replace
the element with another element.
• Deletion: We can also perform the delete operation to remove
the element from the data structure.
Algorithms
• The finite set of instructions which are being carried in a specific
order to perform the specific task.
• It is not the complete program or code; it is just a solution
(logic) of a problem, which can be represented either as an
informal description using a Flowchart or Pseudocode.
• Characteristics of an algorithm:
• Input and output
• Unambiguous: instructions should be clear.
• Finiteness
• Effectiveness
• Language independent
Dataflow of an algorithm
• Problem: A problem can be a real-world problem or any instance
from the real-world problem for which we need to create a program
or the set of instructions. The set of instructions is known as an
algorithm.
• Algorithm: An algorithm will be designed for a problem which is a
step by step procedure.
• Input: After designing an algorithm, the required and the desired
inputs are provided to the algorithm.
• Processing unit: The input will be given to the processing unit, and
the processing unit will produce the desired output.
• Output: The output is the outcome or the result of the program.
Designing an algorithms
• The following are the issues that come while designing an
algorithm:
• How to design algorithms: As we know that an algorithm is a
step-by-step procedure so we must follow some steps to design
an algorithm.
• How to analyze algorithm efficiency
Approaches of Algorithm
• Brute force algorithm: The general logic structure is applied to
design an algorithm. It is also known as an exhaustive search
algorithm that searches all the possibilities to provide the required
solution. Such algorithms are of two types:
• Optimizing: Finding all the solutions of a problem and then take out the best
solution.
• Sacrificing: As soon as the best solution is found, then it will stop.
• Divide and conquer: It allows you to design an algorithm in a
step-by-step variation. It breaks down the algorithm to solve the
problem in different methods and produces a valid output. This valid
output is passed to some other function.
• Greedy algorithm: It is an algorithm paradigm that makes an
optimal choice on each iteration with the hope of getting the best
solution. It is easy to implement and has a faster execution time. But,
there are very rare cases in which it provides the optimal solution.
Approaches of Algorithm
• Dynamic programming: It makes the algorithm more efficient by storing the intermediate
results. It follows five different steps to find the optimal solution for the problem:
• It breaks down the problem into a subproblem to find the optimal solution.
• After breaking down the problem, it finds the optimal solution out of these subproblems.
• Stores the result of the subproblems is known as memorization.
• Reuse the result so that it cannot be recomputed for the same subproblems.
• Finally, it computes the result of the complex program.
• Branch and Bound Algorithm: The branch and bound algorithm can be applied to only
integer programming problems. This approach divides all the sets of feasible solutions into
smaller subsets. These subsets are further evaluated to find the best solution.
• Randomized Algorithm: As we have seen in a regular algorithm, we have predefined input
and required output, and follow some described steps are known as deterministic
algorithms. What happens that when the random variable is introduced in the randomized
algorithm?. In a randomized algorithm, some random bits are introduced by the algorithm
and added in the input to produce the output, which is random in nature. Randomized
algorithms are simpler and efficient than the deterministic algorithm.
• Backtracking: Backtracking is an algorithmic technique that solves the problem recursively
and removes the solution if it does not satisfy the constraints of a problem.
Algorithm Analysis
• The algorithm can be analyzed in two levels, i.e., first is before
creating the algorithm, and second is after creating the algorithm. The
following are the two analysis of an algorithm:
• Priori Analysis: Here, priori analysis is the theoretical analysis of an algorithm
which is done before implementing the algorithm.
• No. of iterations
• They are not hardware dependent
• Returns approximate value.
• Posterior Analysis: Here, posterior analysis is a practical analysis of an
algorithm. The practical analysis is achieved by implementing the algorithm
using any programming language.
• evaluate the running time and space
• Hardware dependent
• Returns Exact value
Algorithm Complexity
• In order to compare algorithms, we must have so criteria to
measure the algorithm efficiency.
• Example: Algorithm M with n input size. So, time and memory
used are the only two measures used for efficiency
measurement.
• Time can be calculated by counting the key operations.
• Space is calculated by maximum occupied memory.
• The complexity can be achieved in terms of function f(n).
So, that means we can have several cases for the complexity:
1. Worst case: the maximum value of f(n) for input n.
2. Average case: the expected value of f(n).
3. Best case: the minimum possible value of f(n).
Asymptotic Analysis
• Big O notation
• Omega Notation
• Theta notation
Calculating algorithm efficiency
• If a function is linear (without any loops or recursions), the efficiency of that algorithm or the running time of
that algorithm can be given as the number of instructions it contains.
• If an algorithm contains certain loops or recursive functions then the efficiency of that algorithm may vary
depending on the number of loops and the running time of each loop in the algorithm.
• The efficiency of an algorithm is expressed in terms of the number of elements that has to be processed. So, if n is
the number of elements, then the efficiency can be stated as
f(n) = efficiency
• Linear loops
for(i=0;i<n; i++)
statement block
f(n) = n
• Logarithmic Loops
for(i=1;i<n;i*=2) for(i=0;i<n;i/=2)
statement block; statement block;
f(n) = log n f(n) = log n
Nested Loops
• Total no. of iterations = no. of iterations in inner loop * no. of iterations in outer loop
• Efficiency is analyzed based on whether it’s a linear logarithmic, quadratic or dependant quadratic nested loop.
Linear logarithmic
for(i=0;i<n; i++)
for(j=1; j<n; j*=2)
statement block;
f(n)= n log n
Quadratic Loop
for(i=0;i<n; i++)
for(j=1; j<n; j++)
statement block;
f(n) = n * n
Dependent Quadratic
for(i=0;i<n; i++)
for(j=0; j<i; j++)
statement block;
f(n) = n (n + 1)/2
Thanks!
Questions and Answers
Contact Details:
Name, Email, and Mobile Number
29