HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > CEN303 2013-15 Questions > problem:


15MdE-20. 50803 - Sum of the depths in BST

CEN303 2013-15 Questions

Start: Dec.15.2013 at 02:00:00 PM
Finish: Dec.15.2013 at 07:00:00 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (1)

Contest problems

• 15FE-04. 50997 - Dynamic Knights
• 15HW-10. 50826 - Olive Containers
• 15HW-30. 50828 - Arranging Time ...
• 15HW-40. 50676 - Cinema Millennium
• 15HW-40. 50829 - Decode an Image
• 15HW-50. 50830 - Sorting BST Nodes
• 15HW-60. 50678 - The Jumping Rabbit
• 15MdE-10. 50802 - Comparing Exams
• 15MdE-20. 50803 - Sum of the ...
• 15MdE-40. 50805 - Sum of the weig...
• 15PrE-10. 50816 - Largest Sum Path
• 15PrE-20. 50817 - The Knight Move
• 15PrE-30. 50818 - Depth Limited BST
• 15PrE-40. 50819 - Linked Numbers
• 15PrE2-01. 50847 - The first m train...
• 15PrE2-06. 50837 - Sum is equal to K
• 15Rst-10. 50857 - Nine-Stones Game

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
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