Question

In: Computer Science

Suppose you are developing part of a social media website. For the following, write down an...

Suppose you are developing part of a social media website.

For the following, write down an algorithm that you would use to accomplish each one of these tasks. Your choice of search algorithm should be selected to complete each task as efficiently as possible

1. A search algorithm to determine the post with the highest number of positive votes (e.g likes)
2. A search algorithm to find all the posts made by a user on a specific date.
3. A search algorithm to determine the first post made by a specific user AFTER a specific date.
4. A search algorithm to find all the posts made by a user between two dates.
5. A search algorithm to find all posts containing a specific pattern of text.

Solutions

Expert Solution

1. For searching a post with highest number of likes

Each post will be having an associated number of likes on that post so first we will start traversing the array/any data structure used to contain the number of likes of the post and have a maximum and compare the next post likes with the current max number of likes. This way space complexity will be O(n). Linear searching is used here.

algorithm:

int max=0,i,maxind=0

int[] likes // likes for each post saved sequentially on timestamp basis

for(i=0;i<likes.length;i++)

if(max<likes[i])

max=likes[i]

maxind=i // save the index to refer the post

else

//do nothing

return max

2. Assuming all the posts made by a user are stored in a sorted order on the basis of their timestamp in an array.

Binary search can be used here.

Algorithm:

dates[] // array of dates

binsearch( dates[] , n, sdate)

left=0,right=0,mid=0

while( left<right)

mid=(right+left)/2

if(dates[mid]==sdate)

while(mid+1<n && dates[mid+1] == key)

mid++

break;

else if (dates[mid]>key)

right=mid

else

left=mid+1

while)mid>-1 && dates[mid]>key)

mid--

return mid+1 // returning mid+1 because of 0 based indexing of array

3. Assuming all the posts made by a user are stored in a sorted order on the basis of their timestamp in an array.(most recent would be the right most element)

Binary search can be used here.It will be almost same as the previous one just the

Algorithm:

dates[] // array of dates

binsearch( dates[] , n, sdate)

left=0,right=0,mid=0

while( left<right)

mid=(right+left)/2

if(dates[mid]==sdate)

while(mid+1<n && dates[mid+1] == key)

mid++

break;

else if (dates[mid]>key)

right=mid

else

left=mid+1

while)mid>-1 && dates[mid]>key)

mid--

return mid+2 // returning mid+1 because of 0 based indexing of array and +1 for the immediate next post

4.   Assuming all the posts made by a user are stored in a sorted order on the basis of their timestamp in an array.(most recent would be the right most element)

ds--> start date de--> end date

Algorithm:

dates[] // array of dates

binsearch( dates[] , n, sdate)

left=0,right=0,mid=0

while( left<right)

mid=(right+left)/2

if(dates[mid]==sdate)

while(mid+1<n && dates[mid+1] == key)

mid++

break;

else if (dates[mid]>key)

right=mid

else

left=mid+1

while)mid>-1 && dates[mid]>key)

mid--

return mid+1 // returning mid+1 because of 0 based indexing of array

// ds is found then de can be found from ds to the end of the array dates using the same algorithm and return all the indexes from ds to de.


Related Solutions

Explain how you can use social media to test you website?
Explain how you can use social media to test you website?
Please in 300 to 400 words (write down references) How do you think social media apps...
Please in 300 to 400 words (write down references) How do you think social media apps affect people's interactive styles? Has the development of digital communication been good or bad for a social life? Why?
Choose one of the following brands. Go the company’s website and locate the social media links...
Choose one of the following brands. Go the company’s website and locate the social media links provided. Access each of the social media brand pages and evaluate them in terms of engaging consumers with the brand and how it is integrated with the website. Provide specific information from each social media network that shows how consumers can be engaged. Identify the number of fans, followers, and posts on each site. Provide screenshots of each social media page and website main...
According to a social media​ blog, time spent on a certain social networking website has a...
According to a social media​ blog, time spent on a certain social networking website has a mean of 16 minutes per visit. Assume that time spent on the social networking site per visit is normally distributed and that the standard deviation is 5 minutes. Complete parts​ (a) through​ (d) below. a. If you select a random sample 36 sessions, what is the probability that the sample mean is between 15.5 and 16.5 minutes? = 0.452 b. If you select a...
According to a social media​ blog, time spent on a certain social networking website has a...
According to a social media​ blog, time spent on a certain social networking website has a mean of 21 minutes per visit. Assume that time spent on the social networking site per visit is normally distributed and that the standard deviation is 3 minutes. Complete parts​ (a) through​ (d) below. a. If you select a random sample of 16 ​sessions, what is the probability that the sample mean is between 20.5 and 21.5 ​minutes? nothing ​(Round to three decimal places...
According to a social media​ blog, time spent on a certain social networking website has a...
According to a social media​ blog, time spent on a certain social networking website has a mean of 22 minutes per visit. Assume that time spent on the social networking site per visit is normally distributed and that the standard deviation is 4 minutes. Complete parts​ (a) through​ (d) below. a. If you select a random sample of 25 sessions, what is the probability that the sample mean is between 21.5 and 22.5 minutes? (Round to three decimal places) b.If...
According to a social media​ blog, time spent on a certain social networking website has a...
According to a social media​ blog, time spent on a certain social networking website has a mean of 18 minutes per visit. Assume that time spent on the social networking site per visit is normally distributed and that the standard deviation is 4 minutes a. If you select a random sample of 25 ​sessions, what is the probability that the sample mean is between 17.5 and 18.5 ​minutes?
According to a social media​ blog, time spent on a certain social networking website has a...
According to a social media​ blog, time spent on a certain social networking website has a mean of 18 minutes per visit. Assume that time spent on the social networking site per visit is normally distributed and that the standard deviation is 4 minutes. a. If you select random sample of 25 sessions, what is the probability that the sample mean is between 17 and 18 minutes?
According to a social media​ blog, time spent on a certain social networking website has a...
According to a social media​ blog, time spent on a certain social networking website has a mean of 17 minutes per visit. Assume that time spent on the social networking site per visit is normally distributed and that the standard deviation is 7 minutes. If you select a random sample of 100 sessions, what is the probability that the sample mean is between 16.5 and 17.5 minutes? A global research study found that the majority of​ today's working women would...
According to a social media​ blog, time spent on a certain social networking website has a...
According to a social media​ blog, time spent on a certain social networking website has a mean of 19 minutes per visit. Assume that time spent on the social networking site per visit is normally distributed and that the standard deviation is 44 minutes. Complete parts​ (a) through​ (d) below a. If you select a random sample of 25 ​sessions, what is the probability that the sample mean is between 18.5 and 19.5 ​minutes? b. If you select a random...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT