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

Need answers for your academic questions?

Need answers for your academic questions? Ask them in the comment section below. Just type in the url link of your question in the comment section below. And get your answer ready in two formats. Hand written Screenshot We will post the answer as soon as we get them (questions) Thank you..
Question: prove by induction 2^2 + 4^2 + 6^2 + ... + (2n)^2 = (2n)(2n+1)(2n+2)/6 ANSWER we will use induction on n base case : n=1 we have, 2^2 = 2*3*4/6 = 4 which is true inductive hypothesis let it be true for n = k i.e.,  2^2 + 4^2 + ... + (2k)^2 =   [(2k)(2k+1)(2k+2)]/6 inductive case let n = k+1 then we have 2^2 + 4^2 + .... + (2k)^2 + (2(k+1))^2 =   [(2k)(2k+1)(2k+2)]/6 + (2k+2)^2 =(2k+2)*[(2k)(2k+1)/6 + (2k+2)] =(2k+2)*[ (4k^2+2k)/6 + (12k + 12)/6 ] =(2k+2)*[ (4k^2+14k+12)/6 ] = =(2k+2)*[(2k)(2k+1)/6 + (2k+2)] =(2k+2)*[ (4k^2+2k)/6 + (12k + 12)/6 ] =(2k+2)*[ (4k^2+14k+12)/6 ] = (2k+2)*[ (4k^2 + 8k + 6k + 12)/6 ] = (2k+2)*[ (4k(k + 2) +6(k+2))/6 ] = (2k+2)*[ (4k+6)(k+2)/6 ] =  (2k+2)*[ 2 (2k+3)(k+2)/6  ] =   (2k+2)*[  (2k+3)*2*(k+2)/6  ] =   (2k+2)*[  (2k+3)(2k+4)/6  ] = [(2*(k+1))(2*(k+1)+1)(2*(k+1)+2)]/6 replacing k+1 by m, we get replacing k+1 by m, we get [(2*m)(2*m+1)(2*m+2)]/6 this completes our proof b...

Get assignments and case studies solved...

Hey Guys! Checkout our new site, https://caseaments.blogspot.com/  , where you can get your assignments done at low rate. Just send us the assignment topic. Specify, what you all need, summary or step by step writing. Give us a dead-line and length of assignment. ( number of words) On the basis of that, you will be charged. Any subject, even you can send us case studies , and get them answered. Payment methods: PayPal Payoneer Mail us at earnwithmetoo@gmail.com with the above details for quick response. Or else, join Hangouts . email-id  earnwithmetoo@gmail.com