Posts

Showing posts from August, 2018

Beginner-2

Image
Bit Manipulation All the input data given to us, as we know is stored in its binary form in the system’s memory. Binary Form implies in its equivalent representation in form of bits. There is a lot of cool stuff which can be done using bits and their manipulations. Have a look at this tutorial : https://www.hackerearth.com/practice/basic-programming/bit-manipulation/basics-of-bit-manipulation/tutorial/ https://www.interviewbit.com/courses/programming/topics/bit-manipulation/ Another thing to keep in mind is that by default when we talk about bits, we think of base-2 representation, however, there are a number of problems where we can expand similar concepts to a base-N representation. We can carry out the bit manipulations by using functions which work for that particular representation and perform tasks akin to the normal bitwise operators. For eg, in this question, one way is to create a function which takes a xor of two numbers with respect to a

Advanced - 1

Image
Advanced Section - 1 Contents: GCD of numbers Euclidean algorithm for GCD (Basic) GCD of two numbers is the largest number that divides both of them. A simple way to find GCD is to factorize both numbers and multiply common factors. Basic Euclidean Algorithm for GCD The algorithm is based on below facts. If we subtract smaller number from larger (we reduce larger number), GCD doesn’t change. So if we keep subtracting repeatedly the larger of two, we end up with GCD. Now instead of subtraction, if we divide smaller number, the algorithm stops when we find remainder 0. . Below is a recursive function to evaluate gcd using Euclid’s algorithm. int gcd(int a, int b) {Ki    if (a == 0) return b;    return gcd(b % a, a); } GCD(10, 15) = 5 GCD(35, 10) = 5 GCD(31, 2) = 1 Time Complexity: O(Log min(a, b))

Beginner - 1

Image
Beginner Section -1 Contents:-   I/O in c++   Understanding Test Cases.   Time Complexity and time limits Hey guys! This is just a small effort to introduce you to the art of Competitive Programming . Give it a read if you love or are enamoured by coding, and even if you are not this is something which might cause a certain stir in your mind and get you fascinated with the Art of Programming. Programming basically entails analysing a given problem statement and working on the data given in the problem ( by storing it in variables, data structures like arrays, strings , graphs etc ) and carefully devising a technique ( an Algorithm ) to solve the question to produce the desired output. One of the highly recommended and preferred languages for Competitive Programming (CP) is C++14. You can go through a basic extended tutorial on C++ on this mentioned link: http://www.ntu.edu.sg/home/ehchua/programming/cpp/cp0_introduction.html Those who are familiar with progra