Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Data_Structures_Algorithms

The document provides an introduction to data structures and algorithms, defining data structures as ways of storing data and algorithms as methods for processing that data. It discusses the relationship between data structures and algorithms, emphasizing their interdependence in program development, and categorizes data structures into linear and non-linear types. Additionally, it covers specific data structures like stacks, their operations, and real-life applications.

Uploaded by

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

Data_Structures_Algorithms

The document provides an introduction to data structures and algorithms, defining data structures as ways of storing data and algorithms as methods for processing that data. It discusses the relationship between data structures and algorithms, emphasizing their interdependence in program development, and categorizes data structures into linear and non-linear types. Additionally, it covers specific data structures like stacks, their operations, and real-life applications.

Uploaded by

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

Data Structures and Algorithms

An Introduction to the
Foundation of Programming
Ashish Kumar Singh
SET, Jain University
What are Data Structures and
Algorithms?
• - The term data structure is used to
describe the way data is stored.
• - The term algorithm is used to describe
the way data is processed.
• - Data Structure <--interrelated--->
Algorithm
• - Data structure affects the kind of
algorithm we might use.
• - Choosing an algorithm affects the data
structures we use.
What is an Algorithm?
• - An algorithm is a finite sequence of
instructions, each of which has a clear
meaning and can be performed with a
finite amount of effort in a finite length of
time.
• - Example: Sorting a list of numbers,
searching for an element in a database.
What is a Data Structure?
• - A data structure is a representation of the
logical relationship existing between
individual elements of data.
• - It defines a way of organizing all data
items, considering not only the elements
stored but also their relationship to each
other.
• - Example: Arrays, Linked Lists, Trees,
Graphs.
Linear Data Structures
• - A data structure is said to be linear if its
elements form a sequence or a linear list.
• - Examples: Arrays, Linked Lists, Stacks,
Queues.
Algorithm + Data Structure =
Program
• - To develop a program for an algorithm,
we should select an appropriate data
structure for that algorithm.
• - Therefore, the relationship is represented
as:
• Algorithm + Data Structure = Program
Classification
• Data structures are divided into two types:
• • Primitive data structures.
• • Non-primitive data structures.
Classification of Data Structures
Data structures: Organization of data

• Contiguous
• Non-Contiguous.
• In contiguous structures, terms of data are kept
together in memory (either RAM or in a file).
• An array is an example of a contiguous structure.
Since each element in the array is locatednext to one
or two other elements. In contrast, items in a non-
contiguous structure and scattered in memory, but we
linked to each other in some way. A linked list is an
example of a non-contiguous data structure. Here, the
nodes of the list are linked together using pointers
stored in each node. Figure below illustrates the
difference between contiguous and non contiguous
structures.
Representation.
• Contiguous structures can be broken drawn further into
two kinds:
• Those that contain dataitems of all the same size, and
those where the size may differ.
• Figure shows example ofeach kind. The first kind is
called the array. shows an example of an array of
numbers. In an array, each element is of the same type,
and thus has the same size.
• The second kind of contiguous structure is called
structure, figure shows a simplestructure consisting of a
person’s name and age. In a struct, elements may be of
different datatypes and thus may have different sizes.
Examples of contiguous
structures.
Non-contiguous structures:
• Non-contiguous structures are
implemented as a collection of data-items,
called nodes, where each node can point
to one or more other nodes in the
collection. The simplest kind of
noncontiguous structure is linked list.
• A linked list represents a linear, one
• A linked list represents a linear, one-
dimension type of non-contiguous
structure, where ther is only the notation of
backwards and forwards. A tree such as
shown in is an example of a two-
dimensional non-contiguous structure.
Here, there is the notion of up and down
and left and right.
• In a tree each node has only one link that
leads into the node and links can only go
down the tree. The most general type of
non-contiguous structure, called a graph
has no such restrictions.
Hybrid Structure
05-02-2025
• Mechanical -
34,30,26,20,5,1,4,28,17,2,27,21,24,11,19,
• Electrical - 16,6
• Civil : 1
Stack
• Stack is a linear, abstract data structure
where the elements could be added or
deleted only at one open end called the
top of the stack.
• That means we cannot add an element
anywhere on the stack or we cannot
delete an element from anywhere.
• It is only the top end where an element
could be added or deleted.
Introduction to Stack
• A stack is a linear, abstract data structure.
• Elements can only be added or deleted
from the top of the stack.
• No insertion or deletion from anywhere
else.
LIFO Principle
• Stack follows Last In, First Out (LIFO)
order.
• The last element added is the first one
removed.
• The first element added is the last one
removed.
Stack Operations
• Push Operation: Insert an element into
the stack.
• Pop Operation: Remove the top element
from the stack.
Stack Overflow & Underflow
• Overflow State: Stack is full, push
operation rejected.
• Underflow State: Stack is empty, pop
operation rejected.
Demonstration of Stack
Operations
• 1. Insert 10 → Stored at index 0.
• 2. Insert 20 → Stored at index 1.
• 3. Insert 30 → Stored at index 2.
• 4. Pop → Removes 30.
• 5. Pop → Removes 20.
• 6. Pop → Removes 10 (Stack is empty).
Real-Life Applications of Stack
• - Function calls and recursion.
• - Undo/Redo operations in software.
• - Backtracking (Maze solving, DFS in
graphs).
• - Expression evaluation (Postfix, Prefix).
Upcoming Topics
• - Real-life software examples using Stack.
• - Implementation of Stack in C
programming.
Quiz
Quiz
Quiz
Quiz
Thank You!
• Stay tuned for the next lecture.
• Questions & Discussion.

You might also like