-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA.html
More file actions
255 lines (196 loc) Β· 5.79 KB
/
Copy pathDSA.html
File metadata and controls
255 lines (196 loc) Β· 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>DSA Basic Notes</title>
</head>
<body style="font-family: Arial, sans-serif; background-color:#0f172a; color:#e2e8f0; padding:20px;">
<h1 style="text-align:center; color:#00f7ff;">π DSA Basic Notes</h1>
<p style="text-align:center;">Data Structures & Algorithms β Quick Revision Sheet</p>
<hr>
<h2>π 1. What is DSA?</h2>
<p>
Data Structures and Algorithms (DSA) is the study of organizing data efficiently
and solving problems using step-by-step procedures.
</p>
<hr>
<h2>π§ 2. Time & Space Complexity</h2>
<ul>
<li><b>Time Complexity:</b> Measures execution time (Big-O notation)</li>
<li><b>Space Complexity:</b> Measures memory usage</li>
</ul>
<p><b>Common complexities:</b></p>
<ul>
<li>O(1) β Constant</li>
<li>O(log n) β Logarithmic</li>
<li>O(n) β Linear</li>
<li>O(nΒ²) β Quadratic</li>
</ul>
<hr>
<h2>π 3. Basic Data Structures</h2>
<h3>π Arrays</h3>
<p>Collection of elements stored in continuous memory locations.</p>
<h3>π Linked List</h3>
<p>Elements stored in nodes, each pointing to the next node.</p>
<h3>π Stack (LIFO)</h3>
<p>Last In First Out. Example: Undo operation.</p>
<h3>π Queue (FIFO)</h3>
<p>First In First Out. Example: Ticket counter.</p>
<h3>π Hash Table</h3>
<p>Stores key-value pairs for fast access.</p>
<hr>
<h2>π Basic Data Structures Detailed </h2>
<!-- ================= ARRAYS ================= -->
<h3>π Arrays</h3>
<p><b>Definition:</b> Arrays are collections of elements stored in contiguous (continuous) memory locations.</p>
<ul>
<li><b>Key Features:</b>
<ul>
<li>Fixed size</li>
<li>Fast access using index (O(1))</li>
<li>Stores same data type elements</li>
</ul>
</li>
<li><b>Example (Java):</b>
<pre><code>
int[] arr = {10, 20, 30};
System.out.println(arr[0]); // Output: 10
</code></pre>
</li>
<li><b>Example (Python):</b>
<pre><code>
arr = [10, 20, 30]
print(arr[0])
</code></pre>
</li>
<li><b>Advantages:</b> Fast access, simple structure</li>
<li><b>Disadvantages:</b> Fixed size, costly insertion/deletion</li>
</ul>
<!-- ================= LINKED LIST ================= -->
<h3>π Linked List</h3>
<p><b>Definition:</b> A collection of nodes where each node contains data and a reference (pointer) to the next node.</p>
<ul>
<li><b>Types:</b> Singly, Doubly, Circular Linked List</li>
<li><b>Example (Concept):</b>
<pre><code>
[10] β [20] β [30] β NULL
</code></pre>
</li>
<li><b>Example (Python):</b>
<pre><code>
class Node:
def __init__(self, data):
self.data = data
self.next = None
</code></pre>
</li>
<li><b>Advantages:</b> Dynamic size, easy insertion/deletion</li>
<li><b>Disadvantages:</b> More memory (pointers), slower access (O(n))</li>
</ul>
<!-- ================= STACK ================= -->
<h3>π Stack (LIFO)</h3>
<p><b>Definition:</b> Stack follows Last In First Out (LIFO) principle.</p>
<ul>
<li><b>Operations:</b> push (insert), pop (remove), peek (top element)</li>
<li><b>Real-Life Example:</b> Undo operation, plates stack</li>
<li><b>Example (Java):</b>
<pre><code>
Stack<Integer> stack = new Stack<>();
stack.push(10);
stack.push(20);
stack.pop(); // removes 20
</code></pre>
</li>
<li><b>Example (Python):</b>
<pre><code>
stack = []
stack.append(10)
stack.append(20)
stack.pop()
</code></pre>
</li>
<li><b>Time Complexity:</b> O(1) for push/pop</li>
</ul>
<!-- ================= QUEUE ================= -->
<h3>π Queue (FIFO)</h3>
<p><b>Definition:</b> Queue follows First In First Out (FIFO) principle.</p>
<ul>
<li><b>Operations:</b> enqueue (add), dequeue (remove)</li>
<li><b>Real-Life Example:</b> Ticket counter, waiting line</li>
<li><b>Example (Java):</b>
<pre><code>
Queue<Integer> queue = new LinkedList<>();
queue.add(10);
queue.add(20);
queue.remove(); // removes 10
</code></pre>
</li>
<li><b>Example (Python):</b>
<pre><code>
from collections import deque
queue = deque()
queue.append(10)
queue.append(20)
queue.popleft()
</code></pre>
</li>
<li><b>Time Complexity:</b> O(1)</li>
</ul>
<!-- ================= HASH TABLE ================= -->
<h3>π Hash Table</h3>
<p><b>Definition:</b> A data structure that stores key-value pairs and provides fast access using hashing.</p>
<ul>
<li><b>Key Concept:</b> Hash function maps keys to index</li>
<li><b>Example (Java):</b>
<pre><code>
HashMap<String, Integer> map = new HashMap<>();
map.put("A", 1);
map.put("B", 2);
System.out.println(map.get("A"));
</code></pre>
</li>
<li><b>Example (Python):</b>
<pre><code>
data = {"A": 1, "B": 2}
print(data["A"])
</code></pre>
</li>
<li><b>Advantages:</b> Very fast lookup (O(1) average)</li>
<li><b>Disadvantages:</b> Collision handling needed</li>
</ul>
<hr>
<h2>π 4. Basic Algorithms</h2>
<h3>π Searching</h3>
<ul>
<li>Linear Search β O(n)</li>
<li>Binary Search β O(log n)</li>
</ul>
<h3>π Sorting</h3>
<ul>
<li>Bubble Sort</li>
<li>Selection Sort</li>
<li>Insertion Sort</li>
<li>Merge Sort β O(n log n)</li>
</ul>
<hr>
<h2>π§© 5. Important Concepts</h2>
<ul>
<li>Recursion</li>
<li>Greedy Algorithms</li>
<li>Dynamic Programming</li>
<li>Backtracking</li>
</ul>
<hr>
<h2>β‘ Quick Tips</h2>
<ul>
<li>Always analyze time complexity before coding</li>
<li>Practice problems daily (LeetCode / Codeforces)</li>
<li>Understand logic, donβt memorize solutions</li>
</ul>
<hr>
<p style="text-align:center; color:#00f7ff;">
π Keep learning. Keep building. Keep improving.
</p>
</body>
</html>