competitive programming cs 104c · benefits of competitive programming improved problem solving...
TRANSCRIPT
![Page 1: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/1.jpg)
Competitive Programming
CS 104C
![Page 2: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/2.jpg)
IntroductionsI am Prof. Etienne Vouga• [email protected]• GDC 5.508
Coach of the ICPC teams
Office hours by appointment
![Page 3: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/3.jpg)
Fellow Lecturers
Arnav Sastry and Ethan Arnold
![Page 4: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/4.jpg)
Other Affiliated Faculty
Glenn Downing
Shyamal Mitra
![Page 5: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/5.jpg)
What is Competitive Programming?
![Page 6: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/6.jpg)
Example ProblemInput: An integer N• 0 <= N <= 106
Output: The number of zeroes at the end of N!
Time limit: 1 secMemory limit: 10 MB
![Page 7: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/7.jpg)
What is Competitive Programming?
Given a concrete problem statement:1. Analyzing the problem and determining what
algorithm can solve it;2. Identifying the possible pitfalls and corner
cases;3. Quickly producing an implementation that
“Just Works the first time”
In other words, efficiently analyzing and solving low-level programming problems
![Page 8: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/8.jpg)
High-Level Design Low-Level Design
Unit of Concern Application; Library Function
Main Goals User ExperienceMaintainability
CorrectnessPerformance
Key QuestionsWhat libraries can I use?Will these features be useful?Will this design scale to more users/data?
What algorithm can I use?What are the corner cases?Will this run in reasonable time and memory?
Skills Needed PlanningCommunication
Problem-solvingAlgorithms knowledge
Scope of Effort Teams working for months
One programmer working for hours
![Page 9: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/9.jpg)
Benefits of Competitive Programming
Improved problem solving skillsImproved knowledge of algorithms
Write more optimized codeWrite less buggy code
Great practice for technical interviewsHave fun, win prizes and glory
![Page 10: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/10.jpg)
Mechanics of a Competition
You receive several (3-10) problems of varying difficulty
Write solution, submit it to an automated judge that runs test suite
![Page 11: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/11.jpg)
Mechanics of a CompetitionYou receive several (3-10) problems of
varying difficultyWrite solution, submit it to an automated
judge that runs test suiteGet back ~2 bits of information:Accepted, Wrong Answer, (Compile Error), (Time
Exceeded), (Memory Exceeded)You are not told the failure cases!
![Page 12: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/12.jpg)
Two Types: Online and Offline
Online: (TopCoder, CodeForces, Google CodeJam)
• Individual• Can use Internet, your old code, …Offline: (ICPC)• Team (shares one computer)• No Internet
![Page 13: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/13.jpg)
Competitions vs Industry
In competitions:• Severe time pressure• no time for unit tests• no time to write documentation
• Style and code quality doesn’t matter*• Maintainability doesn’t matter• Problems are self-contained
![Page 14: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/14.jpg)
Example Problem IIInput: A sorted list of N integers xi and an integer y• 1 <= N <= 106
• -230 <= y, xi <= 230
Output: The number of elements in the list strictly less than y Time limit: 1 secMemory limit: 10 MB
![Page 15: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/15.jpg)
Efficiency Rule of Thumbcomplexity maximum N
(N) 1000000
(N log N) 500000
(N^2) 5000
(N^3) 400
(N^4) 80
(2^N) 20
(N!) 10
![Page 16: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/16.jpg)
Lessons?Read the problem statement• Look at the limits• Check for corner cases
Almost always a performance vs complexity tradeoff – choose carefully!
Big-O critical (but don’t sweat log N)
![Page 17: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/17.jpg)
Other Tips for Getting StartedBecome proficient in one language, and know
its libraries and I/O functions cold• C++, Java, Python
Get out there and code• try out online contests: codeforces,
codechef, projecteuler, hackerrank• you greatly improve by practicing
![Page 18: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/18.jpg)
Assignment and Grading500 points total400 points (80%) homework exercises (3/week):• Vanilla Problem: tests key concepts• Codeforces Exercises• online judge• we pick three problems, you choose one• can do more for extra credit (5 pts per problem)
• Find the Bug• our solution has an issue;
find the problem
![Page 19: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/19.jpg)
Assignment and Grading
400 pts homework exercises (3/week)100 pts programming contest participation• every two weeks on Friday night• first contest: September 8thOne contest (your choice) is requiredCan do more for extra credit
(10 per problem per contest)
![Page 20: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/20.jpg)
Prerequisites
Data Structures (or equivalent)
Working knowledge of Java (for Find the Bug problems)
Strong working knowledge of one of:• C/C++, Java, Python
![Page 21: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/21.jpg)
Academic Dishonesty
Do look up:• Language reference• High level algorithmic conceptsDon’t look up:• Problem solutions / editorials
• We’ve caught people in the past.
![Page 22: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/22.jpg)
Tentative List of Topics● state space search / graph algorithms● recursion / backtracking● binary search● greedy algorithms● dynamic programming● advanced graph algorithms● number theory● probability/combinatorics● advanced data structures
![Page 23: Competitive Programming CS 104C · Benefits of Competitive Programming Improved problem solving skills Improved knowledge of algorithms Write more optimized code Write less buggy](https://reader031.vdocuments.us/reader031/viewer/2022040112/5e6d05fc8c2fb32bad23c0f7/html5/thumbnails/23.jpg)
Coming Soon on Canvas
Links to online competitionsInstructions for setting up Codeforces
account (needed for assignments)First problem (due Wed. at midnight)