0% found this document useful (0 votes)
15 views

Week one

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Week one

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 55

Overview of data structures and

algorithms
•Data structure is the collection of data values,
•the relation between them and the functions or operations that can
be performed on those data.
Basic concepts of data
structures
Data: Data can be defined as an elementary value or the
collection of values
Group Items: Data items which have subordinate data items
are called Group item
Record: Record can be defined as the collection of various
data items
File:A File is a collection of various records of one type of entity
Basic concepts of data structures
Entity: An entity represents the class of certain objects.
Attribute: attribute represents the particular property of an
entity
Field: Field is a single elementary unit of information
representing the attribute of an entity.
Importance of data structures in computer science

It tells how data can be stored and accessed in its


elementary level.
 Provide operation on group of data, such as adding an item,
looking up highest priority item.
 Provide a means to manage huge amount of data efficiently.
 Provide fast searching and sorting of data.
Features of data structures

Efficiency
Adaptability
Robustness
Reusability
Classification of data structures
Primitive data structures
Non-primitive data structures
 Homogenous
Heterogenous
Classification of data structures
Linear:
Non-linear:
Arrays
Linear data structures
Homogenous
stores data elements in adjacent locations.
Int mark[5] ={40,90,80,70,88};
Classification of Arrays
One-dimensional Arrays
Two-dimensional Arrays
Multi-dimensional Arrays
Limitation of arrays
Arrays are of fixed size.
 Data elements are stored in contiguous memory
locations which may not be always available.
 Insertion and deletion of elements can be
problematic because of shifting of elements from
their positions.
Linked List
Linear data structure
Contain data elements call nodes
Each node contains link or pointer to the next node
and data
The last node contain null pointer
Advantages and disadvantages
of Linked list
Advantage
Easy to insert or delete data element

Disadvantage
Slow search operation and requires more memory
Applications of linked-list
Implementing stacks, queues, binary trees and graphs of predefined
size.
Implement dynamic memory management functions of operating
system.
 Polynomial implementation for mathematical operations
Circular linked list is used to implement OS or application functions
that require round robin execution of tasks
Applications of linked-list
Circular linked list is used in a slide show where a user
wants to go back to the first slide after last slide is displayed.
 Doubly linked list is used in the implementation of forward
and backward buttons in a browser to move backwards and
forward in the opened pages of a website.
Circular queue is used to maintain the playing sequence of
multiple players in a game
Types of Linked List
Singly linked list
Doubly linked list
Circular linked list
Singly Linked List
Doubly Linked List
Circular Linked List
Stacks
Linear data structure
LIFO
Implemented using linked list or arrays
Application of stacks
Temporary storage structure for recursive operations
Auxiliary storage structure for nested operations, function calls,
deferred/postponed functions Manage function calls
Evaluation of arithmetic expressions in various programming
languages
 Conversion of infix expressions into postfix expressions
 Checking syntax of expressions in a programming environment
queue
A queue is a linear data structure
where elements are stored in the FIFO
(First In First Out) principle where the
first element inserted would be the
first element to be accessed.
Representation of Queues
Arrays
Linked List
Pointers
Application of Queues
Job scheduler operations of OS like a print buffer queue, keyboard buffer
queue to store the keys pressed by users
Job scheduling, CPU scheduling, Disk Scheduling
 Priority queues are used in file downloading operations in a browser
 Data transfer between peripheral devices and CPU.
 Interrupts generated by the user applications for CPU
 Calls handled by the customers in BPO
