sanjar-notes / dsa Goto Github PK
View Code? Open in Web Editor NEWC++ basics, Data structures and algorithms.
Home Page: https://sanjar-notes.github.io/dsa/
C++ basics, Data structures and algorithms.
Home Page: https://sanjar-notes.github.io/dsa/
Acknowledge this. And study more about this observation.
There are times in DnC when we use partitioning of problems just for the sake of avoiding brute force enumeration, and we may not combine solutions to subproblems at all.
Maybe this is not DnC, but it's an alternative to brute-force enumeration.
Here's a problem that I solved using this "kind of DnC" approach: https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k/
https://youtu.be/oBt53YbR9Kk - 5hrs
Add master theorem, it's quite useful. See https://en.wikipedia.org/wiki/Master_theorem_(analysis_of_algorithms)
Copying from activity_logger
All single pass 1D array problems rely on the "knowing" what has happened in the past - i.e possibility of creating a fast lookup structure for the till-seen part of the array.
This fast lookup structure may be a number (e.g. in case of Kadane's algorithm) or a hashmap or a heap, anything.
Approximately, this should takeo(n) space and/or o(n) lookup time (small O notation).
If this is not possible - i.e. one cannot create a structure at all or it exceeds the said bound, two (or more) loops are inevitable.
*more than one loop is inevitable
This thinking could be extended to more dimensional structures like n-dimensional arrays or trees or graphs or a combination.
Why this might work - noob level information theory
Object oriented programming and design roadmap
https://youtu.be/wWejXusF9qU
This may make writing recursive functions more involved, and less obvious. Basically it'll add need for a basic test of whether the base case is valid for some cases.
This is undesirable, if true.
Th Vimeagen (Prims algo) https://youtu.be/om4nY7nQyBQ?si=F70CoVp8eREBMAjx (see first 1 min)
I haven't finished string algorithms properly so do it now,
https://www.coursera.org/learn/algorithms-on-strings
I first encountered the problem here. Dividing into halves doesn't work here because the minimum problem size is > 2 (4 in this case).
Questions:
The terminology is the confusing part. Goal: understand it.
https://youtu.be/B31LgI4Y4DQ
Very good course, original channel embedded in video description
Consider this problem to understand Trapping Water - LeetCode
Understanding the problem
Suppose we start from the left and continue, we would stop at a height >= where we started,
and then calculate the water = left * (k - j - 1) - sum(blocks in the way).
Now, apply the same logic to the largest and 2nd largest heights. Basically, we cut the maximum height to be
the 2nd maximum height for each case (of selection of region).
We will basically after finding water between them,
the part on the left and right are completely independent.
So we do have optimal substructure.
But we don't have overlapping subproblems. So this can be done by divide and conquer.
trap(i, j) = trap(i, a) + water(a...b) + trap(b, j) where a, b are first and second maximas (in any order).
Trap will return a number.
Also, we can reuse the walls of a region for outer regions.
*/
/*
Approach 1 - simple recursion is optimal? because we have no overlapping subproblems, so nothing to store.
And recursion is a must because input selection is variable for each case.
As we are doing everything optimally, this is optimal? Is it?
By the way, this gave TLE error on LeetCode.
Use CodingNinjas syllabus (in and as repo contents) and study in depth from these.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.