0% found this document useful (0 votes)
4 views28 pages

Data Structures and Algorithms

The document provides an overview of data structures and algorithms, detailing various types of data structures such as arrays, linked lists, and stacks, along with their definitions and applications. It explains the classification of data structures, types of arrays, and the concept of sparse matrices. Additionally, it covers stack operations and their applications in function calls, recursion, and expression evaluation.

Uploaded by

harithapramod09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views28 pages

Data Structures and Algorithms

The document provides an overview of data structures and algorithms, detailing various types of data structures such as arrays, linked lists, and stacks, along with their definitions and applications. It explains the classification of data structures, types of arrays, and the concept of sparse matrices. Additionally, it covers stack operations and their applications in function calls, recursion, and expression evaluation.

Uploaded by

harithapramod09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

DATA STRUCTURES and

ALGORITHMS
- Sulfyth M
Data structures

Arrays and their Applications; Sparse Matrix, Stacks, Queues,


Priority Queues, Linked Lists, Trees, Forest, Binary Tree,
Threaded Binary Tree, Binary Search Tree, AVL Tree, B Tree,
B+ Tree, B* Tree, Data Structure for Sets, Graphs, Sorting
and Searching Algorithms; Hashing.
Data Structure
Definition:
A data structure is a specialized format for organizing, storing, and managing data in a
computer's memory or storage. It defines the logical or mathematical relationships
between data elements and specifies the operations that can be performed on the data.
Classification of Data Structures
Arrays
Definition:

In computer science, an array is a fundamental data structure used to store a collection of


elements, typically of the same data type, at contiguous memory locations. Each element is
identified by a unique index or key, allowing for efficient access and manipulation.

An array in C is a fixed-size collection of similar data items.


❖ Items are stored in contiguous memory locations.
❖ Can be used to store the collection of primitive data types such as int, char, float, etc.,
as well as derived and user-defined data types such as pointers, structures, etc.
Types of Arrays
❖ Single-Dimensional Arrays (One-Dimensional Arrays):
➢ These arrays store a linear sequence of elements of the same data type.
➢ Each element is accessed using a single subscript (index) that indicates its position in the
sequence.
➢ They are often used to represent lists or simple collections of data.
❖ Multi-Dimensional Arrays:
➢ These arrays store elements in a grid-like or multi-dimensional structure.
➢ Elements are accessed using multiple subscripts, typically representing rows, columns, and
potentially other dimensions.
➢ Two-Dimensional Arrays (2D Arrays):
■ Represent data in a tabular form, like a matrix, with rows and columns.
■ Accessed using two subscripts: one for the row and one for the column.
❖ Three-Dimensional Arrays (3D Arrays) and Higher:
➢ Represent data in more complex, multi-dimensional structures.
➢ Accessed using three or more subscripts, corresponding to each dimension.
Applications of Arrays
❖ Storing and accessing data: Arrays store elements in a specific order and allow
constant-time O(1) access to any element.
❖ Searching: If data in array is sorted, we can search an item efficiently.
❖ Implementing other data structures: Arrays are used as the underlying data structure for
implementing stacks and queues.
❖ Dynamic programming: Dynamic programming algorithms often use arrays to store
intermediate results of subproblems in order to solve a larger problem.
❖ Data Buffers: Arrays serve as data buffers and queues, temporarily storing incoming data
like network packets, file streams, and database results before processing.
Sparse Matrix
A sparse matrix, in the context of data structures, is a matrix where the vast majority of its
elements are zero. This contrasts with a "dense" matrix, where most elements are non-zero.
Types of Sparse Matrix
Types based on Structure:

❖ Diagonal Matrix: Only elements on the main diagonal are non-zero.


❖ Triangular Matrices:
➢ Lower Triangular Matrix: All elements above the main diagonal are zero.
➢ Upper Triangular Matrix: All elements below the main diagonal are zero.
❖ Tridiagonal Matrix: Non-zero elements exist only on the main diagonal, the diagonal
immediately above it, and the diagonal immediately below it.
Linked List
A linked list is a fundamental data structure in computer science. It mainly allows
efficient insertion and deletion operations compared to arrays. Like arrays, it is also used
to implement other data structures like stack, queue and deque.
Types of Linked List
❖ Singly Linked Lists
❖ Doubly Linked Lists
❖ Circular Linked Lists
Doubly Linked List
Circular Linked List
Stacks
A stack is a linear data structure that adheres to the Last In, First Out (LIFO) principle, also
known as First In, Last Out (FILO). This means that the last element added to the stack is the
first one to be removed.

❖ Operations:
➢ Push: Adds a new element to the top of the stack.
➢ Pop: Removes and returns the element currently at the top of the stack.
➢ Peek/Top: Returns the element at the top of the stack without removing it.
➢ isEmpty: Checks if the stack contains any elements.
➢ isFull (for fixed-size implementations): Checks if the stack has reached its
maximum capacity.

Overflow & Underflow conditions


Applications of Stack
❖ Function calls: Stacks are used to keep track of the return addresses of function calls,
allowing the program to return to the correct location after a function has finished
executing.
❖ Recursion: Stacks are used to store the local variables and return addresses of recursive
function calls, allowing the program to keep track of the current state of the recursions.
❖ Expression evaluation and conversion: Stacks are used to evaluate expressions in postfix
notation (Reverse Polish Notation).
❖ Syntax parsing: Stacks are used to check the validity of syntax in programming languages
and other formal languages.
❖ Memory management: Stacks are used to allocate and manage memory in some operating
systems and programming languages.
❖ Undo/Redo functions, String reversal, Parentheses checking, Backtracking….
Expression Conversion
Stacks are used to convert expressions and evaluate them. There are three types
of notations

1. Infix - eg: a+b


2. Postfix - eg: a b + (Reverse Polish Notation)
3. Prefix - eg: + a b (Polish Notation)
Example
Convert the following infix expression to postfix (A+B)^C-(D*E)/F
Precedence and associativity of operators
( ) { } [ ] - (highest precedence)

^%↑ (higher precedence)

%* (higher precedence)

+ – (lower precedence)

Associativity

/ * left to right

+ – left to right

^ right to left
convert
M*N+(O^P)*W/U
2025
e
Jun
2 023
c
De
2 023
c
De
2019
e
Jun
The postfix expression for the infix expression x ^ y / ( 5 * z ) + 1 0 is:

A) xy^5z*/10+
B) xy5*z^/10+
C) xy^5z*10/+
D) xy5z^*/10+
20 23
M ar
Convert the expression (A+B)*C-(D-E)^(F+G) to equivalent postfix notation?

A) AB+C*DE – FG+^ –
B) AB – C*DE–FG+^
C) AB+CDE* – – FG+^
D) AB+*CDE – – FG+^

You might also like