Question
A certain program has to maintain an array, count, of N counters which are all initialised to zero. The value of counter i can be
A certain program has to maintain an array, count, of N counters which are all initialised to zero. The value of counter i can be incremented by one by the call: increment(i), and this is the only way the program changes counter values. Two variables, mincount and maxcount, must always hold the smallest and largest of the counter values whenever the point of execution is not within the function increment. You may assume that increment is called about 1000N times when the program is run and that its argument is typically uniformly randomly distributed between 1 and N, but on some runs it cycles through the numbers 1 to N in order 1000 times. (a) Describe, in detail, an efficient data structure and algorithm to use when N is expected to be about 10. (b) Describe, in detail, an alternative data structure and algorithm to use when N is about a million. (c) Suppose your algorithm for (a) above were used when N = 106 , estimate how much slower it would be compared with your algorithm for (b).
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