Question
Book Icon
Chapter 25, Problem 25.17PE
Program Plan Intro

Program Plan:

  • Include the required import statement.
  • Define the main class.
    • Declare the necessary variables
    • Using start initialize the required.
      • Create border pane, tree view, text field and button.
      • Set the tree view as center, alignment.
      • Add an action event to the button.
      • Create a scene and place the pane in the stage.
      • Set the title.
      • Place the scene in the stage.
      • Display the stage.
    • Define the main method using public static main.
      • Initialize the call.
    • Define “decode” method.
      • Declare the variable
      • Check the length of the “bits”.
        • If the “bits” value is “0” set that value into left subtree, if the “bits” value is “1” set the value into right subtree.
      • If the left subtree is null, leaf is detected and restart from the root.
      • Return the “result”.
    • Define “encode” method.
      • Declare and set the value.
      • Check the length of the “text”.
        • Calculate the result.
        • Return the “result”.
    • Define “getCode” method.
      • Check the “root” value is null
      • The variable “codes” is declared and allocates memory for that variable.
      • Call the “assignCode” method.
      • Return the “codes” value.
    • Define “assignCode” method.
      • Check if root of left subtree value is not null.
        • If the condition is true, calculate the left and right subtree value and call the “assignCode” method with the respective parameters.
      • Otherwise calculate the “root” element value.
    • Define “getHuffmanTree” method.
      • Create a heap to hold the trees.
      • Add the values into the heap tree.
      • If the heap tree is greater than 1, remove the smallest and next smallest weight from the tree and combine the two trees.
      • Finally return the tree.
    • Define “getCharacterFrequency” method.
      • Declare the variable.
      • The try-catch block is used to check the input file is present or not and count the number of characters in that file.
      • Return the total counts.
    • Define “TreeView” class.
      • Declare the required variables.
      • Define the constructor.
      • Define the “setTree” method.
        • Add the value.
        • Call the “repaint” method.
      • Define the “repaint” method.
        • Clear the pane
        • Display the tree recursively.
    • Define the “displayTree” method.
      • Check if the left node value is not equal to null.
        • Draw a line to the up node.
        • Draw the left subtree recursively.
      • Check if the right node value is not equal to null.
        • Draw a line to the down node.
        • Draw the left subtree recursively.
      • Display the node.
    • Define “Tree” class.
      • Declare the variable.
      • Create a tree with two subtrees,
      • Create a tree containing a leaf node.
      • Compare the trees based on their weights.
    • Define “Node” class.
      • Declare the required variables.
      • Create a default constructor.
      • Create a node with the particular weight and character.
    • Define “Heap” class.
      • Create the object for the ArrayList
      • Create the default constructor.
      • Create a heap from an array of objects.
      • Define “add” method.
        • Add the new object into the heap.
        • Check the “currentIndex” value is greater than 0.
          • Swap if the current object is greater than its parents.
          • Assign “parentIndex” value into “currentIndex” variable.
      • Define “remove” method.
        • Check the condition and remove the root from the heap.
        • Declare and compute the left and right child index.
        • Then find the maximum value between two children.
        • Swap if the current node is less than maximum value.
        • Finally return the value.

Blurred answer
Students have asked these similar questions
Using the notation

you can select multipy options
For each of the following, decide whether the claim is True or False and select the True ones: Suppose we discover that the 3SAT can be solved in worst-case cubic time. Then it would mean that all problems in NP can also be solved in cubic time. If a problem can be solved using Dynamic Programming, then it is not NP-complete. Suppose X and Y are two NP-complete problems. Then, there must be a polynomial-time reduction from X to Y and also one from Y to X.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning