Skip to main content

Posts

BIT-Manipulation

  The bits work faster by reducing your execution time as it is the greatest factor in   competitive programming . Faster the execution time better the code performance. So, let’s know about the major hacks that can be done at a bit level to optimise the code. Useful operators for bit manipulation: The  & (bitwise AND)  takes two operands and perform AND operation. It results in 1 if both numbers are the same else 0. The  | (bitwise OR)  takes two operands and perform OR operation. It results in 1 when both bits are different. The  ^ (bitwise XOR)  takes two number as operands and perform XOR operation. It results in 1 if both bits are different. The  << (left shift)   t akes two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift. Or in other words, left shifting an integer “x” with an integer “y” (x<<y) is equivalent to multiplying x with 2^y (2 raised to power y)...

STL-2

  Imagine a situation when you are giving an online competition of coding and there stuck a problem. In the last five minutes, you clicked the idea that the question implements a queue data structure. But you don’t have time to write the whole push, pop functions. So, now you are   STUCK  and you could not finish on time.  Here comes the most powerful weapon of competitive programming the  STL  libraries . The above problem statement could be done with the library “queue”. This library has all the inbuilt functions of queue data structure like pop, push, etc. Moreover, all these libraries are generic and can be implemented for any data type. Below mentioned libraries are a major boon for Competitive Programming: <vector> : The major problem with  c++  arrays is to resize. Vectors come with this beautiful feature to resize. It has more features like cache friendliness, no need to pass the size, can be returned from a function. It has rich lib...