Question

Consider The problem of determining whether an arbitrary sequence [x1,x2,...,xn] of n numbers contains repeated occurrences...

Consider The problem of determining whether an arbitrary sequence [x1,x2,...,xn] of n numbers contains repeated occurrences of some number. Show that this can be done in O(nlogn) time.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Yes, this can be done in O(nlogn) time.

lets see

first those n numbers using merge sort (which will take O(nlogn) time )

then traverse the sorted sequence using for loop, and compare adjacent elements (takes O(n) time)

if any two adjacent elements are equal, means we have found a repeated occurrence

if we don't find then there are no repeated occurrences

total complexity : n+nlogn = O(nlogn)

Add a comment
Know the answer?
Add Answer to:
Consider The problem of determining whether an arbitrary sequence [x1,x2,...,xn] of n numbers contains repeated occurrences...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT