1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
svetlana [45]
3 years ago
14

Write a recursive function that calculates if two binary trees are similar?

Computers and Technology
1 answer:
ahrayia [7]3 years ago
5 0

Answer:

bool identicaltrees(Node* root1,Node* root2)//function of type boolean true if idenctical false if not.

{

   if(root1==NULL&&root2==NULL)//both trees are null means identical.

   return true;

   if(roo1 && root2)

   {

       if(root1->data==root2->data)//condition for recursive call..

       {

           return (identicaltrees(root1->left,root2->right)&&identicaltrees(root1->right&&root2->right);

       }

   }

   else

   return false;

}

Explanation:

In this function it of type boolean returns true if both the trees are identical return false if not.First we are checking root node of both the trees if both are null then they are identical returning true.

If both root nodes are not null then checking their data.If data is same then recursively traversing on both trees and checking both trees.

else returning false.

You might be interested in
What were the advantages and disadvantages of agricultural technology to us.
Digiron [165]

Advantages of technology in agriculture include expediting crop production rate and crop quantity, which in turn reduces costs of production for farmers and food costs for consumers, and even makes crops more nutritious and livestock bigger and meatier.

The excessive use of chemicals by the help of machines reduces the fertility of the land.Lack of practical knowledge the farmers cant handle the machines properly.While the cost of maintenance is very high.Overuse of machines may lead to environmental damage.It is efficient but has many side effects and drawbacks.

5 0
3 years ago
Read 2 more answers
When reading words using a Scanner object's next method, _________. a. any characters at the beginning of the input that are con
zavuch27 [327]

Answer:

The answer is "Option d"

Explanation:

The scanner method is the full token of the process, that finds and returns. It is token, which is followed by both the inputs meeting and the guideline template. This method can block, even though the former instance of hasNext() is true while waiting for input, and wrong choices can be described as follows:

  • In option a, It is incorrect because the character at the beginning can't be considered.
  • In option b, It is wrong because the characters are known as the word in which blank space not a part of the word.
  • In option c, It is wrong because in this input before the call is not the method.
3 0
3 years ago
Write the function prototype for a function called showSquare. The function should have a single parameter variable of the int d
xeze [42]

Answer:

void showSquare(int param){

}

Explanation:

In C++ programing language, this is how a function prototype is defined.

The function's return type (In this case Void)

The function's name (showSquare in this case)

The function's argument list (A single integer parameter in this case)

In the open and closing braces following we can define the function's before for example we may want the function to display the square of the integer parameter; then a complete program to accomplish this in C++ will go like this:

<em>#include <iostream></em>

<em>using namespace std;</em>

<em>void showSquare(int param);</em>

<em>int main()</em>

<em>{</em>

<em>    showSquare(5);</em>

<em>    return 0;</em>

<em>}</em>

<em>void showSquare(int param){</em>

<em>int square = param*param;</em>

<em>cout<<"The Square of the number is:"<<endl;</em>

<em>cout<<square;</em>

<em>}</em>

8 0
4 years ago
What is the thing I have circled in the picture?
Verizon [17]
The number of branliest answers you have

5 0
3 years ago
Read 2 more answers
What could prevent earmuffs from providing your ears good protection from noise?
uranmaximum [27]
Well for one thing, ear muffs were made to keep your ears warm, not protection from noise.
3 0
4 years ago
Other questions:
  • A(n)…………is the interface used toconnect external devices to the computer.
    5·1 answer
  • One of the best examples of outcome control is the re-hiring of Steve Jobs by Apple as CEO
    14·1 answer
  • is the process of creating a message to be communicated. a. Encoding b. Decoding c. Receiving d. Sending
    10·2 answers
  • When an attacker presents a program or himself as someone else to obtain private information and pretends to be a legitimate web
    11·1 answer
  • Intellectual property piracy has gotten a small boost from the increasing availability of counterfeit goods through Internet cha
    14·1 answer
  • If you are working with a team of students on a class project and your team chooses to share content by uploading Word and Excel
    13·1 answer
  • Start with the following Python code. alphabet = "abcdefghijklmnopqrstuvwxyz" test_dups = ["zzz","dog","bookkeeper","subdermatog
    13·1 answer
  • What are the 3 examples of numeral systems
    5·1 answer
  • Write Java code that creates an array of n integers myArray, by taking n integers from the user with duplications, and do the fo
    8·1 answer
  • Use a slicer to filter the data in this table to show only rows where the Category value is Coffee or Meals
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!