Sumit Dsa
Sumit Dsa
=DATA STRATURE
===================================================================================
=======
Data Structure ek aisa way hai jisme data ko organize aur manage kiya jata hai
taaki us data par asani se operations perform kiye ja saken, jaise data ko store
karna, retrieve karna, sort karna, etc.
Samjho ki aapko ek library me kitaaben arrange karni hain. Agar kitaaben haphazard
(bina kisi order ke) rakhi hui hongi, to unko dhoondhna mushkil hoga. Lekin agar
aap unhe alphabetically ya category-wise arrange karoge, to jaldi se mil jayengi.
Data structure kuch aise hi kaam karta hai.
Database ek organized collection hota hai data ka, jise hum efficiently store,
retrieve, update, aur manage kar sakte hain. Database ko use karke hum large amount
of data ko systematic tareeke se store karte hain taaki usse aasani se access kiya
ja sake.
Database ke andar data tables me stored hota hai. Ek table rows (rows) aur columns
(columns) ka collection hoti hai.
Row (पंक्ति): Har row ek record ko represent karti hai.
Column (स्तंभ): Har column kisi specific type ke data ko represent karta hai.
Example: Student ka table, jisme har row ek student ka data (ID, naam, marks, etc.)
hoga aur columns me wo specific information hogi.
===================================================================================
==DATAWAREHOUSE====================================================================
======================
Data Warehouse ek centralized system hota hai jahan large amount of data ko long
term ke liye store kiya jata hai. Iska main purpose analysis, reporting, aur
decision-making ke liye historical data ko store karna hota hai.
Key Concepts:
Structured Data: Data warehouse me structured data store kiya jata hai, jo
databases aur tables ke format me organized hota hai (jaise relational databases).
===================================================================================
===BIG
DATA===============================================================================
===============
Big Data ka matlab hai extremely large aur complex data sets jo traditional
databases ke through process nahi kiya ja sakte. Big Data ka main purpose real-time
processing aur unstructured data ko handle karna hota hai.
===================================================================================
====ALGORTHOM======================================================================
======================
Algorithm ek step-by-step procedure hota hai jo kisi problem ko solve karne ke liye
follow kiya jata hai. Ye ek finite set of instructions hota hai jo clearly defined
steps me bataata hai ki kaise kisi specific problem ko solve kiya jaye.
===================================================================================
====STACK AND
HEAP===============================================================================
========
Stack ek special memory area hai jo LIFO (Last In, First Out) principle par kaam
karta hai. Stack mainly static memory allocation ke liye use hota hai, jisme memory
ko compile-time par allocate aur deallocate kiya jata hai
Pros of Stack:
=============
Cons of Stack:
=============
HEAP
====
Heap ek memory area hai jisme dynamic memory allocation hota hai, matlab memory ko
runtime par allocate kiya jata hai. Jab aapko program ke execution ke dauran
(runtime) memory ki zaroorat hoti hai, to heap se memory allocate ki jati hai.
Pros of Heap:
============
Large amount of memory allocate kiya ja sakta hai.
Memory ko runtime ke hisaab se manage kiya ja sakta hai.
Cons of Heap:
============
Slower Access: Stack ke mukable heap memory access karna thoda slow hota hai.
Memory Fragmentation: Heap me alag-alag sizes ke data ko allocate karne ke baad
memory fragmented ho sakti hai.
===================================================================================
===========notestion===============================================================
======================
Example: Agar algorithm ki complexity O(n) hai, to iska matlab hai ki jaise-jaise
input size (n) badhta hai, waise algorithm ka time linear tareeke se badhta hai.
=======
Example Time Complexities:
=========================
Example: Agar algorithm ki complexity Ω(n) hai, to iska matlab hai ki best-case me
algorithm ka time complexity linear hoga.
========
Example Time Complexities:
==========================
LOG(N)
========
LOG KA MATLAB HOTA HAI KI N KO KITNE BAAR ADA(THODO) KARO
XE=
N=8
8,6,4,2
LOG HOGA VO LOG 4 HOGA KYO KI N KO HAM NE 4 BAR TODA HAI
===============================================================================best
case worst case and average case with
notestion=========================================================
Best case wo situation hoti hai jab algorithm ko sab kuch bilkul sahi milta hai,
aur wo minimum kaam karta hai. Yani ki algorithm sabse kam steps me apna kaam kar
leta hai. Jaise agar aapka exam me wahi question aajaye jo aapne sabse achi tarah
prepare kiya tha.
Example with Linear Search: Sochiye aapko ek array me koi number dhoondhna hai.
Agar wo number array ke bilkul pehle wale position par ho, to aapko bas ek
comparison karna padega
&)Best Case Time Complexity: 𝑂(1)O(1) hoti hai, kyun ke aapko pehle hi element mil
gaya.
Example with Binary Search: Agar aap sorted array me Binary Search use kar rahe
hain aur pehla comparison hi sahi ho jaaye, to aapka kaam turant khatam ho jata
hai.
Example with Linear Search: Agar wo number array ke sabse last position par ho ya
array me ho hi na, to aapko poora array check karna padega.
&)Worst Case Time Complexity: 𝑂(𝑛)O(n) hoti hai, kyunki aapko har element ko check
karna padega.
Example with Binary Search: Binary Search me worst case tab hota hai jab aapko
array ko baar baar half karte hue ek single element tak pahuchna padta hai, phir
bhi number nahi milta.
&)Average Case Time Complexity: 𝑂(log 𝑛)O(logn), kyunki array ko divide karke
search efficient ho jati hai.
Space Complexity:
================
Space complexity yeh batata hai ke ek algorithm kitna zyada memory use karta hai,
time ke ilawa.
Linear Search: Iska space complexity 𝑂(1) hota hai kyunki sirf ek index store
karna hota hai
============
.Binary Search:
version𝑂(log)O(logn)
𝑛
============ Iterative version ka space complexity O(1) hota hai, lekin recursive
hota hai recursion ke call stack ki wajah se.
================================================================================ABS
TRACT DATA
TYPES(ADT)=========================================================================
===========
Abstract Data Types (ADT)** ko hum aise samajh sakte hain jaise ek "naksha" ya
"blueprint" jo batata hai ki kisi data structure par kya-kya operations (kaam) ho
sakte hain, lekin yeh nahi batata ki unko kaise kiya jayega. ADT ek tarah se rules
set karta hai ki hum kin kaamon ko kar sakte hain, jaise data ko insert karna,
delete karna, ya search karna, lekin us data ko kaise store ya manage kiya ja raha
hai, yeh chhupa ke rakhta hai.
Array ADT:
=========
Array ek ADT hai jo elements ka collection hota hai, aur har element ko ek unique
index ke through access kiya ja sakta hai. Array me jo basic kaam (operations) hum
kar sakte hain, wo kuch is tarah ke hote hain:
1. get(i): Yeh function array ke kisi particular index **i** par jo element hai,
usse return karta hai.
2. set(i, num): Is function se hum array ke kisi index **i** par koi naya element
(jaise **num**) set kar sakte hain.
Yeh basic concepts hain jo array ke bare me samajhne ke liye zaroori hain. Agle
step me hum in concepts ko coding ke through implement kar sakte hain.
=====================================================================Array as An
Abstract Data Type in Data Structures
Notes============================================================
Array ko Abstract Data Type (ADT) ke roop me samajhna aasan hai. ADT ek tarah ka
user-defined data type hota hai, jo hum apne hisaab se methods aur operations ke
sath bana sakte hain. Jaise humne int ya float data types ka use kiya hai, waise hi
ADT me hum apne khud ke methods aur operations define kar sakte hain.
Ab samjho ki hume ek array banana hai jo ek customized array ho, jisme hum apne
tarike se values aur operations ko control kar sakein. Hum is array ka naam myArray
rakhte hain. Is array ke kuch important values aur operations honge.
Values (Parameters):
total_size: Yeh parameter array ke total memory size ko batata hai, yaani kitni
jagah reserve ki gayi hai array ke liye.
used_size: Yeh parameter batata hai ki array me kitni memory ka actual use ho raha
hai.
base_address: Yeh pointer hota hai jo array ke pehle element ka address ya memory
location store karta hai.
Example: Agar humne ek array banaya jisme total 6 elements rakhne ki jagah reserve
ki hai, lekin abhi tak sirf 3 elements use ho rahe hain, to:
total_size = 6
used_size = 3
Operations (Methods):
max(): Array me jo sabse bada element hai, use find karne ke liye method.
get(i): Array ke kisi particular index i par jo element hai, usko retrieve karne ke
liye method.
set(i, num): Array ke kisi particular index i par ek naya element set karne ke liye
method.
add(another_array): Do arrays ko mila kar ek naya array banane ke liye method.
Implementation ka idea:
Hum array ko ek structure ke roop me define kar sakte hain, jisme yeh sab values
aur methods honge. Hum in values aur methods ka code likh kar apna customized array
bana sakte hain jo heap memory me store hota hai (heap memory dynamic hoti hai,
isliye hum array ka size change kar sakte hain jab zarurat pade).
================================================================================tra
vertion of the
arrry==============================================================================
=======
element tak jana or dekh na
/******************************************************************************
*******************************************************************************/
#include <stdio.h>
}printf("\n");
}
int main()
{
int arry[100]={12,1,22,33,454,545};
display(arry,6);
return 0;
}
===================================================================================
insertioncode======================================================================
======================
#include <stdio.h>
int insertion(int arry[], int size, int capacity, int element, int index) {
if (size >= capacity) {
printf("chak");
return -1;
}
return 0;
}
int main() {
int arry[100] = {12, 233, 223, 44, 22, 3};
int size = 6, capacity = 100, element = 34, index = 3;
return 0;
}
===================================================================================
=deletion
===================================================================================
============
#include <stdio.h>
// Function to delete an element at a given index and replace it with a new element
int deletion(int size, int index, int arry[], int element)
{
// Loop to shift elements to the left, starting from the specified index
for (int i = index; i < size - 1; i++)
{
arry[i] = arry[i + 1]; // Assign the next element to the current position
}
// Assign the new element to the specified index
arry[index] = element;
}
int main()
{
// Initialize an array with some predefined elements
int arry[100] = {100, 122, 23, 323, 233};
int size = 5; // Number of elements in the array
int index = 2; // Index where deletion and replacement will occur
int element = 221; // New element to insert at the specified index
return 0;
}