Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 2: Christmas lights15 Consider that you have a set of N Christmas lights, which can turn red or green. The lights are numbered from

Task 2: Christmas lights15

image text in transcribedConsider that you have a set of N Christmas lights, which can turn red or green. The lights are numbered from 1 to N. Initially at time step 1 they are all red. The mechanism is set such that at time t, all lights whose id is divisible by t will change color (i.e. red to green, or green to red).For example, given 6 lights, numbered 1,2,3,4,5,6at time step 1R R R R R Rat time step 2R GR GR Gat time step 3 R G GG R RHow many lights will be red at the end of N time steps ?Give a pseudocode of your algorithm and its complexity.If the algorithm complexity is O(n2) then you get 5 pointsIf the algorithm complexity is O(n) then you get 10 pointsIf the algorithm complexity is less than O(n) then you get 15 points

Task 2: Christmas Lights15 Consider that you have a set of N Christmas lights, which can turn red or green. The lights are numbered from 1 to N. Initially at time step 1 they are all red. The mechanism is set such that at time t, all lights whose id is divisible by t will change color (i.e. red to green, or green to red). For example, given 6 lights, numbered 1,2,3,4,5,6 at time step 1 RRRRRR at time step 2>RGRGRG at time step 3 RGGGRR How many lights will be red at the end of N time steps ? Give a pseudocode of your algorithm and its complexity. If the algorithm complexity is O(n) then you get 5 points If the algorithm complexity is O(n) then you get 10 points If the algorithm complexity is less than O(n) then you get 15 points

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

Students also viewed these Databases questions