Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

39 Job evaluation methods.

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago