Library of all the algorithms implemented in C++/Java that I have encountered. Some of the code examples here are taken from the "Competitive Programming 3" book.
I'm still writing most of this, and it's still under development. I will be adding more and more algorithms as I learn more things.
Areas Already Organized
- Simple built-in features
- Data Structures
printf scanfinstead of
cin coutfor a speedup.
- Use the
algorithm::sortas it runs in O(nlogn), and it is cache friendly.
- For Bit manipulation use built-in integer data types, and if not enough use bitset rather than vector.
ArrayListis faster than Vector.
BufferedReader in = new BufferedReader(new InputStreamReader(System.in, ”ISO−8859−1”));
To run C++ faster you can use tags like:
g++ -std=c++11 -O3 filename.cpp
This will run the third optimization level of g++.
-O3 is only appropriate when trying to generate fast code though - use it with caution.
-Ofast would also work: -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for all standard compliant programs.