Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
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
a) Write a program that asks user to enter number of vertices in an undirected graph and then the adjacency matrix representing the undirected graph. The program, then, must display whether the given graph is connected or not. You will find two sample runs of the program below. Sample 1 Sample 2 Enter number of vertices: 3 Enter number of vertices: 3 Enter adjacency matrix: 0 1 1 1 0 0 1 0 0 Enter adjacency matrix: 0 1 0 1 0 0 0 0 0 The graph is connected. The graph is not connected.
Data structure/ C language /  Graph /  Dijkstra’s algorithm implement a solution of a very common issue: how to get from one town to another using the shortest route.* design a solution that will let you find the shortest paths between two input points in a graph, representing cities and towns, using Dijkstra’s algorithm. Your program should allow the user to enter the input file containing information of roads connecting cities/towns. The program should then construct a graph based on the information provided from the file. The user should then be able to enter pairs of cities/towns and the algorithm should compute the shortest path between the two cities/towns entered.Attached a file containing a list of cities/towns with the following data:Field 1: Vertex ID of the 1st end of the segmentField 2: Vertex ID of the 2nd of the segmentField 3: Name of the townField 4: Distance in Kilometer Please note that all roads are two-ways. Meaning, a record may represent both the roads from…
a) Write a program that asks user to enter number of vertices in a directed graph and thenthe adjacency matrix representing the directed graph. The program, then, must display thenode with the highest outdegree. Assume that nodes are named as 0, 1, 2 and so on.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education