|
1 | 1 | # Data Structures and Algorithms
|
2 | 2 |
|
3 |
| -These notes can be used to find top patterns for each category. Moreover, it can take an evening to refresh your knowledge or understand the important part of each pattern. I highly recommend the following materials (ordered by importance). This repository provides the notes taken from all these sources. |
| 3 | +These notes can be used to find top patterns for each category. Note that reading these notes can be much faster than watching videos. Moreover, it can take only take an evening to refresh your knowledge or understand the important part of each pattern. I highly recommend the following materials (ordered by importance). This repository provides the notes taken from all these sources. |
4 | 4 |
|
5 |
| -- [Udacity nano degree: Data Structures and Algorithms](https://www.udacity.com/course/data-structures-and-algorithms-nanodegree--nd256) |
6 |
| -- [Data Structures, Algorithms, and Machine Learning Optimization](https://www.oreilly.com/library/view/data-structures-algorithms/9780137644889/) |
7 |
| -- [Data Structures and Algorithmic Thinking With Python](https://www.amazon.com/Data-Structure-Algorithmic-Thinking-Python/dp/8192107590) |
| 5 | +- [Udacity nano degree: Data Structures and Algorithms](https://www.udacity.com/course/data-structures-and-algorithms-nanodegree--nd256) |
| 6 | +- [Data Structures and Algorithmic Thinking With Python](https://www.amazon.com/Data-Structure-Algorithmic-Thinking-Python/dp/8192107590) |
| 7 | +- [Data Structures, Algorithms, and Machine Learning Optimization](https://www.oreilly.com/library/view/data-structures-algorithms/9780137644889/) [If you are intrested in ML] |
8 | 8 | - [Bari's YouTube playlist](https://www.youtube.com/watch?v=0IAPZzGSbME&list=PLDN4rrl48XKpZkf03iYFl-O29szjTrs_O) [If you are a beginner]
|
9 | 9 |
|
10 | 10 |
|
@@ -226,6 +226,27 @@ Everythin less than 8 are already below 8 so cemented
|
226 | 226 |
|
227 | 227 | O(n2) if it’s already sorted. Why? Wasting time
|
228 | 228 |
|
| 229 | + |
| 230 | +## Sliding Window |
| 231 | +How to tell if its a sliding window problem? |
| 232 | +• Deals with arrays |
| 233 | +• Find/calculate among subarrays |
| 234 | + |
| 235 | +> Q: Given an array, find the average of each subarray of ‘K’ contiguous elements in it. |
| 236 | +
|
| 237 | + |
| 238 | +Input: ![[Pasted image 20220910145630.png]] |
| 239 | +Output: ![[Pasted image 20220910145753.png]] |
| 240 | +Alg1: Bruteforce return the average for every 5 element |
| 241 | +Time: O(N * K) |
| 242 | +• Its not optimal because we are calculating the sum of overlapping elements between subarray more than once. |
| 243 | +![[Pasted image 20220910150423.png]] |
| 244 | +• Why not use a sliding window and substract and add to the sum? |
| 245 | +![[Pasted image 20220910150647.png]] |
| 246 | +Alg2: Sliding window |
| 247 | + |
| 248 | + |
| 249 | + |
229 | 250 | ## Dynamic Programming
|
230 | 251 |
|
231 | 252 | (Programming == tables)
|
|
0 commit comments