Question: 4. A tree is called symmetric if for every internal node u all the children of u store the same value. For example the following

 4. A tree is called symmetric if for every internal node

4. A tree is called symmetric if for every internal node u all the children of u store the same value. For example the following tree with root a is symmetric, but the tree with root b is not symmetric as one child of node v stores value 2 while the other stores 3. 60000 6 60000 6 (a) [6 marks) Write in pseudocode an algorithm isSymmetric(r) that receives as input the root r of a tree and it outputs the value true if the tree is symmetric and false if it is not. For a node v let v.value denotes the value stored in v. To access the children of a node r use the following pseudocode: for each child c of r do {...}. (b) (2.5 marks) Compute the time complexity of your designed algorithm as a function of the total number n of nodes in the tree in worst case. You must (i) explain what the worst case for the algorithm is; (ii) explain how you computed the time complexity; (iii) give the order of the time complexity of the algorithm. (c) (2 marks] What's the space complexity of your designed algorithm in worst case and give the order. No need to draw the execution stack but explain it. (Hint: space complexity is the amount of memory needed for execution stack and storing data structures)

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!