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
Scanner can be used to read tokens from a String literal Scanner can be used to read tokens from the console window (user input)
Paladinen [302]

Answer:

Scanner can be used to read tokens from the console window (user input)

Explanation:

Scanner is a class used in some programming languages to obtain inputs from users.

It is mostly well developed in Java programming language and used exclusively for taking and obtaining inputs.

Scanner takes input in primitive types such as doubles, floats and integers. IT also takes string inputs.

Here is a code snippet where the class scanner is used:

         Scanner input = new Scanner (System.in)

The code above creates an object of the scanner class

7 0
3 years ago
The ____ event of a ComboBox object is triggered when the user changes the selection.?
Semmy [17]
The "Selected Index Changed" event of a ComboBox object is triggered when the user changes the selection.
8 0
2 years ago
Define an __init__ method that has all the field names as parameters (in the order they appear in the second argument to pnamedt
mario62 [17]

<!DOCTYPE html PUBLIC "-//IETF//DTD HTML//EN">

<html><head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

 <title>Program 3</title>

</head>

<body bgcolor="white">

<center>

<h1>Program 3</h1>

<h1>

Programs that Write Programs: pnamedtuple

</h1>

<p>

</p><h2>ICS-33: Intermediate Programming<br>

</h2>

<p>

</p></center>

<!-- Introduction -->

<a name="Introduction">

<hr align="left" width="33%">

<table rules="none" border="0" cellpadding="5" cellspacing="0" width="100%">

<tbody>

<tr valign="top">

<td width="20%"><b>Introduction</b></td>

<td width="80%">

This programming assignment is designed to show how Python functions can define

 other Python code (in this case, a class) in an unexpected way: the function

 can build a huge string that represents the definition of a Python class and

 then call <b>exec</b> on it, which causes Python to define that class just as

 if it were written in a file and imported (in which case Python reads the

 file as a big string and does the same thing).

Your code will heavily rely on string formatting operations: I suggest using

 the <b>str.format</b> method to do the replacements: now is a good time to

 learn about this function if you don't know already know it; but you are free

 to use whatever string processing tool(s) you want.

<p>

I suggest that you first read the description below and define/test/debug as

 much of the <b>Point</b> class as you can, writing it directly in Eclipse

(especially the<b>__getitem__</b>, <b>__eq__</b>, and <b>_replace__</b>

 methods).

You might want to write a small batch file to help you test this class.

</p><p>

Once you have written/debugged the code for the <b>Point</b> class, define the

 general <b>pnamedtuple</b> function, which when given the appropriate

 arguments (for the <b>Point</b> class: <b>pnamedtuple('Point', 'x y')</b>)

 constructs a huge string containing the same code as the <b>Point</b> class

 you wrote.

Much of the code from your <b>Point</b> class will be turned into strings and

 made generic: generalized for calls to <b>pnamedtuple</b> with different

 arguments.

Use the <b>.format</b> method to replace the generic parts with the actual

 strings needed for the class being defined.

5 0
2 years ago
Using the diagram to the right, match each letter
alexira [117]

Answer:

A - slide

B - ribbon

C- command

D - group

E - format painter

F - tab

Explanation:

edge2020

5 0
2 years ago
Write an if/else statement that compares the variable age with 65, adds 1 to the variable seniorCitizens if age is greater than
Oduvanchick [21]

if age >= 65:

seniorCitizens = seniorCitizens + 1

else:

nonSeniors = nonSeniors + 1

6 0
2 years ago
Other questions:
  • If you are trying move a hard drive from a non-working computer to a working computer for the purposes of accessing the data on
    5·1 answer
  • Which network is the predecessor of the Internet?
    13·1 answer
  • The windows troubleshooting utility that identifies and eliminates nonessential files is called _____.
    15·2 answers
  • Write a program that uses for loops to perform the following steps: Prompt the user to input two integers: firstNum and secondNu
    15·1 answer
  • True or false? the categories of software applications are mutually exclusive
    6·2 answers
  • Advantages and disadvantages of internet
    11·2 answers
  • You need to protect sensitive files from unauthorized users even if the disk is stolen. What feature should you use and on what
    8·1 answer
  • Question #4
    10·1 answer
  • Which elements of text can be changed using automatic formatting? Check all that apply.
    8·1 answer
  • 7.2.4 Area of Triangle HELP PLEASE!! (JAVA SCRIPT) I WILL WAIT FOR THE SOLUTION.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!