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

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...

IT management

FIGURE P1.1 The File Structure for Problems 1-4 1.       How many records does the file contain? How many fields are there per record? 2.       What problem would you encounter if you wanted to produce a listing by city? How would you solve this problem by altering the file structure? 3.       If you wanted to produce a listing of the file contents by last name, area code, city, state, or zip code, how would you alter the file structure? 4.       What data redundancies do you detect? How could those redundancies lead to anomalies? Figure P2.4 The DealCo relational diagram 4. Identify each relationship type and write all of the business rules. 5.       Create the basic Crow’s Foot ERD for DealCo. FIGURE P3.17 The Ch03_TransCo Database Tables     17. For each table, identify the primary key and the for...

Freelance Writing

We have top rated writers to help you with your assignments... Get your assignments/orders done. Work Types Essay Article Argumentive essay Coursework Dissertation Thesis Editing Proofreading Case study Lab report Problem-solving Multiple-choice questions Powerpoint presentation Critical thinking Short story Assignment Speaker notes 1-page summary Poster Speech Referencing styles APA MLA Chicago Harvard Vancouver Oxford CSE Others How to post the question/problem?? Comment/Mail : Subject Academic level (High-school/Undergraduate/Postgraduate/Master/PhD/....) Style (APA/MLA/Harvard/..........) Language (English US/UK) Order type (essay/thesis/lab report/...........) Number of pages and sources required Deadline Number of pages Compensation that you are ready to offer