TCO17: Analysis of Algorithm Semifinals, Pt. 2

October 27, 2017 guestblogger

Today it turned out that I am not the only Topcoder marathoner who is also a runner. It is tomerun who runs marathons and ultramarathons in real life in addition to Topcoder marathon-style programming competitions. We sit together with him and brainstormed the 250-point problem from yesterday algo Semifinal 2.

The task, available for practice in the arena, is to create a Skolem sequence-like binary tree. That is, you need to connect nodes with numbers from 1 to k, into a binary tree. Each number appears twice in the final tree. Additional requirement is that a distance between 2 nodes with the same number x in them, should be equal to that number x.

This task is even more constructive than the 250-pointer from Semifinal 1. I advise you to try to play with pen and paper before proceeding with the reading.

Spoiler. Did you really take your pen and pencil and tried to solve this task?

First of all, it is clear that we must place 1-1 edge somewhere, along with its nodes. Let us do it in the very beginning. Then we may draw all external edges going to/from these 1’s we have just placed:

Now we may place 2s:

Now the key idea is to forget about 3s and instead place all the even numbers remaining there.

Now we can put the odd numbers in a form of clamp around one of the 2s and 4. That’s it. Or wait, we did not cover the case when there are just 3 numbers. Hopefully it is provided as an example, so we can just hardcode it.

Thanks for reading, and good luck to algo finalists!

Anatolijs Gorbunovs, gorbunov, is a software programmer from Latvia. During his school years, he was an amateur athlete with several Latvian Youth/Junior champion titles in long distance running. He graduated from University of Latvia and his hobbies include music, running, and programming competitions.

The post TCO17: Analysis of Algorithm Semifinals, Pt. 2 appeared first on .

Previous Article
Get Spooked with These 10 Haunting Tech Trends
Get Spooked with These 10 Haunting Tech Trends

#1: Self-driving cars Smart? Sure. Spooky? Absolutely. #2: Robots Remember that time this real-life robot t...

Next Article
The TCO17 Champion Who Almost Wasn’t!
The TCO17 Champion Who Almost Wasn’t!

When you want something, the whole universe conspires to make it happen! Monday (23rd October, 2017) would ...