Skip to main content

Question: AVL & Hashing in JAVA LANGUAGE PLEASE :) Building a data structure for countries visa applications data Step 1: build a sample data file that contains countries visa applications records in the following format: Country_Nme / Country_VISA_related_data_file_name (e.g. Germany / Germany.txt ) Step 2: using the data file created in step 1, build an AVL tree of countries nodes (use country name as key). Step 3: implement the following functions on countries AVL tree:  Print out countries sorted.  Search for a specific country  Insert a new country record.  Delete a specific country record.  Calculate tree height.  Save Tree back to file. Step 4: using the Country_VISA_related_data_file_name that stored in each tree country node, load the visa data that stored in each file. The visa record data format in these files is as follow: Passport_#/Full_name/Age/Gender/ Intended_date_of_arrival/ Intended_date_of_departure (e.g. 289332/Mamoun Nawahdah/40/M/26\4\2016/2\5\2016) Step 4: create a Hash Table using the country visa data from step 4. Step 5: implement the following functions on country visa hash table:  Print hashed table (including empty spots).  Print out table size.  Print out used hash function.  Insert a new visa record to hash table.  Search for a specific visa record.  Delete a specific visa record.  Save hash table back to file. thank you :)


ANSWER
  1.  import java.util.Scanner;
    
  2.  
    
  3.  /* Class AVLNode */
    
  4.  class AVLNode
    
  5.  {    
    
  6.      AVLNode left, right;
    
  7.      int data;
    
  8.      int height;
    
  9.  
    
  10.      /* Constructor */
    
  11.      public AVLNode()
    
  12.      {
    
  13.          left = null;
    
  14.          right = null;
    
  15.          data = 0;
    
  16.          height = 0;
    
  17.      }
    
  18.      /* Constructor */
    
  19.      public AVLNode(int n)
    
  20.      {
    
  21.          left = null;
    
  22.          right = null;
    
  23.          data = n;
    
  24.          height = 0;
    
  25.      }     
    
  26.  }
    
  27.  
    
  28.  /* Class AVLTree */
    
  29.  class AVLTree
    
  30.  {
    
  31.      private AVLNode root;     
    
  32.  
    
  33.      /* Constructor */
    
  34.      public AVLTree()
    
  35.      {
    
  36.          root = null;
    
  37.      }
    
  38.      /* Function to check if tree is empty */
    
  39.      public boolean isEmpty()
    
  40.      {
    
  41.          return root == null;
    
  42.      }
    
  43.      /* Make the tree logically empty */
    
  44.      public void makeEmpty()
    
  45.      {
    
  46.          root = null;
    
  47.      }
    
  48.      /* Function to insert data */
    
  49.      public void insert(int data)
    
  50.      {
    
  51.          root = insert(data, root);
    
  52.      }
    
  53.      /* Function to get height of node */
    
  54.      
    
  55.    "4. check empty");
    
  56.             System.out.println("5. clear tree");
    
  57.  
    
  58.             int choice = scan.nextInt();            
    
  59.             switch (choice)
    
  60.             {
    
  61.             case 1 : 
    
  62.                 System.out.println("Enter integer element to insert");
    
  63.                 avlt.insert( scan.nextInt() );                     
    
  64.                 break;                          
    
  65.             case 2 : 
    
  66.                 System.out.println("Enter integer element to search");
    
  67.                 System.out.println("Search result : "+ avlt.search( scan.nextInt() ));
    
  68.                 break;                                          
    
  69.             case 3 : 
    
  70.                 System.out.println("Nodes = "+ avlt.countNodes());
    
  71.                 break;     
    
  72.             case 4 : 
    
  73.                 System.out.println("Empty status = "+ avlt.isEmpty());
    
  74.                 break;     
    
  75.             case 5 : 
    
  76.                 System.out.println("\nTree Cleared");
    
  77.                 avlt.makeEmpty();
    
  78.                 break;         
    
  79.             default : 
    
  80.                 System.out.println("Wrong Entry \n ");
    
  81.                 break;   
    
  82.             }
    
  83.             /*  Display tree  */ 
    
  84.             System.out.print("\nPost order : ");
    
  85.             avlt.postorder();
    
  86.             System.out.print("\nPre order : ");
    
  87.             avlt.preorder();
    
  88.             System.out.print("\nIn order : ");
    
  89.             avlt.inorder();
    
  90.  
    
  91.             System.out.println("\nDo you want to continue (Type y or n) \n");
    
  92.             ch = scan.next().charAt(0);                        
    
  93.         } while (ch == 'Y'|| ch == 'y');               
    
  94.     }
    
  95.  }

Comments

Popular posts from this blog

Osmosis Data Sheet

Data Sheet: Activity - Osmosis Name Course Date Activity Data Code       Procedure I -Test Solution 1: Water Complete the tablesand questions below using your data and information found under the Background tab Data Table I Note: Difference in Final Volumes = Final Volume of Test Sol - Final Volume of Water Trial Starting Volume of Test Solution (L) Starting Volume of Water (L) Final Volume of Test Solution (L) Final Volume of Water (L) Difference in Final Volumes (L) 1 1.28 1.75 1.51 1.52 -0.01 2 1.28 2.00 1.64 1.64 0 Observations and Questions [1] Given that the final heights (and volumes) are the same for the water and test solution, what can you...

Pseudocode - painting a wall

My pseudocode from Module Two: Pseudocode – Painting a Wall MEASURE wall-length MEASURE wall width CALCULATE wall area DETERMINE amount of paint needed for wall-size PURCHASE desired paint and tools (brushes, rollers, pan, etc.) PREPARE work area and tools START painting wall END when painting is complete CLEAN work area and tools STORE tools and any leftover pa​‌‌‌‌‌‌‍‍‍‌‌‍‍‍‌‍‌‍‍​int
Simple Computer Science Questions Question 2 ANSWER Match the following a - 4 b - 10 c - 8 d - 6 e - 9 f - 1 g - 2 h - 7 i - 3 j - 5