1/24/25, 3:06 PM
Data Structures | Manvendra's Learning
TRIMESTER-1 CLASS SUMMERY
Data Structures
Total lecture 18
Course Content
Exams
Material
Lecture 1: (11/01/2025 )
Class Recording
4MB
Lecture 1_class_notes.pdf
pdf
What is Algo
Problem
When we say algo is solving
Lecture 2:(12/01/2025 )
Class Recording
4MB
Lecture 2_class_notes.pdf
pdf
https://m-tech-in-artificial-intelligenc.gitbook.io/manvendra_learning/trimester-1-class-summery/dsa
1/9
1/24/25, 3:06 PM
Data Structures | Manvendra's Learning
InsertionSort:
Technic ==> Incremental
Pseudocode code
(A, n)
for i = 2 to n:
key = arr[i]
j = i - 1
while j > 0 and arr[j] > key:
arr[j + 1] = arr[j]
j = j - 1
arr[j + 1] = key
// Python Code of Insertion sort
array = [6, 5, 4, 3, 1, 2]
print("Initial Array =", array)
for i in range(1,len(array)):
ele = array[i]
j = i-1
while j>=0 and ele< array[j]:
array[j+1] = array[j]
j = j-1
array[j+1] = ele
print("i =", i, "Then Array =", array)
// Dry Run
Initial Array = [6, 5, 4, 3, 1, 2]
i = 1 Then Array = [5, 6, 4, 3, 1, 2]
i = 2 Then Array = [4, 5, 6, 3, 1, 2]
i = 3 Then Array = [3, 4, 5, 6, 1, 2]
i = 4 Then Array = [1, 3, 4, 5, 6, 2]
i = 5 Then Array = [1, 2, 3, 4, 5, 6]
Measure the Run Time
Code it and check the runtime
Drawback:
• Depend upon the size of Array
• Hardware depends
https://m-tech-in-artificial-intelligenc.gitbook.io/manvendra_learning/trimester-1-class-summery/dsa
2/9
1/24/25, 3:06 PM
Data Structures | Manvendra's Learning
Run Time
No of basic operation an algo perform as function of input size f(n)
let's take the example of InsertionSort
Basic operation
No of times
Total Time
for i = 2 to n:
2
N
2n
key = arr[i]
1
N-1
N-1
j=i-1
1
N-1
N-1
while j > 0 and arr[j]
> key:
2
Σti i = 2..n
2 *Σti
arr[j + 1] = arr[j]
1
Σt(i-1) i = 2..n
Σt(i-1)
j=j-1
1
Σt(i-1) i = 2..n
Σt(i-1)
arr[j + 1] = key
1
N-1
N-1
T(n) = Basic operation * No of times
T(n) = 2n + 3(n-1) + 2 Σ times + 2 Σ (ti-1)
Best case scenario:
when ti = 1
= 2n + 3(n-1) + 2(n-1) + 0
= 7n - 5 ==> an + b where a and b are const
= O(n)
Worst case scenario
when ti = i
= 2n + 3(n-1) + 2(n(n+1)/2-1) 2(n-1)/2-1
= a*n2 + B, an2 + b where a and b are const
= O(n2)
Why only leading term matters
https://m-tech-in-artificial-intelligenc.gitbook.io/manvendra_learning/trimester-1-class-summery/dsa
3/9
1/24/25, 3:06 PM
Data Structures | Manvendra's Learning
Larger power take more time to execute for large number of data set it might take
less time for smaller vales depending on the expression. We can prove this by graph
Lecture 3:(18/01/2025 )
Class Recording
56MB
Lecture 3_class_notes.pdf
pdf
Merge Sort
Technic => Divide and conquer
Divide => one or more smaller problem
conquer => Solve the sub problem using recursively
Combine => Merge the solution of small problem and create solution of problem
Pseudocode code
https://m-tech-in-artificial-intelligenc.gitbook.io/manvendra_learning/trimester-1-class-summery/dsa
4/9
1/24/25, 3:06 PM
Data Structures | Manvendra's Learning
call => MergeSort(arr, 1, length(arr))
MergeSort(arr, s, e):
if s >= e:
return
mid = s + (e - s)/2
MergeSort(arr, s, mid)
MergeSort(arr, mid+1, e)
Merge(arr, arr[s: mid], arr[mid+1: e])
// end of method MergeSort
Merge(arr, left, right):
i = 1, j = 1, k = 1
n = length(left)
m = length(right)
while i <=n and j <=m:
if left[i]<= right[j]:
arr[k]= left[i]
i++
else
arr[k]= right[j]
j++
k++
//end of while
while i <=n:
arr[k]= left[i]
i++, k++
while j <=m:
arr[k]= right[j]
j++, k++
//end of Merge method
Complexity
T (n) = 2k T (n/2k ) + cn
T(n) = c’NlogN +cN => O(NlogN) (b/c it is leading term)
https://m-tech-in-artificial-intelligenc.gitbook.io/manvendra_learning/trimester-1-class-summery/dsa
5/9
1/24/25, 3:06 PM
Data Structures | Manvendra's Learning
Recurrence Reaction
A is a equation a/c to which a term of sequence of no is equal to some combination of
previous term
Recursive Tree Method
T (n) = 3 ∗ T (n/4) + cn2
level => LogN +1
Height => log4(n+1)
Length => (Log4(n+1))3
Total Time => O(n2)
Lecture 4:(19/01/2025 )
Class Recording
https://m-tech-in-artificial-intelligenc.gitbook.io/manvendra_learning/trimester-1-class-summery/dsa
6/9
1/24/25, 3:06 PM
25MB
Data Structures | Manvendra's Learning
Lecture 4_class_notes.pdf
pdf
Self learning: Stack, queue and Linked-list
Hashing
It is typically to maintain a dynamic set that support three operations => CRD
Dynamic set: Set of elements where every element has key
Direct-address Tables (Array)
Every election of Dynamic set has a distinct key
Every element has a key. Like in array index is key
Key = {0,1,… n-1}
Cons => Space issue
To tackle this problem we use Hash Tables
Hash Tables
In hash table denoted by T[0: m-1], whr m< n
Manvendra's Learning
Whatsapp
Linked In
Key = {0,1,… n-1}
Hash function
T [h(x.key)], whereh : U 0, 1 … m − 1
Issue when two values map on same key this is called Collision.
https://m-tech-in-artificial-intelligenc.gitbook.io/manvendra_learning/trimester-1-class-summery/dsa
7/9
1/24/25, 3:06 PM
Data Structures | Manvendra's Learning
2 is Collision point
Chaining
• to handele collision
• we create a linked list
• we will map the key to a linked list and that connect the new element
Lecture 5: (25/01/2025 )
Class Recording:
Previous
Machine Learning
Next
Optimization
Last updated 4 hours ago
https://m-tech-in-artificial-intelligenc.gitbook.io/manvendra_learning/trimester-1-class-summery/dsa
8/9