0% found this document useful (0 votes)
6 views10 pages

Competitive Programming Guide

Competitive programming guide

Uploaded by

debucolumbas2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Competitive Programming Guide

Competitive programming guide

Uploaded by

debucolumbas2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

What is Competitive Programming?

Competitive programming is essentially a time bound sport that requires you


to solve a given problem by writing code. It can be compared to the work of
an artist or a musician, with the difference being that the medium of your
composition is your code. It may seem daunting at first, however once you
dive deep into it, you begin to get obsessed with it, to the extent that there’s a
feeling of incompleteness inside you until and unless you arrive at the right
solution to a problem.

Simply put, if you’ve always had a knack for solving puzzles, mind-benders,
and also like Math, competitive programming is bound to appeal to you.

Check [Link] to learn about the Indian Computing


Olympiad and its incentives.

We are there to help you out with any doubts or queries you may have, at
every step of the way.

Feel free to contact the appropriate CW members whenever you want.

How to get Started

There are a few prerequisites that you should be acquainted with before you
actually start your journey into competitive programming.

1. Needless to say, you should be confident with a programming language,


and it is going to be the medium of communication between your logic and
the compiler. The language you want to learn is C++.
You can follow the given tutorial to familiarise yourself with the language.

[Link]

(Note: A common Myth and Misconception revolves around the idea that
knowing multiple languages makes you a better programmer, however
competitive programming is not about knowing multiple languages but
using any language to give structure to your thoughts and solve problems)
2. Some basic ideas of math and programming that you will require
throughout your journey as a competitive programmer,

[Link] and

[Link]
library-e910f43379ea

3. Read this book to learn about standard algorithms, data structures and
problem solving paradigms : [Link]

How to Improve
Now that you have laid the foundations to become a competitive
programmer, it’s time to start the good stuff.

We recommend you follow the given guided tour and try to perfect each
topic before moving on to the next.

Note: The key to improving is solving as many problems as possible, and to


make sure you learn something new from every problem you solve.

Topic 1: Efficiency:
[Link]
a57d4c72cfb9404ca089bb3f0e1402cf/main

Topic 2: Sorting:
[Link]
[Link]
sorting/
a. Quicksort:
[Link]
a4cbc9509d1/main and [Link]
material/topics/[Link]
b. Mergesort:
[Link]
and
[Link]
8bf964204/main
Quicksort and mergesort won't make too much sense at this point so it's ok if
you don't understand how they work completely. Try to go through them
again while you're going through Topic-6
[Link]

Practice problems:
-[Link]
-[Link]

Topic 3: Searching:
[Link]
[Link]
601e95ee310545a78a429b676def547f/main
[Link]
9efbe64b3fb04690abc1622b461185fd/main

After this read this whole document:


[Link]
binary-search/

Practice problems:
[Link]

[Link]/problems/AGGRCOW/

[Link]
practice-problems/algorithm/the-old-monk/
[Link]

STL:
[Link]
power-up-c-with-the-standard-template-library-part-1/

BITS:
[Link]
manipulation/basics-of-bit-manipulation/tutorial/
[Link]
bit-of-fun-fun-with-bits/

Kadane’s algorithm:
[Link]

Problems for practice:


-[Link]

-[Link]

Recursion:
[Link]
an-introduction-to-recursion-part-1/
[Link]

an-introduction-to-recursion-part-2/

Topic 4: Greedy Algorithms

[Link]

algorithms/tutorial/

[Link]

[Link]
[Link]

greedy-is-good/

Practice Problems:

[Link]

[Link]

[Link]

finals

After this, make an account on codeforces and solve at 50 least Educational

round ‘A’ problems.

Topic 5: Math, Algebra, Number Theory

[Link]

theory-1/tutorial/

[Link]

theory-2/tutorial/

[Link]

combinatorics/tutorial/

[Link]

[Link]

[Link]

[Link]

multiple-queries/
[Link]

multiplication-exponential-squaring

[Link]

basics-of-combinatorics/

Practice Problems:

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

Topic 6: Dynamic Programming

[Link]

[Link]

[Link]

[Link]

[Link]

LIS O(N^2): [Link]

LIS O(NLogN): [Link]


Prefix Sum 1D

[Link]

[Link]

Prefix Sum 2D

[Link]

[Link]

Intro to Dynamic Programming

[Link]

dynamic-programming-from-novice-to-advanced/

Knapsack: [Link]

knapsack-problem/

[Link]

allowed/

Practice Problems:

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]

[Link]
[Link]

[Link]

[Link]

[Link]

[Link]

Topic 7: Stacks

[Link]

next-smaller-element-for-each-element

Practice Problems:

1. Implement a single code that stores for ever index the next larger,

previous larger, next smaller and previous smaller.

2. Given an array, for every range L to R in the array take its minimum

element. Find the sum of these minimum elements in O(N)

[Link]

next-smaller-element-for-each-element

[Link]

Topic 8: Graph Theory -

Part A: Definitions and Representation

Intro: [Link]

[Link]

introduction-to-graphs-and-their-data-structures-section-1/

