12 Days of Xmas

Assignment 1
Note: you will demo your xmas project in class.

Objective: Understanding of efficient algorithmic thinking and analysis.

Assignments from Book: Do the following problems from the Cormen book:

1 sec1 min1 hour1 day1 month1 year1 century
lgn

n

n
n lgn
n2
n3
2n
n!

Program Description: In this assignment, you will create a program to calculate the total number of gifts received on the nth day of xmas - a cumulative total - according to the song "The Twelve Days of Xmas":

  1. Partridge in a pear tree

  2. Turtle doves

  3. French hens

  4. Calling birds

  5. Golden rings

  6. Geese a-laying

  7. Swans a-swimming

  8. Maids a-milking

  9. Pipers playing

  10. Drummers drumming

  11. Ladies dancing

  12. Twelve lords a-leaping

So, on the first day of xmas, you receive only 1 gift - the partridge.  On the second day, however, you receive 3 gifts (2 turtle doves and a partridge), creating a total on the second day of 4.  Your job is to calculate the total number on day n.  This day can be well beyond 12 - so you can't hardcode that day 1 is 1, day 2 is 4, etc...  Note: you should not print out the song, just the total.

In addition to writing this program, you will analyze the efficiency of your program in terms of  either Θ, ΟΩ, explaining why you believe your program runs within the bounds you claim.  Can this problem be solved in Ο (nn), Ο (n2), Ο (n lg2n), Ο (n), or even Ο (1)?  How many presents would you have if this continued all year?

Program Requirements: The program should prompt the user for the day to calculate, and then produce the total number of gifts since day 1.

Example: xmas.exe

Extra Credit:  10 pts extra credit to the person who comes up with the most efficient algorithm!

Program Turnin: Use WebSubmit to submit your written assignment.  You will show your code demo your program in front of the class, explaining your answer.