Question

Collaborative filtering is a technique for generating recommendations, such as suggestions for products, songs, movies, news...

Collaborative filtering is a technique for generating recommendations, such as suggestions for products, songs, movies, news stories, and so on. The idea is to identify other users who have similar preferences, and recommend to you things that have been popular with them. It requires a formal notion of “similarity” between users, and some of the essence of this is captured by the problem of counting the number of inversions in an array.

An inversion in an array A[1,...,n] is a pair of indices (i,j) such that i < j and A[i] > A[j]. For example, in the array A = [1,3,5,2,4,6], there are three inversions, 5 and 2 (corresponding to i = 3 and j = 4), 3 and the 2, and the 5 and the 4. For this problem we will count the number of inversions in an array of size n.

(a) Write pseudo-code for an efficient brute force algorithm to find the total number of inversions in the worst-case. Find the exact number of inversions. Show your work. (b) Write pseudo-code for an optimal algorithm to find the total number of inversions in the worst-case. What is the asymptotic runtime of your algorithm?

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

(a) Brute Force Method Inversion (int are []) 1 int contatos for (int i = 0; i < arr-length-l; i++) { for (int j zitl ; jcare(b) Optimal algorithm merge Sort and Inie (int [] are, int I, int r) int count = 0; if (lar) int me (l+2)/2 count count & mersubarray // Fill from the rest of the left while (ic left length) are [k++] = left [it+] Il Fill from the rest of the right s

Add a comment
Know the answer?
Add Answer to:
Collaborative filtering is a technique for generating recommendations, such as suggestions for products, songs, movies, news...
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