Red-Green-Code

Deliberate practice techniques for software developers

  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter

Why is Java I/O Slow?

By Duncan Smith Leave a Comment May 20 6

Tortoises

You can read a lot on Quora about the best language to use for competitive programming. Here are some of the points covered by those questions:

  • C and C++ execute quickly, and their macro support can reduce the amount of code that you end up typing in your solution.
  • A language like Java can be useful for problems with some specific requirements (such as integers that don’t fit in 64 bits, or calendar problems).
  • The main contributor to execution speed is the algorithm that you use, not the language that you choose to implement it. But the language can provide a performance edge at the margins.
  • Choice of language is less important for more recent contests, since problem setters have made an effort to level the playing field (e.g., by testing Java solutions to ensure that the time limit is sufficient).

I decided to use Java for Project 462, mainly because it’s similar to my primary language (C#), and I’m more interested in learning about problem solving and algorithms than learning a new language that I’m unlikely to use much outside of competitive programming.

One thing about the uHunt problems that I’m working through is that they draw from a database of contest problems going back to the 1990s. Competitive programming and programming languages have changed a lot since then, so what the problem setters were going for in the original contest may not match up with how a contestant sees the problem today. Modern contests tend to be more forgiving of the slower execution time of languages that aren’t C or C++, and they know about the fancy libraries that programmers have access to.

Last week I wrote about Solving UVa 11340 in Java, and covered some performance tips related to reading files that are larger than those typically found in programming puzzles. It turns out that the very next starred problem, UVa 12356: Army Buddies, is an even stricter test of I/O performance. And for this one, there is no particular hint in the problem statement that I/O will be an issue.

Once I came up with an Accepted solution for UVa 12356 in Java, I decided to do some more benchmarking, and use the results to update my solution template. Figuring all of this out once is educational, but I’d rather not be fiddling with I/O issues for every problem that happens to have large input or output requirements.

« Continue »

Solving UVa 11340 in Java

By Duncan Smith Leave a Comment May 13 6

ISO-8859-1

UVa 11340: Newspaper, despite being ranked at only Level 2 difficulty on uHunt, turned out to be rather tricky. Apparently others thought so too, judging by the 11 pages (151+ posts) of discussion on the UVa OJ message board. Many of the message board posts focus on the characters used in the test input. The consensus is that they are 8-bit characters (with values from 0 to 255). At a minimum, these characters need to be stored in an unsigned char data type in C++. Nevertheless, people seemed to run into problems even after getting that hint. I solved the problem in Java, which doesn’t have an unsigned char data type, but it has its own set of difficulties. I’ll cover the two issues that I ran into when solving this problem.

« Continue »

The Long Game

By Duncan Smith Leave a Comment May 6 0

AnathemDoom

The theory of deliberate practice is a popular starting point for online article writers. I subscribed to an alert for the term, and I generally get a few results every day (of varying quality). Its popularity isn’t surprising. Deliberate practice offers a process that anyone can use to get better, assuming they are willing to follow it carefully and put in the required hours. Articles and books on the topic often provide examples of well-known experts who followed a deliberate practice process. Geoff Colvin’s Talent is Overrated mentions Tiger Woods pushing golf balls into the sand to make them harder to hit. James Clear writes about Kobe Bryant’s 800 jump shots before practice. But there are also examples of people who didn’t have coaches to steer them towards the right practice steps, but nevertheless achieved incredible results. I recently finished reading Masters of Doom, the story of the founders of id software. One of the recurring themes in the book is the incredible work ethic of John Carmack, co-founder, graphics engine developer, and all-around game programming legend.

« Continue »

Lessons from Competitive Programming 3, Chapter One

By Duncan Smith Leave a Comment Apr 29 4

CP3Chapter1

This post is part of a series of commentaries covering each chapter of Competitive Programming 3 by Steven and Felix Halim. You can find the rest of the posts in the series by visiting my CP3 post category.

Many of the problems in the UVa Online Judge are taken directly from past ACM-ICPC contest problems. If you’re preparing for this contest or the IOI (which targets a subset of ICPC content), it makes sense to be familiar with these problems. But even if you’re planning to compete on platforms like TopCoder and CodeForces, it can be useful to train using UVa OJ problems, despite the platform’s quirks. Competitive programming problems tend to cover similar topics regardless of the contest platform, especially when it comes to easy and medium problems. The difference is mainly about which topics are emphasized more.

Because UVa OJ has been around for a while, several books use its problems as exercises. One of these is Competitive Programming 3 (CP3), the companion book to the uHunt site. Last week I wrote about the Chapter 1 uHunt starred problems. This week I’m going to cover some highlights from the corresponding chapter in the CP3 book. I’m using the 3rd edition, but you can find similar (but older) content in the free 1st edition ebook.

« Continue »

Lessons from uHunt Chapter One

By Duncan Smith Leave a Comment Apr 22 0

uHuntChapter1

This post is part of a series that considers what can be learned from the problems in each chapter of uHunt, a tool for competitive programming practice. You can find the rest of the posts in the series by visiting my uHunt post category.

This week, I submitted the solution to the last of the 39 starred problems in uHunt Chapter 1. This is part of a learning project that I’m calling Project 462, after the 462 uHunt starred problems.

The problems in uHunt Chapter 1 are introductory and ad-hoc problems. They help uHunt users get familiar with the UVa Online Judge system, and they don’t require any specific competitive programming techniques to solve. Nevertheless, there were quite a few challenging problems in this chapter.

How to Attack a Programming Puzzle contains six tips for using UVa OJ. This post contains my remaining thoughts on solving the types of problems found in Chapter 1.

« Continue »

Productivity Habits

By Duncan Smith Leave a Comment Apr 15 0

Elephant

When you’re working on a serious learning project, especially if you’re applying deliberate practice techniques, it’s essential to have a set of core habits that you can rely on. Deliberate practice is intended to be a demanding process (see elements #4 and #5 from the linked post). This is good because it makes you push against your limits, but it can also make it difficult to maintain a schedule if you’re just using an ad-hoc process. Experimenting with habits and selecting a few that work for you makes it more likely that you’ll be able to continue working on your project for as long as it takes to complete it.

A productivity habit is something you do on a regular basis (often daily) to help you be more productive. Although the habit may have some value on its own, what’s more important is the effect it has on your work. For example, I find it useful to keep track of how long it takes to complete various tasks. Analyzing this data over time can uncover some interesting trends. But it’s even more powerful to use time tracking for setting time goals, like the number of hours per day that I commit to spending on a project.

Here are the habits that I have found to be the most useful as I work on Project 462.

« Continue »

What Are the Important Problems of Your Field?

By Duncan Smith Leave a Comment Apr 8 0

Science Fish

Do these questions sound familiar?

  • What are the important problems of your field?

  • What important problems are you working on?

  • If what you are doing is not important, and if you don’t think it is going to lead to something important, why are you … working on it?

They come from a 1986 speech by mathematician and Turing award winner Richard Hamming. Hamming originally asked them in the dining hall at Bell Labs, but they have since inspired other people who are interested in finding the best way to spend their work hours.

« Continue »

Building Mathematical Thinking Skills

By Duncan Smith Leave a Comment Apr 1 0

Pumpkin Pi

When people hear the term competitive programming, they naturally think about programming contests and rankings. People who are encountering the term for the first time are just using the literal meaning, while those who are familiar with the topic think about the top competitors that they hear a lot about. But someone who is just starting to learn to solve the types of problems found in programming competitions may see things differently. In my experience, introductory problems often challenge mathematical thinking skills more than programming skills. Only a small subset of a programming language is required to solve these problems, and there’s plenty of time to look up syntax (since beginners are often not taking part in a timed competition). However, most problems (other than the very easiest ones) are structured to require mathematical thinking.

« Continue »

The Missing Piece of the Computer Science Curriculum

By Duncan Smith Leave a Comment Mar 25 0

Allen Center

Despite the increasing availability of alternative options such as online learning sites and coding boot camps, many students who are interested in programming still pick the traditional approach: getting a Computer Science degree. If you plan to do academic research, a degree is really the only option. But for someone who wants to get a job as a programmer, there are both advantages and disadvantages to a traditional degree.

« Continue »

What You Can Learn from Easy Programming Puzzles

By Duncan Smith Leave a Comment Mar 18 0

Imagine Create Learn

When you start solving programming puzzles like those on uHunt Chapter 1, what are you learning about? The obvious answer is that you’re learning about competitive programming. After all, uHunt has a companion textbook called Competitive Programming, and many programming puzzle sites are associated with the competitive programming community, or even run their own contests. But I don’t think that’s the right way to look at it. First of all, there’s not much competition happening when you’re first getting started. You may be using a site where the only rating is the number of problems submitted. Or if you are participating in real-time contests, you may not be making it through many problems before time runs out.

« Continue »

  • « Previous Page
  • 1
  • …
  • 46
  • 47
  • 48
  • 49
  • Next Page »

Stay in the Know

I'm trying out the latest learning techniques on software development concepts, and writing about what works best. Sound interesting? Subscribe to my free newsletter to keep up to date. Learn More
Unsubscribing is easy, and I'll keep your email address private.

Getting Started

Are you new here? Check out my review posts for a tour of the archives:

  • 2023 in Review: 50 LeetCode Tips
  • 2022 in Review: Content Bots
  • 2021 in Review: Thoughts on Solving Programming Puzzles
  • Lessons from the 2020 LeetCode Monthly Challenges
  • 2019 in Review
  • Competitive Programming Frequently Asked Questions: 2018 In Review
  • What I Learned Working On Time Tortoise in 2017
  • 2016 in Review
  • 2015 in Review
  • 2015 Summer Review

Archives

Recent Posts

  • Do Coding Bots Mean the End of Coding Interviews? December 31, 2024
  • Another Project for 2024 May 8, 2024
  • Dynamic Programming Wrap-Up May 1, 2024
  • LeetCode 91: Decode Ways April 24, 2024
  • LeetCode 70: Climbing Stairs April 17, 2024
  • LeetCode 221: Maximal Square April 10, 2024
  • Using Dynamic Programming for Maximum Product Subarray April 3, 2024
  • LeetCode 62: Unique Paths March 27, 2024
  • LeetCode 416: Partition Equal Subset Sum March 20, 2024
  • LeetCode 1143: Longest Common Subsequence March 13, 2024
Red-Green-Code
  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter
Copyright © 2025 Duncan Smith