SlideShare a Scribd company logo
Competitve Programming
Analyzing and Solving problems
By Gaurav Agarwal
What is it?
 Writing programs to solve problems in a
contest environment.
 One has a limited time to solve the
problems. Ranging from a few hours to
a few days.
 The solution should be efficient in terms
of execution time, memory used or in
some cases even the length of code.
What’s new?
 The code will be executed on an Online Judge (OJ).
 Which means you should write code which conforms
to the specific format of input and gives the output in
the required format.
 With tough constraints on execution time, it is crucial
that you use faster algorithms to avoid TLE(s) on
your test cases.
 This requires a good knowledge of time complexities.
For example:
 Say you want to write a function to
calculate x^4.
We can simply solve this with:
z=x*x*x*x;
return z; //required 3 multiplication instructions.
but a better solution will be:
z=x*x;
z=z*z;
return z; //required 2 multiplication instructions.
Contd…
 In the previous example, one instruction did not seem to make a
difference.
 But if you had to solve the problem for a few million test cases
(not uncommon in competitive coding), then you saved yourself
from a few million instructions and thereby reduced your
execution time correspondingly.
 Using such clever techniques is just a small part of competitive
programming 
 Thus devising new and better algorithms is crucial for
competitive programming.
Understanding the input format
 Input on OJ’s is very straightforward. You don’t need
to prompt for it like we usually do.
 The first line of input is usually the number of test
cases, followed by the test cases.
For example:
 If the input format states something like: “The first line
of input gives the no. of test cases with each test
case having 2 numbers n and m.”, then it would look
something like this:
3
2 5
6 8
3 9
And its code in C would be:
int a,b,c;
scanf("%d",&a);
while(a>0)
{
a--;
scanf("%d %d",&b,&c);
}
Getting started with competitive
coding:
Solving the problems in a coding contest is not easy.
Many online judges have problems of similar difficulty
and similar environment. A list of such judges are:-
TopCoder
SPOJ
Codechef
HackerEarth
HackerRank
Codeforces
And many more…
A few tips to perform better:
 Have a thorough grasp on the basic
concepts first.
 Develop a good understanding of data
structures like lists, trees and graphs.
 Try to learn as many new and efficient
algorithms and implement them when
required.
Some prestigious contests:
 ACM – ICPC
 Google Code Jam
 Topcoder Open
 Facebook Hacker Cup (Recent)
Students who perform well in these contests are
some of the finest brains in the world and
instantly recognized by top institutions
(companies, academia).
What’s next?
 Sign up on any of the plethora of online judges and
start solving their practice problems.
 You will run into a lot of errors in the beginning.
 Also, participate in other online contests arranged by
sites like codechef and SPOJ.
 Many companies use these contests to hire students
for jobs and internships as well.
Welcome to the world of Competitive
programming! 
Ad

More Related Content

What's hot (20)

Workshop on programming contest
Workshop on programming contestWorkshop on programming contest
Workshop on programming contest
Abir Khan
 
Competitive programming
Competitive  programmingCompetitive  programming
Competitive programming
Himanshu Agrawal
 
Session 3 : Competitive programming 1
Session 3 : Competitive programming 1Session 3 : Competitive programming 1
Session 3 : Competitive programming 1
Koderunners
 
Introduction to Competitive programming
Introduction to Competitive programmingIntroduction to Competitive programming
Introduction to Competitive programming
Ayoub Eddakhly
 
Competitive Programming Guide
Competitive Programming GuideCompetitive Programming Guide
Competitive Programming Guide
Ajay Khatri
 
Competitive Programming
Competitive ProgrammingCompetitive Programming
Competitive Programming
Ritesh Reddy
 
Basic Problems and Solving Algorithms
Basic Problems and Solving AlgorithmsBasic Problems and Solving Algorithms
Basic Problems and Solving Algorithms
Nopadon Juneam
 
1 introduction to problem solving and programming
1 introduction to problem solving and programming1 introduction to problem solving and programming
1 introduction to problem solving and programming
Rheigh Henley Calderon
 
INTRODUCTION TO ALGORITHMS Third Edition
INTRODUCTION TO ALGORITHMS Third EditionINTRODUCTION TO ALGORITHMS Third Edition
INTRODUCTION TO ALGORITHMS Third Edition
PHI Learning Pvt. Ltd.
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
Dr Geetha Mohan
 
Road map to competitive programming
Road map to competitive programmingRoad map to competitive programming
Road map to competitive programming
Tutort Academy
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
2210 s15 qp_ms_er_12
2210 s15 qp_ms_er_122210 s15 qp_ms_er_12
2210 s15 qp_ms_er_12
Tabsheer Hasan
 
