Difference between revisions of "Programming Practice"

From Computer Science
Jump to: navigation, search
(Sites with Problems)
(Sites with Problems)
Line 2: Line 2:
= Sites with Problems =  
= Sites with Problems =  
'''[https://hackerrank.com Hackerrank]'''
'''[https://open.Kattis.com Open Kattis'''
= Why Your Program is Wrong =
= Why Your Program is Wrong =

Revision as of 16:34, 8 February 2021

This page is meant to get you started working on programming problems that are similar to ones you will see in programming contests and job interviews.

Sites with Problems


[https://open.Kattis.com Open Kattis

Why Your Program is Wrong

Automatically Checked

Programming contests are normally checked by scripts that run your program and check whether your input is exactly the same as the model solution. If the correct output is "Hello World!", your program would be incorrect if it output "Hello World." or "hello world!". If the problem asks for an integer then make sure to output an integer (not a floating point number). So you need to pay careful attention to what the problem asks for in terms of output.

Run time

Some contest problems are fairly easy to solve with an inefficient program, but the real work is figuring out how to make your program faster. Oftentimes, your program needs to finish in around 1-5 seconds to be fast enough. For a C program, a single loop that goes through around 100 million iterations might be okay. For a Python program, a single loop that goes through 1 million iterations might be okay. If you have nested looped, you should count how many times the innermost part runs - two nested loops that each go 1 to 1000 will end up running the innermost code 1 million times.

Algorithm Techniques

The following are some of the most common algorithms/techniques that you will see with these problems.

  1. Simulation - the problem gives rules to be used to run a simulation, and you need to run the simulation until a certain point and output the result.
  1. Brute force
  1. Dynamic programming
  1. Graph problems
  1. Greedy
  1. Sorting
  1. Math tricks