Question: NEED PSEUDOCODE FOR THIS CODING package binary; import java.util.Scanner; public class Binary { /** * @param args the command line arguments */ public static void

NEED PSEUDOCODE FOR THIS CODING

package binary;

import java.util.Scanner;

public class Binary {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner b = new Scanner(System.in);

System.out.print("Enter input: "+" ");

int n=b.nextInt();

int c=b.nextInt();

int parent[]=new int[n+1];

int color[]=new int[n+1];

parent[1]=-1;

for(int i=2;i<=n;i++)

{

parent[i] = b.nextInt();

}

for(int j=1;j<=n;j++)

{

color[j]= b.nextInt();

}

int ans[]=new int[n+1];

for(int k=1;k<=n;k++)

{

ans[k]=-1;

}

for(int v=1;v<=n;v++)

{

int ancestor=parent[v];

while(ancestor!=-1)

{

if(color[v]==color[ancestor])

{

ans[v] = ancestor;

break;

}

ancestor = parent[ancestor];

}

}

System.out.print("output: "+" ");

for(int i=1;i<=n;i++)

{

System.out.print(ans[i]+" ");

}

System.out.print(" ");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!