Brute force-algorithm
Brute force-algorithmBrute force-algorithm
Brute force-algorithm
9854098540
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
Bulbul Agrawal
 
Symbolic Mathematics
Symbolic Mathematics Symbolic Mathematics
Symbolic Mathematics
saadurrehman35
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O Notation
Jawad Khan
 
Unit 1 Webtechnology
Unit 1  WebtechnologyUnit 1  Webtechnology
Unit 1 Webtechnology
Abhishek Kesharwani
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
Tarun Sharma
 
Workshop on programming contest
Workshop on programming contestWorkshop on programming contest
Workshop on programming contest
Abir Khan
 
Session 3 : Competitive programming 1
Session 3 : Competitive programming 1Session 3 : Competitive programming 1
Session 3 : Competitive programming 1
Koderunners
 
Introduction to Competitive programming
Introduction to Competitive programmingIntroduction to Competitive programming
Introduction to Competitive programming
Ayoub Eddakhly
 
Competitive Programming Guide
Competitive Programming GuideCompetitive Programming Guide
Competitive Programming Guide
Ajay Khatri
 
Competitive Programming
Competitive ProgrammingCompetitive Programming
Competitive Programming
Ritesh Reddy
 
Basic Problems and Solving Algorithms
Basic Problems and Solving AlgorithmsBasic Problems and Solving Algorithms
Basic Problems and Solving Algorithms
Nopadon Juneam
 
1 introduction to problem solving and programming
1 introduction to problem solving and programming1 introduction to problem solving and programming
1 introduction to problem solving and programming
Rheigh Henley Calderon
 
INTRODUCTION TO ALGORITHMS Third Edition
INTRODUCTION TO ALGORITHMS Third EditionINTRODUCTION TO ALGORITHMS Third Edition
INTRODUCTION TO ALGORITHMS Third Edition
PHI Learning Pvt. Ltd.
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
Dr Geetha Mohan
 
Road map to competitive programming
Road map to competitive programmingRoad map to competitive programming
Road map to competitive programming
Tutort Academy
 
Brute force-algorithm
Brute force-algorithmBrute force-algorithm
Brute force-algorithm
9854098540
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
Bulbul Agrawal
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O Notation
Jawad Khan
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
Tarun Sharma
 

Similar to An introduction to Competitive Programming (20)

ADA_Module 1_MN.pptx- Analysis and design of Algorithms
ADA_Module 1_MN.pptx- Analysis and design of AlgorithmsADA_Module 1_MN.pptx- Analysis and design of Algorithms
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
madhu614742
 
chapter 1
chapter 1chapter 1
chapter 1
yatheesha
 
Jeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testingJeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy
 
1. Solving a Problem With a Computer.pptx
1. Solving a Problem With a Computer.pptx1. Solving a Problem With a Computer.pptx
1. Solving a Problem With a Computer.pptx
SharjeelFaisal4
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
Rohit Shrivastava
 
Why computer programming
Why computer programmingWhy computer programming
Why computer programming
TUOS-Sam
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
SourabhPal46
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
Mard Geer
 
midterm_fa07.pdf
midterm_fa07.pdfmidterm_fa07.pdf
midterm_fa07.pdf
RavinderKSingla
 
AA Lecture 01 of my lecture os ghhhggh.ppt
AA Lecture 01 of my lecture os ghhhggh.pptAA Lecture 01 of my lecture os ghhhggh.ppt
AA Lecture 01 of my lecture os ghhhggh.ppt
maryamzahra3366
 
How to complement TDD with static analysis
How to complement TDD with static analysisHow to complement TDD with static analysis
How to complement TDD with static analysis
PVS-Studio
 
01SoftwEng.pptInnovation technology pptInnovation technology ppt
01SoftwEng.pptInnovation technology pptInnovation technology ppt01SoftwEng.pptInnovation technology pptInnovation technology ppt
01SoftwEng.pptInnovation technology pptInnovation technology ppt
sultanahimed3
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challenges
Dhanu Srikar
 
251 - Alogarithms Lects.pdf
251 - Alogarithms Lects.pdf251 - Alogarithms Lects.pdf
251 - Alogarithms Lects.pdf
Abdulkadir Jibril
 
8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving
Khan Yousafzai
 
Chapter one
Chapter oneChapter one
Chapter one
mihiretu kassaye
 
ALGO.ppt
ALGO.pptALGO.ppt
ALGO.ppt
PidoonEsm
 
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
Sheba41
 
