Skip to content

Commit 885d36c

Browse files
authored
Updated the readme
1 parent cb23ada commit 885d36c

File tree

1 file changed

+48
-204
lines changed

1 file changed

+48
-204
lines changed

README.md

Lines changed: 48 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ Q: For inputs (dates), what are the valid inputs? Q: How input are encoded? (yyy
6868

6969
**Step 2: Write simple code that works partially for the problem**
7070

71-
- Chances are, you need to consider all possible conditions. Often, this results in getting stuck in finding the perfect solutions. Hence, its advisable that you find the simplest solution that works. E,g, solve with a single simple case.
71+
- Chances are, you need to consider all possible conditions. Often, this results in getting stuck in finding the perfect solutions. Hence, it's advisable that you find the simplest solution that works. E,g, solve with a single simple case.
7272

7373
Tips: Break into simple parts so that we can see our progress. Write simple small codes that work No need to figure out all the details.
7474

7575
![](media/807b5c8aee182baaa1713c01e98994f9.png)
7676

7777

78-
Now we look into the main topics that are being covered in most interviews/coding challenges. We also look into the patterns that appear in solutions which can be used in new problems. The goal is to understand the fundamentals and try to use them to solve problems.
78+
Now we look into the main topics that are being covered in most interviews/coding challenges. We also look into the patterns that appear in solutions that can be used in new problems. The goal is to understand the fundamentals and try to use them to solve problems.
7979

8080

8181
## Binary Search
@@ -128,75 +128,13 @@ O (n log (n))
128128

129129
**Q:** Why we are seeing log (n) in our efficiency? Hint: same as the binary search problem
130130

131-
**Quick Sort:**
132-
Idea is to use pivots to sort the array.
133-
134-
![](media/efb964d97b2648ca21e04162697e01e1.png)
135-
136-
137-
On each step we are performing two moving around.
138-
139-
![](media/2aab5b68c0b0e7ea62486cfe66e08caa.png)
140-
141-
(Pivot = Last element)
142131

143-
1. Select the rightmost element as the pivot
144-
2. Shift Pivot to left by one element
145-
3. Swap start and left
146-
4. Compare Start with pivot. If (Start \> Pivot repeat step 2)
147-
5. Else move to second start
148-
149-
![](media/b41c1c2d2548c9e6940e3506ec84f34f.png)
150-
151-
![](media/4def5b724f6f15c6b099ce425f8c4e09.png)
152-
153-
![](media/4a3923fde43ff67cc4066b14626677b0.png)
154-
155-
Why it can be chosen as the most efficient algorithm?
156-
157-
Because on average it will outperform merge sort.
158-
159-
160-
**Great no need to move the original pivot anymore (2 is at the right place)**
161-
162-
![](media/c018057d901372ab5b57e93742036550.png)
163-
164-
Check 2 with lefts
165-
166-
New pivot on right. Compare
167-
168-
Moving phase
169-
170-
Everything less than 8 and 10 sweep results in:
171-
Everything less than 8 is already below 8
172-
173-
![](media/c018057d901372ab5b57e93742036550.png)
174132

175133
**Efficiency:**
176134

177135
O(n2) if it’s already sorted. Why? Wasting time
178136

179137

180-
## Sliding Window
181-
How to tell if it's a sliding window problem?
182-
• Deals with arrays
183-
• Find/calculate among subarrays
184-
185-
> Q: Given an array, find the average of each subarray of ‘K’ contiguous elements in it.
186-
187-
188-
Input: ![[Pasted image 20220910145630.png]]
189-
Output: ![[Pasted image 20220910145753.png]]
190-
Alg1: Bruteforce returns the average for every 5 element
191-
Time: O(N * K)
192-
• Its not optimal because we are calculating the sum of overlapping elements between subarrays more than once.
193-
![[Pasted image 20220910150423.png]]
194-
• Why not use a sliding window and subtract and add to the sum?
195-
![[Pasted image 20220910150647.png]]
196-
Alg2: Sliding window
197-
198-
199-
200138
## Dynamic Programming
201139

202140
(Programming == tables)
@@ -252,181 +190,87 @@ Longest common subsequent
252190

253191
![](media/1f11fb9b2ed3eb432764db5635531f54.png)
254192

255-
## Complexity Theory
256-
257-
Class P: n, n\^2,… (Any problem that can be solved in poly time)
258-
259-
Class NP (Non deterministic): A set of decision problems where yes can be verified in polytime.
260-
261-
Descion problems (answers are yes or no) can I go from a to be less than 100miles? Lets take traveling sales man. Optimization can I do this less than 100 miles?
262-
263-
Is the answer more thaan 100? Yes is it lower than 200? 150? This way you will solve the problems
264-
265-
Proof/verified/certificate Orlando – Atlanta – L.A
266-
267-
Is this number a prime 234715307129734085? Hard to check
268-
269-
Suppose this number not a prime? 1324 if the answer is no it can be verified quickly
270-
271-
Class Co-NP: \_No\_ polytime
272193

273194
## Greedy Algorithm
274-
(Best option at each step)
195+
The best option at each step might not lead to the best results.
275196

276197
![](media/44d46f063fca4872104e6edb1a26e63d.png)
277198

278-
ATM machine : 1,2,10,20,50,100\<
279-
280-
Return: n\$ the number of bills should be minimized
281-
282-
21\$ = 20 +1
283-
284-
N= 365 – (3x100)- (1x50)-(1x10) – (1x 5)
285-
286-
What about Target = 8?
287-
288-
Example:
289-
290-
Min operations example {see code}: By using while, in dividing numbers in half // == / and using
291-
292-
##
293199
## Graph Algorithm
294-
(data structure that shows relation)
295-
Graph(Tree is a subgroup of graph,Network) Nodes(Vertex) Edges
200+
Graph is a data structure that is mostly used to shows relations.
296201

297202
![](media/d5e6c36b1d10faaaf0d1ae40e3182cca.png)
298203

299-
Directed (non-directed), Acyclic, Connectivity
300-
301-
Connectivity: You friends (social circle)
302-
303-
As seen below, the right graph is stronger. In contrast, the left group can be dissolved if one of the connections drops.
304-
305-
![](media/4c958b1e2b2f2c7a5c54dc66945872db.png)
306-
307-
![](media/426dc47adbe8aa35d9ca78e2e77905be.png)
308-
309-
Go through array reccursavley.
310-
311-
![](media/9475b959311dc362995bdb778c55234b.png)
312-
313-
Let’s define 3 variables
314-
315-
![](media/9beca1381c793944285f552ff3a4842c.png)
316-
317-
Final answer we be the best solution out of these both (A[i] B[i] )
318-
319-
# 5. Technical Interview
204+
Directed (non-directed), Acyclic
320205

321-
Now lets focus on the technical interviews. We tend to simplify the concepts by using memory palace techniques. I adivse everyone to develop a memory palace for algorithms/techniques that requrie knowledge about more than 6-7 steps.
206+
The notion of connectivity: As seen below, the right graph is stronger. In contrast, the left group can be dissolved if one of the connections drops.
322207

323-
![](media/4fe578f16ea7ad1e9fd04d71fdea444a.png)
324208

325-
The context should be asking questions and brainstorm at first. As you go on you rather than asking question everystep you must make statements and justify them.
326-
327-
{so we can have null input like [] Is that right?} { I have a feeling that it might be useful in future steps}
328-
329-
Example: So it contains integers right? So Null input is another input that we can have.
330-
331-
Q:
332-
A: Thanks it’s a pleasure to do interview with you. {Positive mindset} {Don’t give up}
333-
334-
1. **Clarifying the question {To prove you wont dive into the problem without learning more about it}**
335-
336-
Q: Given a 2D matrix of m, Just 0 and 1. Count the number of islands in the matrix [island is a group of 1 or just 1 by itself.]
337-
338-
A: ok so, we are given a 2D matrix which will look something like this.:
339-
340-
[[1,0,1],[1,1,1)
341-
342-
So, our goal is find the number of islands. Is the outcome the number? Or X? So if the are connected (I[1,0,0],[0,1,0],[0,0,1]) diagonally? Does that consider an island?
343-
344-
So what we supposed to do is to find the number of
345-
346-
{Just want to check Im solving the right problem…}
347-
348-
1. Generating inputs and outputs:
349-
350-
> So my input is matrix of 0 s, 1 s (Integers, strings? No)
351-
352-
> Output: Integer (\# of islands) (1s or group of ones)
353-
354-
1. Generating test cases:
355-
356-
> {So just to test some cases {Special}}
357-
358-
> {Can we get Is it ok we have }? Yes
359-
360-
Q: number of island in a matrix
361-
362-
\*\*1.Clarify the question \*\*
363-
364-
A[[1,0,0),[1,1,0){Just to make sure I’m solving the right problem….}
365-
366-
**2.Generating input/output**
367-
368-
\<\<\<\<\<\<\< HEAD 1. Generating input/output
369-
370-
Input matrix of integers
371-
372-
Output integers ( number of islands 0- max{n})
209+
# 6. Practice Problems
210+
DSA problems:
211+
- [Algorithmic Thinking](https://www.amazon.com/Data-Structure-Algorithmic-Thinking-Python/dp/8192107590)
212+
- [LeetCode](https://leetcode.com/)
373213

374-
1. {Trick \#1 you can always answer the null case to interviewer.}{ I have a feeling that it might be useful in future steps} **Test cases** [**Edge cases**] [ Possible weird inputs that we have to handle A or none object
214+
Machine Learning:
215+
- [Cracking ML inteviews](https://github.com/shafaypro/CrackingMachineLearningInterview)
216+
- [Machine Learning Interviews](https://github.com/khangich/machine-learning-interview)
217+
- - [Interview Problems for ML engineers](https://mlengineer.io/common-leetcode-questions-by-categories-532b301130b)
218+
- [Interview Problems + Solutions](https://github.com/ashfarhangi/Data-Structures-and-Algorithms/blob/master/Leetcode-Problems.ipynb)
375219

376-
{Null - empty- Write a code that doesnt crash}
220+
The following sources can be used for academia and research:
221+
- [CLRS book](https://www.amazon.com/Introduction-Algorithms-3rd-MIT-Press/dp/0262033844)
222+
- [COT 5405: Design & Analysis Algorithms](http://www.cs.ucf.edu/~sharma/COT5405)
223+
- [COT 6410: Computational Complexity](http://www.cs.ucf.edu/courses/cot6410/Spring2021/COT6410Spring2021.html)
377224

378-
1. **Brainstorming** So if we have null, for sure we have 0 so there would be no islands in this case. ======= Input matrix of integers.Output integers (number of islands 0- max{n})
225+
## Archive:
226+
**Complexity Theory**##
379227

380-
**3.Test cases**: {Trick \#1 you can always answer the null case to interviewer.}{ I have a feeling that it might be useful in future steps} **Test cases** [**Edge cases**] [ Possible weird inputs that we have to handle A or none object.
228+
Class P: n, n\^2,… (any problem that can be solved in polytime)
381229

382-
{Null - empty- Write a code that doesnt crash}
230+
Class NP (Nondeterministic):
383231

384-
**4.Brainstorming:** {Variables that needs to initialized} {so I need to track X} {And keep tracking} {Runtime error} {Data structure brainstorm algorithms and data structures} {Represent graph DFS problem} So if we have null, for sure we have 0 so there would be no islands in this case. \>\>\>\>\>\>\> 600e13278473db6cc40a022e79c37c0e0baa2b56
232+
Class Co-NP: \_No\_ polytime
385233

386-
But also we can have this as input (the input she wants) {So what I am thinking here} is start at the first element . So i need a counter **variable** and I **initialze** it there. And **increment** it by 1.
234+
**Quick Sort:**
235+
The idea is to use pivots to sort the array.
387236

388-
We get to Zero. Thats not part of any island so I need to keep track of X. Hmmmm. Maybe I can look at the elements on top and bottom and check if they are on the same island and keep track of it. Since there is no above that. We get a run time error. Maybe it could a case of data structure we can solve this. {This might be a breath first search problem. I can look at the elements around it. **Set to mark** as **visited** and **keep going**
237+
![](media/efb964d97b2648ca21e04162697e01e1.png)
389238

390-
**If you are stuck?** This represent a type of data structure and algorithm . Merge sort maybe… Keep talking
391239

392-
\*\*5. Runtime anaylsis \*\*
240+
On each step we are performing two moving around.
393241

394-
When I’m looking all the elements in matrix I’m looking at them atlease once so I’m thinking the runtime would be nXm where N is the number of rows and M is the number of columns. Well it seems like the optimal solution. So i think i start and jump on coding now.
242+
![](media/2aab5b68c0b0e7ea62486cfe66e08caa.png)
395243

396-
**6.Coding**
244+
(Pivot = Last element)
397245

398-
So I’m calling my mainfunction islandCounter():
246+
1. Select the rightmost element as the pivot
247+
2. Shift Pivot to left by one element
248+
3. Swap start and left
249+
4. Compare Start with pivot. If (Start \> Pivot repeat step 2)
250+
5. Else move to second start
399251

400-
Variable a,b,c If() While() For()
252+
![](media/b41c1c2d2548c9e6940e3506ec84f34f.png)
401253

402-
**7.Debugging**
254+
![](media/4def5b724f6f15c6b099ce425f8c4e09.png)
403255

404-
Test cases: input None -\> return 0 so its working
256+
![](media/4a3923fde43ff67cc4066b14626677b0.png)
405257

406-
So [[1,0,1],[1,1,0). Go ahead, that looks good. Now I’m adding both of these. And I probably {} O looks like I forget to {add a return} Looks like it works.
258+
Why it can be chosen as the most efficient algorithm?
407259

260+
Because on average it will outperform merge sort.
408261

409-
\<\<\<\<\<\<\< HEAD while(len(q)!= 0):
410262

411-
And run it by
263+
**Great no need to move the original pivot anymore (2 is at the right place)**
412264

413-
{oh looks like I forget to}
265+
![](media/c018057d901372ab5b57e93742036550.png)
414266

415-
Looks like it works.
267+
Check 2 with lefts
416268

269+
New pivot on right. Compare
417270

418-
# 6. Practice Problems
419-
DSA problems:
420-
- [Algorithmic Thinking](https://www.amazon.com/Data-Structure-Algorithmic-Thinking-Python/dp/8192107590)
421-
- [LeetCode](https://leetcode.com/)
271+
Moving phase
422272

423-
Machine Learning:
424-
- [Cracking ML inteviews](https://github.com/shafaypro/CrackingMachineLearningInterview)
425-
- [Machine Learning Interviews](https://github.com/khangich/machine-learning-interview)
426-
- - [Interview Problems for ML engineers](https://mlengineer.io/common-leetcode-questions-by-categories-532b301130b)
427-
- [Interview Problems + Solutions](https://github.com/ashfarhangi/Data-Structures-and-Algorithms/blob/master/Leetcode-Problems.ipynb)
273+
Everything less than 8 and 10 sweep results in:
274+
Everything less than 8 is already below 8
428275

429-
The following sources can be used for academia and research:
430-
- [CLRS book](https://www.amazon.com/Introduction-Algorithms-3rd-MIT-Press/dp/0262033844)
431-
- [COT 5405: Design & Analysis Algorithms](http://www.cs.ucf.edu/~sharma/COT5405)
432-
- [COT 6410: Computational Complexity](http://www.cs.ucf.edu/courses/cot6410/Spring2021/COT6410Spring2021.html)
276+
![](media/c018057d901372ab5b57e93742036550.png)

0 commit comments

Comments
 (0)