0% found this document useful (0 votes)
13 views24 pages

Notes PPTS

The document outlines a comprehensive curriculum on Data Structures, covering topics such as arrays, linked lists, stacks, queues, trees, and graphs over multiple days. It includes definitions, implementations, and various algorithms for searching and sorting, along with their complexities. Additionally, it explains the importance of data structures in programming for efficiency, abstraction, and reusability.

Uploaded by

nanikartik13
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)
13 views24 pages

Notes PPTS

The document outlines a comprehensive curriculum on Data Structures, covering topics such as arrays, linked lists, stacks, queues, trees, and graphs over multiple days. It includes definitions, implementations, and various algorithms for searching and sorting, along with their complexities. Additionally, it explains the importance of data structures in programming for efficiency, abstraction, and reusability.

Uploaded by

nanikartik13
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/ 24

PreCAT: OM11

SunBeam Institute of
Information & Technology,
Hinjwadi, Pune & Karad.
SACHIN PAWAR
Sunbeam Infotech www.sunbeaminfo.com
Data Structures

# DAY-01 & DAY-02:


Introduction:
- Why there is a need of data structure?
- What is data structure & its classification?
- What is an algorithm?
Array:
- Searching Algorithms: Linear Search & Binary Search
- Sorting Algorithms:
- Selection Sort, Bubble Sort & Insertion Sort: Algorithms &
Implementation
- Merge Sort & Quick Sort: Only Algorithms.

Sunbeam Infotech www.sunbeaminfo.com


Data Structures

# DAY-03 & DAY-04:


- Limitations of an Array data structure
Linked List:
- Concept & Definition
- Implementation of Singly Linear Linked List Operations: Addition &
Deletion
- Concepts:
- Singly Circular Linked List
- Doubly Linear Linked List
- Doubly Circular Linked List.
- Difference between Array and Linked List

Sunbeam Infotech www.sunbeaminfo.com


Data Structures

# DAY-05 & DAY-06


Stack:
- Concept & Definition
- Implementation of Stack by using an array
- Stack Application Algorithms:
- Conversion of infix expression into its equivalent postfix
expression.
- Conversion of infix expression into its equivalent prefix expression.
- Conversion of prefix expression into its equivalent postfix
expression.
- Evaluation of postfix expression

Sunbeam Infotech www.sunbeaminfo.com


Data Structures

# DAY-07 & DAY-08:


Queue:
- Concept & Definition
- Types of Queue
- Implementation of Linear Queue & Circular Queue
Tree terminologies
Graph terminologies

Sunbeam Infotech www.sunbeaminfo.com


Data Structures

# DAY-07 & DAY-08:


Queue:
- Concept & Definition
- Types of Queue
- Implementation of Linear Queue & Circular Queue
Tree terminologies
Graph terminologies

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Introduction

Q. Why there is a need of Data Structure?


There is a need of data structure to achieve 3 things in programming
1. Efficiency
2. Abstraction
3. Reusability

Q. What is Data Structure?


Data Structure is a way to store data elements into the memory (i.e.
into the main memory) in an organized manner so that operations
like addition, deletion, traversal, searching, sorting etc... can be
performed on it efficiently.

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Introduction

Two types of Data Structures are there:


1. Linear/Basic: data elements gets stored into the
memory in a linear manner and hence can be accessed
linearly.
- Array
- Structure & Union
- Class
- Linked List
- Stack
- Queue
2. Non-linear/Advanced: data elements gets stored into the memory in a non-linear
manner and hence can be accessed non-linearly.
- Tree (Hierarchical)
- Graph

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Introduction

Array: It is a collection of logically related similar type of elements in which data


elements gets stored into the memory at contiguos locations.

Structure: It is a collection of logically related similar and disimmilar type of


elements gets stored into the memory collectively (as a single entity/record).
Sizeof of structure is sum of size of all its members.
Union: Union is same like structure, except, memory allocation i.e. size of union is
the size of max size member defined in it and that memory gets shared among all its
members for effective memory utilization (can be used in a special case only).

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Introduction

Q. What is a Program?
- A program is a set of instructions written in any programming language (like
C, C++, Java, Python, Assembly etc...) given to the machine to do specific task.
- An algorithm is a template whereas a program is an implementation
of an algorithm.

Q. What is an Algorithm?
- An algorithm is a finite set of instructions written in human understandable
language (like english), if followed, acomplishesh a given task.
- An algorithm is a finite set of instructions written in human understandable
language (like english) with some programming constraints, if followed,
acomplishesh a given task, such an algorithm also called as pseudocode.

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Introduction

Example: An algorithm to do sum of all array elements


Algorithm ArraySum(A, n)//whereas A is an array of size n
{
sum=0;//initially sum is 0
for( index = 1 ; index <= size ; index++ ) {
sum += A[ index ];//add each array element into the sum
}
return sum;
}
- In this algorithm, traversal/scanning operation is applied on an array. Initially
sum is 0, each array element gets added into to the sum by traversing array
sequentially from the first element till last element and final result is returned as
an output.

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Introduction

- An algorithm is a solution of a given problem.


