Design an algorithm for determining the day of the week of any date since Januar
ID: 3546889 • Letter: D
Question
Design an algorithm for determining the day of the week of any date since January 1, 1900. For example, November 15, 2013 is a Friday and January 1, 1900 is a Monday. Give the psuedocode (not python) for the algorithm and a brief description of why it works (it doesn't need to be as detailed as my argument for selection sort above). Remember that in pseudocode you don't need to explain every detail, for example you don't need to say how a day of the week is stored. You can just say things like "the weekday 3 days after Sunday".
Design an algorithm that, given a list of integers, finds the two smallest elements in the list without sorting the entire list. Give the pseudocode and a brief argument for why it works (it doesn't need to be as detailed as my argument above). Hint: the answer is similar to selection sort above, but of course does not sort the entire list.
Explanation / Answer
Answer 1 :
input: Day of the Date,
Month of the Date,
Year of the Date
Output : Weekday
century_offset = first two characters of Year - 19
year_offset = last two characters of year
month_offset = month - 1
date_offset = date
offset_sum = century_offset + year_offset + month_offset +date_offset
numeric_value for Weekday = offset_sum%7
if numeric_value = 1 then weekday = Monday
else if numeric_value = 2 then weekday = Tuesday
else if numeric_value = 3 then weekday = Wednesday
else if numeric_value = 4 then weekday = thursday
else if numeric_value = 5 then weekday = friday
else if numeric_value = 6 then weekday = saturday
else if numeric_value = 0 then weekday = sunday
return weekday
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.