ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Data Structures > задача:


50803 - Sum of the depths in BST

Гость
• Вопросы к жюри (1)

Задачи сборника

• 50411 - Sum of the Leaves
• 50677 - The Cottage
• 50795 - Trunk
• 50414 - Traffic
• 50698 - Ayran Delivery
• 50978 - Albanian Coders
• 50699 - Fighting Vampires
• 50830 - Sorting BST Nodes
• 50803 - Sum of the depths in BST
• 50805 - Sum of the weights in a BST
• 50712 - Moon algebra
• 50675 - Kruja Boys
• 50415 - The Scientist
• 50679 - Jetpack Hurdle Jumping
• 50717 - Hurdle Jumping
• 50421 - Repairing road segments
• 50431 - Sultan's Game

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Question by Sidrit Reka.

Sum of the depths of all odd numbers in a BST

The depth of a node in a tree, is the number of steps to reach to the node from the root. The depth of the root node is assumed to be zero.

Question: You will be given a series of numbers to be inserted into an initially empty Binary Search Tree (BST). Calculate the sum of the depths of all odd numbers found in the BST.

Input specification
You will be first given a number (n) the number of nodes to be inserted in the BST where 1 <= n <= 10000. Then you will be given n space separated numbers (nums[n]) where each of the number in the series is 1 <= nums[i] <= 10000.

Output specification
Calculate and show the sum of the depths of all odd numbers found in the BST.

Sample Input I
7
4 7 3 2 7 6 3
Sample Output I
2

  1. The depth of 4 is 0,
  2. The depth of 3 is 1,
  3. The depth of 7 is 1,
  4. The depth of 2 is 2,
  5. The depth of 6 is 2.
We have 2 odd numbers in our BST (3, 7). We add their depths (1 + 1 = 2).

Sample Input II
12
6 8 2 4 1 2 7 9 4 3 6 5
Sample Output II
12

  1. The depth of 6 is 0,
  2. The depth of 2 is 1,
  3. The depth of 8 is 1,
  4. The depth of 1 is 2,
  5. The depth of 4 is 2,
  6. The depth of 7 is 2,
  7. The depth of 9 is 2,
  8. The depth of 3 is 3,
  9. The depth of 5 is 3.
We have 5 odd numbers in our BST (1, 3, 5, 7, 9). We add their depths (2 + 3 + 3 + 2 + 2 = 12).



Для отправки решений необходимо выполнить вход.

www.contester.ru