- Algorithm = Solution.
- One Problem has many solutions, e.g. Sorting.
Sorting: To arrange data elements in a collection/list of elements either in an
ascending order or in a descending order.
- There are many sorting algorithms/solutions on sorting:
A1: Selection Sort, A2: Bubble Sort, A3: Insertion Sort, A4: Merge Sort,
A5: Quick Sort, A6: Shell Sort, A7: Radix Sort, A8: Heap Sort etc...
- As one problem may has many solutions, there is need to select an efficient
aglorithm/solution out of it, and hence to decide their efficiency we need to do
their analysis.
- Analysis of an algorithm is a work of determining how much time i.e.
computer time and space i.e. computer memory it needs to run to completion.

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Introduction

- There are two measures of an analysis of an algorithms:


1. Time Complexity: It is the amount of time i.e. computer time required
for an algorithm to run to completion.
2. Space Complexity: It is the amount of space i.e. computer memory
required for an algorithm to run to completion.
Asymptotic Analysis: It is a mathematical way to calculate time
complexity and space complexity of an algorithm without implementing it
in any programming language.
- In this type of analysis, analysis can be done on the basis of basic
operation in that algorithm.
e.g. in searching & sorting algorithms comparison is the basic operation and
hence analysis gets done on the basis of no. of comparisons, in addition of
matrices algorithms addition is the basic operation and hence on the basis of
addition operation.

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Introduction

"Best case time complexity": if an algo takes min amount of time to


complete its execution then it is referred as best case time complexity.
"Worst case time complexity": if an algo takes max amount of time to
complete its execution then it is referred as worst case time complexity.
"Average case time complexity": if an algo takes neither min nor max
amount of time to complete its execution then it is referred as an average
case time complexity.
"Asympotic Notations":
1. Big Omega (Ω):): this notation is used to denote best case time
complexity
2. Big Oh (O): this notation is used to denote worst case time complexity
3. Big Theta (θ):): this notation is used to denote an average case time
complexity

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Searching Algorithms

1. Linear Search/Sequential Search:


- In this algorithm, key element gets compared sequentially with each array
element by traversing it from first element till either match is found or
maximum till the last element.
Algorithm LinearSearch(A, size, key)
{
for( index = 1 ; index <= size ; index++ ){
if( key == A[ index ] )
return true;
}
return false;
}

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Searching Algorithms

Best Case: If key is found at very first position in only 1 no. of


comparison then it is considered as a best case and running time
of an algorithm in this case is O(1) = Ω):(1)
Worst Case: If either key is found at last position or key does
not exists, maximum n no. of comparisons takes place, it is
considered as a worst case and running time of an algorithm in
this case is O(n) = O(n)
Average Case: If key is found at any in between position it is
considered as an average case and running time of an algorithm
in this case is O(n/2) = θ):(n)

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Searching Algorithms

2. Binary Search/Logarithmic Search:


- This algorithm follows divide-and-conquer approach.
- To apply binary search on an array prerequisite is that array elements
must be in a sorted manner.
- In this algorithm, in first iteration, by means of calculating mid position big
size array gets divided into two subarray’s, left subarray and right
subarray, key element gets compared with element which is at mid
position, if key is found at mid position in very first iteration in only 1 no. of
comparison, then it is considerd as a best case and in this case an algortihm
takes O(1) time.
- If key is not found in the first iteration then either it will get searched into
left subarray or into the right subarray by applying same logic repeatedly till
either key is not found or till max the size of any subarray is valid i.e. size of
subarray is greater or equal to 1.

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Searching Algorithms

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Searching Algorithms

Best Case: if the key is found in very first iteration at mid


position in only 1 no. of comparison it is considered as a best
case and running time of an algorithm in this case is O(1) =
Ω):(1).
Worst Case: if either key is not found or key is found at leaf
position it is considered as a worst case and running time of an
algorithm in this case is O(log n) = O(log n).
Average Case: if key is not found in the first iteration and it is
found at non-leaf position it is considered as an average case and
running time of an algorithm in this case is O(log n) = θ):(log n).

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Sorting Algorithms

1. Selection Sort:
- In this algorithm, in first iteration, first position gets selected and
element which is at selected position gets compared with all its next
position elements, if selected position element found greater than
any other position element then swapping takes place and in first
iteration smallest element gets setteled at first position.
- In the second iteration, second position gets selected and element
which is at selected position gets compared with all its next position
elements, if selected position element found greater than any other
position element then swapping takes place and in second iteration
second smallest element gets setteled at second position, and so on
in maximum (n-1) no. of iterations all array elements gets arranged
in a sorted manner.

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Sorting Algorithms

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Sorting Algorithms

Best Case : Ω):(n2)


Worst Case : O(n2)
Average Case : θ):(n2)

2. Bubble Sort:
- In this algorithm, in every iteration elements which are two consecutive
positions gets compared, if they are already in order then no need of
swapping between them, but if they are not in order i.e. if prev position
element is greater than its next position element then swapping takes
place, and by this logic in first iteration largest element gets setteled at
last position, in second iteration second largest element gets setteled at
second last position and so on, in max (n-1) no. of iterations all
elements gets arranged in a sorted manner.

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Sorting Algorithms

Sunbeam Infotech www.sunbeaminfo.com


Data Structures: Sorting Algorithms

Best Case : Ω):(n) – if array elements are already


arranged in a sorted manner.
Worst Case : O(n2)
Average Case : θ):(n2)

Sunbeam Infotech www.sunbeaminfo.com

You might also like