In pseudocode rather than actual java, c, or python code write Map and Reduce fu
ID: 3865638 • Letter: I
Question
In pseudocode rather than actual java, c, or python code write Map and Reduce functions in pseudocode for the following problem:
Assume that you have the Twitter follower list for a large number of users. The follower list is provided in the following format:
first user's twitter handle, second user's twitter handle to indicate that the second user is a follower of the first user.
For example, alice01, bob02 would indicate that bob02 follows alice01.
1. Given input data containing many such user, follower pairs, write map and reduce functions to calculate the total number of followers for each user. The output file should contain the user names followed by a comma followed by a number indicating the number of followers of the user.
For example, if alice01 has 7 followers, then the output should contain the line alice01, 7
[Hint: You can adapt the word count example to solve the above problem]
2. Given input data containing many such user, follower pairs, write map and reduce functions to calculate the number of common followers for all pairs of users.
For example, if alice01 and bob02 has 3 common followers, then the output should contain the line alice01, bob02, 3
Explanation / Answer
Pseudocode:
Reduce_function1()
start
=>Declare the Required Variables
Declarations
String map[100]
char user_profile[10]
int count
int follower
for(follower=0;follower<no.ofUsers;followers++)
//outer Loop to find Followers for each user
{
user_profile=map[followers];
for(followers=0;followers<len;followers++) //Inner Loop
{
if(user_profile==map[followers]) //Compare
How many of Followers.
{
count++; //For Counting the Noof Followers
}
}
=>append the Followers data and count value to output file
write to file(user_profile,count);
}
end
Reduce_function2(Char *argv[],int argc)
{
Declarations
String array[100];
int i,j //Loop Control Variables
int count=0;
FILE *file = fopen( argv[1], "r" ); //First
arguement is Filename opening for reading purpose
while(fgets(array[i],sizeof(array), file)!=NULL)
{
array[i][strlen(array[i])-1]=''; //Store the
List of Lines in an Array for Compare the common Followers
i++;
}
for loop (i to No.of follower) //Outer Loop
for determining Common Followers from all pairs
{
for Loop (j to Noof followers)
{
if(array[i]==array[j]}
{
count++; //Count The
No.of Common Followers to the console.
}
}
}
}