Google Interview Questions By Scholarhat
Google Interview Questions By ScholarhatGoogle Interview Questions By Scholarhat
Google Interview Questions By Scholarhat
Scholarhat
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
pasinduneshan
 
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
ADA_Module 1_MN.pptx- Analysis and design of AlgorithmsADA_Module 1_MN.pptx- Analysis and design of Algorithms
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
madhu614742
 
Jeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testingJeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy
 
1. Solving a Problem With a Computer.pptx
1. Solving a Problem With a Computer.pptx1. Solving a Problem With a Computer.pptx
1. Solving a Problem With a Computer.pptx
SharjeelFaisal4
 
Why computer programming
Why computer programmingWhy computer programming
Why computer programming
TUOS-Sam
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
SourabhPal46
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
Mard Geer
 
AA Lecture 01 of my lecture os ghhhggh.ppt
AA Lecture 01 of my lecture os ghhhggh.pptAA Lecture 01 of my lecture os ghhhggh.ppt
AA Lecture 01 of my lecture os ghhhggh.ppt
maryamzahra3366
 
How to complement TDD with static analysis
How to complement TDD with static analysisHow to complement TDD with static analysis
How to complement TDD with static analysis
PVS-Studio
 
01SoftwEng.pptInnovation technology pptInnovation technology ppt
01SoftwEng.pptInnovation technology pptInnovation technology ppt01SoftwEng.pptInnovation technology pptInnovation technology ppt
01SoftwEng.pptInnovation technology pptInnovation technology ppt
sultanahimed3
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challenges
Dhanu Srikar
 
8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving
Khan Yousafzai
 
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
Sheba41
 
Google Interview Questions By Scholarhat
Google Interview Questions By ScholarhatGoogle Interview Questions By Scholarhat
Google Interview Questions By Scholarhat
Scholarhat
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
pasinduneshan
 
Ad

Recently uploaded (20)

Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Ad

An introduction to Competitive Programming

  • 1. Competitve Programming Analyzing and Solving problems By Gaurav Agarwal
  • 2. What is it?  Writing programs to solve problems in a contest environment.  One has a limited time to solve the problems. Ranging from a few hours to a few days.  The solution should be efficient in terms of execution time, memory used or in some cases even the length of code.
  • 3. What’s new?  The code will be executed on an Online Judge (OJ).  Which means you should write code which conforms to the specific format of input and gives the output in the required format.  With tough constraints on execution time, it is crucial that you use faster algorithms to avoid TLE(s) on your test cases.  This requires a good knowledge of time complexities.
  • 4. For example:  Say you want to write a function to calculate x^4. We can simply solve this with: z=x*x*x*x; return z; //required 3 multiplication instructions. but a better solution will be: z=x*x; z=z*z; return z; //required 2 multiplication instructions.
  • 5. Contd…  In the previous example, one instruction did not seem to make a difference.  But if you had to solve the problem for a few million test cases (not uncommon in competitive coding), then you saved yourself from a few million instructions and thereby reduced your execution time correspondingly.  Using such clever techniques is just a small part of competitive programming   Thus devising new and better algorithms is crucial for competitive programming.
  • 6. Understanding the input format  Input on OJ’s is very straightforward. You don’t need to prompt for it like we usually do.  The first line of input is usually the number of test cases, followed by the test cases.
  • 7. For example:  If the input format states something like: “The first line of input gives the no. of test cases with each test case having 2 numbers n and m.”, then it would look something like this: 3 2 5 6 8 3 9
  • 8. And its code in C would be: int a,b,c; scanf("%d",&a); while(a>0) { a--; scanf("%d %d",&b,&c); }
  • 9. Getting started with competitive coding: Solving the problems in a coding contest is not easy. Many online judges have problems of similar difficulty and similar environment. A list of such judges are:- TopCoder SPOJ Codechef HackerEarth HackerRank Codeforces And many more…
  • 10. A few tips to perform better:  Have a thorough grasp on the basic concepts first.  Develop a good understanding of data structures like lists, trees and graphs.  Try to learn as many new and efficient algorithms and implement them when required.
  • 11. Some prestigious contests:  ACM – ICPC  Google Code Jam  Topcoder Open  Facebook Hacker Cup (Recent) Students who perform well in these contests are some of the finest brains in the world and instantly recognized by top institutions (companies, academia).
  • 12. What’s next?  Sign up on any of the plethora of online judges and start solving their practice problems.  You will run into a lot of errors in the beginning.  Also, participate in other online contests arranged by sites like codechef and SPOJ.  Many companies use these contests to hire students for jobs and internships as well. Welcome to the world of Competitive programming! 