Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Algorithm design. Each of n users spends some time on a social lklkmedia site. For each i = 1 , dots, n , user i

Algorithm design. Each of n users spends some time on a social lklkmedia site. For each
i=1,dots,n, user i enters the site at time ai and leaves at time biai. You are interested
in the question: how many distinct pairs of users are ever on the site at the same time?
(Here, the pair (i,j) is the same as the pair (j,i)).
Example: Suppose there are 5 users with the following entering and leaving times:
Then, the number of distinct pairs of users who are on the site at the same time is three:
these pairs are (1,2),(4,5),(3,5).(Drawing the intervals on a number line may make
this easier to see).
(a)(10 points) Given input (a1,b1),(a2,b2),dots,(an,bn) as above in no particular order
(i.e., not sorted in any way), describe a straightforward algorithm that takes (n2)-
time to compute the number of pairs of users who are ever on the site at the same
time, and explain why it takes (n2)-time. [We are expecting pseudocode and
a brief justification for its runtime.]
Answer:
(b)(10 points) Give an (nlog(n))-time algorithm to do the same task and analyze its
running time. (Hint: consider sorting relevant events by time).[We are expecting
pseudocode and a brief justification for its runtime.]
Answer:
image text in transcribed

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 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

Students also viewed these Databases questions