Graph
A Graph is a non-linear data structure that
consists of vertices (nodes) and edges.
Application of graphs
Social networks: Friendships and other relationships
are the edges, while each individual is a vertex.
Potential friends can be suggested via algorithms.
Maps & Navigation: Roads are kept as edges, and
locations, such as towns or bus stations, are saved as
vertices. When represented as a graph, algorithms can
determine the shortest path between two points.
Application of graphs
The Internet can be visualized as a graph,
where hyperlinks are the edges and web pages
are the vertices.
Biology: Neural networks and the spread of
diseases are two systems that graphs can
simulate.
Tree
A tree is a non-linear data structure in which data is
organized in branches
It imposes a hierarchical structure on the data
elements.
Advantages and disadvantages
of trees
Advantage: Provides quick search, insert, and delete
operations
 Disadvantage: Complicated deletion algorithm
APPLICATION OF TREES
Implementing the hierarchical structures in computer systems like
directory and file system.
Implementing the navigation structure of a website.
 Code generation like Huffman’s code.
 Decision making in gaming applications.
 Implementation of priority queues for priority-based OS
scheduling functions
APPLICATION OF TREE
Spanning trees for routing decisions in computer
and communications networks
 path-finding algorithm to implement in AI, robotics
and video games applications
Static data structure and
dynamic data structure
In Static data structure the size of the structure is fixed
In Dynamic data structure the size of the structure in not
fixed and can be modified during the operations performed
on it
Operation of data structures
Traversing
Searching
Inserting
Deleting
Sorting
Merging
Abstract data structure
A collection of data items together with the
operations on the data.
It involves what can be done with the data, not how
has to be done.
Algorithms
Algorithm is a step-by-step procedure, which defines a set
of instructions to be executed in a certain order to get the
desired output.
Algorithms are generally created independent of
underlying languages
Categories of algorithms
Search − Algorithm to search an item in a data structure.
Sort − Algorithm to sort items in a certain order.
Insert − Algorithm to insert item in a data structure.
Update − Algorithm to update an existing item in a data
structure.
Delete − Algorithm to delete an existing item from a data
structure.
Characteristics of algorithms
Clear and Unambiguous:
Well-Defined Inputs:
 Well-Defined Outputs:
Finite-ness:
Feasible
Language independent
Advantage of algorithms
It is easy to understand.
 Algorithm is a step-wise representation of a solution to a given
problem.
 In Algorithm the problem is broken down into smaller pieces or
steps hence, it is easier for the programmer to convert it into an actual
program.
Disadvantages of algorithms
Writing an algorithm takes a long time so it is time-
consuming.
 Branching and Looping statements are difficult to
show in Algorithms.
Approaches to designing
algorithms
Top down approach
Bottom up approach
Top down approache
Problem − Design an algorithm
to add two numbers and display
the result.
Step 1 − START
Step 2 − declare three integers a, b & c
Step 3 − define values of a & b
Step 4 − add values of a & b
Step 5 − store output of step 4 to c
Step 6 − print c
Step 7 − STOP
Problem − Design an algorithm
to add two numbers and display
the result.
Alternatively
Step 1 − START ADD
Step 2 − get values of a & b
Step 3 − c ← a + b
Step 4 − display c
Step 5 − STOP
Algorithm complexity
The complexity of an algorithm f(n) gives the running time and/or
the storage space required by the algorithm in terms of n as the
size of input data
Space complexity
Space complexity of an algorithm represents
the amount of memory space required by the
algorithm in its life cycle
Time complexity
Time complexity of an algorithm represents the amount of
time required by the algorithm to run to completion.
Analysis of algorithm
A Priori Analysis or Asymptotic Analysis
A Posterior Analysis
Type of analysis
Worst case
If an algorithm takes maximum amount of time to execute for a specific set
of input, then it is called the worst case time complexity.
Average case
If the time complexity of an algorithm for certain sets of inputs are on an average,
then such a time complexity is called average case time complexity.
Best case
If an algorithm takes the least amount of time to execute a specific set of
input, then it is called the best case time complexity.
Time complexity
If an algorithm takes the least amount of time to
execute a specific set of input, then it is called the
best case time complexity.
Asymptotic Notations
Big-O notation,
Omega(Ώ ) notation
 Theta(θ) notation

You might also like