summaryrefslogtreecommitdiff
path: root/PlaygroundCpp
AgeCommit message (Collapse)Author
2018-12-28Max expression with paren done!HEADmasterHaidong Ji
Thanks googletest! I figured out the way to convert char to int using the minus '0' trick. All done with all exercises for UCSD Algo MicroMaster first course! Woohoo, what fun! I'm very happy :) On to more fun stuff! I'll try different IDEs. So far I've used Eclipse for all exercises. But for next one, I'm thinking of trying Jetbrains IDEA, PyCharm, and possibly Code::Blocks for C/C++.
2018-12-27Knapsack partition3 done!Haidong Ji
2018-12-26Knapsack maximize gold done!Haidong Ji
Interesting signal 11 segmentation fault problem. Once I changed the 2D array to 2D vector, it worked: // int value[W + 1][j + 1]; vector< vector<int> > value(W + 1, vector<int>(j + 1));
2018-12-25Woohoo, longest subsequence (3 seqs) done!Haidong Ji
2018-12-25Longest subsequences (2 seqs) done!Haidong Ji
Working with vector in C++ is much easier than arrays!. Plus in Java all ints are initialized as 0, but not in C++, so I had to add logic to do that properly.
2018-12-22Edit Distance done!Haidong Ji
2018-12-19Primitive calculator done!Haidong Ji
Relatively easy since I worked it out in Java and Python. Slight change of getting rid of the 2 dimensional array, which is probably better and should have been done in Java and Python. Man, C++ is way more efficient than Java and Python.
2018-12-17coin change Dynamic Programming done!Haidong Ji
2018-12-17Closest Pair done in C++!Haidong Ji
Finally Divide and Conquer section is finished. A lot of work but so much fun! A few take aways: 1. Be careful when copying code over from Java to C++. Java does parameter passing through reference as default, but I forgot to add "&" in C++ code, which caused my code not passing earlier; 2. Avoid unnecessary calculation. For example, the sqrt calculation is not necessary, until the last step. Avoiding that in my Python code saved a lot of time. 3. It seems that preallocate vector size, if you know beforehand, is a good idea. Woohoo, onto the next section!
2018-12-09Organize lottery done!Haidong Ji
2018-11-28Inversion count done!Haidong Ji
Worked out the algo earlier, but the challenge was to learn to use vector in C++ and vector slicing. I got bad allocation error initially due to misunderstanding that the end is not inclusive: that is, vector.begin() + m reaches vector.begin() + m-1.
2018-11-23Improved QuickSort done!Haidong Ji
2018-11-16Majority Element finally done!Haidong Ji
Wow, it took awhile to finish. Work has been busy and I haven't had time to hack...
2018-10-10Binary search done!Haidong Ji
It was interesting that int in jave has a bigger range than int in C++ Java: https://cs.fit.edu/~ryan/java/language/java-data.html C++: https://stackoverflow.com/questions/1819189/what-range-of-values-can-integer-types-store-in-c I used vector<int> initially, which failed on grader's test case 17/36. Changing that to vector<long> fixed it! Also interesting that recursive approach appears to be slightly faster with slighter bigger memory usage.
2018-10-03Largest number aka maximize salary done!Haidong Ji
2018-09-28Maximize num of places of prize done!Haidong Ji
More practice with C++ vector.
2018-09-27Covering segments/Collecting Signature done!Haidong Ji
Really fun to implement it in C++. Learned std::sort, std::unique, == overloading for struct for std::unique to work. Good stuff!
2018-09-07max dot product doneHaidong Ji
also known as maximize online ad revenue in exercise pdf file.
2018-09-07Fractional Knapsack done.Haidong Ji
Good exercise. Learned C++ vector usage, and the ASSERT_NEAR macro for testing floats/doubles. Lots of fun.
2018-09-02Changing money done.Haidong Ji
I noticed that in this case, it was really simple, because I pretty much copied the code from Java.
2018-08-29Fixing merging errorsHaidong Ji
2018-08-29Partial Fib sum last digit done for C++Haidong Ji
This concludes the second module of Algorithmic Design and Techniques from edX. I had a lot of fun doing it. It's challenging and I learned a lot!
2018-08-28Fib sum last digit done!Haidong Ji
2018-08-26Huge Fib mod M done!Haidong Ji
This was so much fun! I'm glad I did it with Python, Java, and C++, in that order. I learned so much through the process: typing, overflow, BigInteger, and ended up not needing BigInteger! Yay!!!
2018-08-19LCM done!Haidong Ji
2018-08-19GCD done!Haidong Ji
2018-08-16Got googletest going and fib last digit done!Haidong Ji
2018-08-13First optimized Fibonacci done!Haidong Ji
2018-08-07Max Pairwise Product implemented!Haidong Ji
2018-08-06Initial commit.Haidong Ji