Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A student in COL100 has n topics to study, numbered from 1 to n. He decided to study one topic a day and has designed
A student in COL100 has n topics to study, numbered from 1 to n. He decided to study one topic a day and has designed a schedule : N N (function that takes input day no. and outputs the topic to study on that day). For eg. on day K, he will study topic numbered schedule(K). He will study these n topics in n days. A topic(say k) is said to be well studied if he has studied all the topics numbered from 1 to k. For example, if n = 5 and the schedule is given as schedule(1) = 2, schedule(2) = 1, schedule(2) = 1, schedule(3) = 3, schedule(4) = 5, schedule(5) = 4 i.e. on day 1 he will study topic 2 and on day 2 he will study topic 1 and so on. Day Studied topics Well studied topics 1 2 2 3 1, 2 1, 2, 3 1, 2, 3, 5 1, 2, 3, 4, 5 None 1, 2 1, 2, 3 1, 2, 3 1, 2, 3, 4, 5 4 5 Then on day 2, 3, 5 all the studied topics are well studied. Write a function in mathematical notation or an SML function which takes input schedule, n and returns the number of days when all the studied topics are well studied (e.g. 3 in the above example). Also explain your algorithm in words. For full marks, your algorithm should take O(n) time. [5 marks] A student in COL100 has n topics to study, numbered from 1 to n. He decided to study one topic a day and has designed a schedule : N N (function that takes input day no. and outputs the topic to study on that day). For eg. on day K, he will study topic numbered schedule(K). He will study these n topics in n days. A topic(say k) is said to be well studied if he has studied all the topics numbered from 1 to k. For example, if n = 5 and the schedule is given as schedule(1) = 2, schedule(2) = 1, schedule(2) = 1, schedule(3) = 3, schedule(4) = 5, schedule(5) = 4 i.e. on day 1 he will study topic 2 and on day 2 he will study topic 1 and so on. Day Studied topics Well studied topics 1 2 2 3 1, 2 1, 2, 3 1, 2, 3, 5 1, 2, 3, 4, 5 None 1, 2 1, 2, 3 1, 2, 3 1, 2, 3, 4, 5 4 5 Then on day 2, 3, 5 all the studied topics are well studied. Write a function in mathematical notation or an SML function which takes input schedule, n and returns the number of days when all the studied topics are well studied (e.g. 3 in the above example). Also explain your algorithm in words. For full marks, your algorithm should take O(n) time. [5 marks]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started