Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please do it for complexity O(M(k)) Consider a set of n boxes with their positions numbered from 1 to n. Initially all the boxes are
Please do it for complexity O(M(k))
Consider a set of n boxes with their positions numbered from 1 to n. Initially all the boxes are CLOSED. These n boxes are subject to modifications over n iterations as follows. At the ith iterations the boxes at the positions whose ids are multiples of i are flipped, i.e. changed from CLOSED to OPEN or vice-versa. For example, at iteration 1, boxes at all positions are flipped, at iteration 2, boxes at positions 2,4,6,etc. are flipped, at iteration 3, boxes at positions 3,6,9, etc. are flipped. Propose an algorithm for find out, that after n such iterations how many boxes will be OPEN. Note that the answer requires only how many boxes, not their positions. Describe the rationale for the algorithm, give the pseudocode, and its complexity. Grading scheme: (your grade will be based on whichever class your algorithm falls in) For algorithms with complexity O(n) or higher (10 pts) . For algorithms with complexity (kn), where k is the number of digits of n (15 pts) For algorithms with complexity O(M(k)), where k is the number of digits of n, and M(k) is the complexity of multiplying two k digit numbers (20 pts)
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