Two ordered trees T1 and T2 are called isomorphic if one of the following conditions holds true:
Design an algorithm to test if two given ordered trees are isomorphic. What is the running time of your algorithm?
Algorithm: ( To check the two trees are isomorphic or
not)
Parameter: Isomorphic(Tree T1(root1),Tree T2(root2))
Step 1: If Both T1 and T2 are empty, then T1 and T2 are isomorphic
Step 2: If any one of the tree is non-empty and other is
empty , then
T1 and T2 are not isomorphic
Step 3: If the value of root1(T1) are different from
value of root2(T2), then
T1 and T2 are not isomorphic
Step 4: If the value of root1(T1) is same as that of
value of root2(T2),then
Recursively checking the subtrees are isomorphic or
not By executing Step 5
Step 5: Either Isomorphic(root1->left,root2->left)
and Isomorphic(root1->right,root2->right)
or Isomorphic(root1->right,root2->left) and
Isomorphic(root1->left,root2->right)
If any one the above two condition is true then T1 and
T2 are isomorphic
End Algorithm.
Two ordered trees T1 and T2 are called isomorphic if one of the following conditions holds...
Problem 2 [35 points (155 15)]: Let Ti and T2 be two binary search trees containing the same elements. In this problem, you will show how to transform Ti into T2 (i.e. Ti is altered to now have the same structure as T2) through a series of rotation operations. (a) Define a binary tree to be a right-going chain if no node in the tree has a left child (in other words, the tree is a linked list formed through...
in java ..write all complete program from a- e
1. Given the two binary trees below: 14 16 Write a method called swapSubtrees, which swaps all of the left and right subtrees in the above binary trees. Add this method to the class BinaryTree and create a program to test this method for these 2 trees. Show the original trees and the resulting trees. Note: To test your algorithm, first create a binary search tree. Write a method called singleParent,...
I have almost done with this code to Implement Huffman Coding. However I have an error at the "Heap<Tree>". Could anyone help with solving this issue, really appreciated. Thank you!! import java.util.Scanner; public class HuffmanEncoding { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a text: "); String text = input.nextLine(); int[] counts = getCharacterFrequency(text); // Count frequency System.out.printf("%-15s%-15s%-15s%-15s\n", "ASCII Code", "Character", "Frequency", "Code"); Tree tree = getHuffmanTree(counts); // Create a Huffman tree String[]...
Exercise 11.3 Consider the following duopoly model. There are two firms sup- plying a market where demand is given by p(Q)- a-bQ. Firm i produces qi units of output and so the total level of production is q1q2. Both firms face the same constant marginal cost, so the cost of producing qi for firm i įs cqỉ. Thus the profit functions of firms 1 and 2 respectively, are given by: (a) Suppose that each firm takes the output of the...
I need help with the Implementation of an Ordered List (Template Files) public interface OrderedStructure { public abstract int size(); public abstract boolean add( Comparable obj ) throws IllegalArgumentException; public abstract Object get( int pos ) throws IndexOutOfBoundsException; public abstract void remove( int pos ) throws IndexOutOfBoundsException; public abstract void merge( OrderedList other ); } import java.util.NoSuchElementException; public class OrderedList implements OrderedStructure { // Implementation of the doubly linked nodes (nested-class) private static class Node { private Comparable value; private...
JAVA Lab Create a class called ArrayBasedStack. Declare the following variables: • data: references an array storing elements in the list • topOfStack: an int value representing the location of the stack top in the array • INITIAL_CAPACITY: the default capacity of the stack public class ArrayBasedStack <E> { private E[] data; private int topOfStack; private static final int INITIAL_CAPACITY = 5; } Add a constructor that will initialize the stack with a user-defined initial capacity. The top of the...
Please Write Pseudocode or Python code!
Thanks!
P1. b) is the following:
W1. (6 marks) Write the pseudocode for removing and returning only the second element from the Stack. The top element of the Stack will remain the top element after this operation. You may assume that the Stack contains at least two items before this operation. (a) Write the algorithm as a provider implementing a Stack using a contiguous memory implementation. You can refer to the implementation given in...
Recursion and Trees Application – Building a Word Index Make sure you have read and understood · lesson modules week 10 and 11 · chapters 9 and 10 of our text · module - Lab Homework Requirements before submitting this assignment. Hand in only one program, please. Background: In many applications, the composition of a collection of data items changes over time. Not only are new data items added and existing ones removed, but data items may be duplicated. A list data structure...
In this assignment you’ll implement a data structure called a trie, which is used to answer queries regarding the characteristics of a text file (e.g., frequency of a given word). This write-up introduces the concept of a trie, specifies the API you’re expected to implement, and outlines submission instructions as well as the grading rubric. Please carefully read the entire write-up before you begin coding your submission. Tries A trie is an example of a tree data structure that compactly...