Practice problems:
Implement a basic code for Adjacency matrix and Adjacency List

(Take input of user for the number of vertices, (1 to n) number of edges and

then take each edge in the form of u v w where u = initial vertex v = final

vertex and w = cost. Output an adjacency matrix with cell [u][v] having value

w for all edges and the cities not directly connected should have value -1. In a

new program output the adjacency list instead, in which for each vertex from

1 to N output the list of vertices it is connected to and the corresponding edge

weight).

[Link]

[Link]

Part B: Reachability and Traversals -

[Link]

[Link]

(Including video)

[Link]

(Including video)

[Link]

introduction-to-graphs-and-their-data-structures-section-2/

Practice Problems:

[Link]

[Link]

[Link]

[Link]

[Link]
[Link]

search/practice-problems/algorithm/b-31/

Part C: DAGs and Topological Sort-

[Link]

[Link]

Practice problems:

[Link]

[Link]

[Link] (Introduces LCA in logN, read

this for a detailed tutorial [Link]

common-ancestor)

Topic 9: Important Tricks:

Binary string generation [Link]

strings-from-given-pattern/

Meet in the Middle

[Link]

Practice Problems:

[Link]

[Link]

Common questions

Powered by AI

The Standard Template Library (STL) in C++ is fundamental in competitive programming as it offers a collection of ready-to-use, efficient algorithms and data structures. Mastering STL allows programmers to implement solutions quickly and focus on problem logic rather than writing complex structures from scratch. Understanding its implementation optimizes code efficiency and significantly impacts performance in time-bound competitions .

Greedy algorithms choose the best possible option at each step aiming for local optimization, which doesn't always lead to a global optimum. In contrast, dynamic programming considers not just immediate consequences, but overall subproblem solutions to ensure the global optimum is found. Greedy algorithms are faster and simpler but limited as they can fail in complex problems requiring consideration of various future consequences. For instance, in certain knapsack problems, a greedy approach won't guarantee the optimal solution while dynamic programming will .

Dynamic programming enhances problem-solving efficiency by breaking down complex problems into simpler subproblems and storing results to avoid redundant calculations. It is particularly advantageous in optimization problems like the Knapsack problem, where it efficiently finds the maximum value that can be put in a knapsack . Another example is calculating the longest increasing subsequence which can be optimized using dynamic programming techniques to reduce time complexity from O(N^2) to O(NLogN).

Competitive programming, like the work of an artist or a musician, involves creating a solution through a medium—in this case, code. However, unlike art or music, the primary focus in competitive programming is on logic and mathematical problem-solving, likened to creating new compositions to solve given problems. The process can become quite consuming, as finding the right solution invokes a sense of completeness much like completing a piece of art or music .

Before starting a journey into competitive programming, one must be confident with a programming language, as it is the medium of communication between logic and the compiler. C++ is recommended for this purpose . Understanding this is significant because competitive programming focuses on problem-solving using any chosen language to structure thoughts effectively rather than knowing multiple languages. Additionally, having foundational knowledge in mathematics and programming concepts is essential as these are required in various competitive programming scenarios .

The 'Meet in the Middle' technique is used to split a problem into two halves, solving each independently, and then combining their results. This is particularly effective for large search space problems where a brute force approach would be infeasible. For instance, in subset sum problems, this technique drastically reduces the solution space from O(2^N) to O(2^(N/2)), making it feasible to handle larger input sizes within time constraints .

Recursion in competitive programming holds significant value as it allows the simplification of problems by reducing them to simpler subproblems, mirroring the divide and conquer approach. It is particularly useful in algorithms like quicksort, depth-first searches, and Fibonacci sequence calculators. Rather than iteratively managing subtask solutions manually, recursion automates the approach, simplifying code structure especially in inherently recursive problems like tree and graph traversals .

Regular practice with a variety of coding problems is crucial in competitive programming as it helps in the retention of concepts and broadens a programmer's ability to tackle diverse problem sets. This continuous engagement develops problem-solving speed, optimizes thought processes, and enhances the ability to adapt and apply different algorithms and data structures efficiently. Each problem poses unique challenges that incrementally increase a programmer's competency and confidence in competitive environments .

Graph theory is crucial in competitive programming as many problems regarding networks, relationships, and paths are modeled using graphs. Mastery is required in graph representation (adjacency matrix/list), traversal techniques (BFS, DFS), pathfinding algorithms (Dijkstra, Bellman-Ford), and special graph types like Directed Acyclic Graphs (DAGs) including topological sorting . These are essential as they underpin solutions to complex real-world problems involving connections and flows.

Understanding sorting algorithms like Quicksort and Mergesort is pivotal because they form the basis of many problems encountered in competitive programming. Quicksort is known for its efficiency in average cases with O(N log N) time complexity and is generally faster due to its in-place sorting nature. Mergesort, while also having O(N log N) complexity, is stable and useful for linked lists or when stable sorting is required, such as in merge routines of large data sequences . Choosing the right algorithm affects the overall performance and solution correctness in contests.

You might also like