Java review 003, java003

Source: Internet
Author: User

Java review 003, java003

Today I will mainly review the data structure.
Tree
  • Red/black tree (symmetric Binary Tree B) (wiki)
  • Features:
  • Advantages:
  • Purpose: used to construct correlated arrays (Map) and sets)
  • B tree

  • B + tree
  • Feature: No data is saved for each keyword and is only used for indexing. All data is saved on the leaf node. if the search is successful, the process ends only when the query is successful on the leaf node (different from B-tree)
  • Purpose: it is usually used in file systems of databases and operating systems.
  • B * tree
  • B + tree variants add pointers to brothers in non-root and non-leaf nodes of B + tree; BThe number of non-leaf node keywords defined in the tree must be at least (2/3)M, that is, the minimum block usage is 2/3 (instead of 1/2 of B + tree );
  • Key tree

  • Trie tree (Dictionary tree)
  • A typical application is used for statistics, sorting, and saving a large number of strings (but not limited to strings). Therefore, it is often used by the search engine system for text word frequency statistics.
  • Advantage: the common prefix of the string is used to reduce the query time and minimize unnecessary string comparisons. The query efficiency is higher than that of the hash table.
  • Sorting (implemented in java)

    See my other blog: some-sort-algorithms

  • Binary Search Package vell. bibi. algorithms. search;

    Public class BinarySearch {

    // Non-Recursive Implementation
    Public static int search (int [] a, int key ){
    Int low = 0, high = a. length-1, mid = 0;
    While (high> = low ){
    Mid = (high + low)/2;
    If (key = a [mid]) return mid;
    Else if (key> a [mid]) low = mid + 1;
    Else high = mid-1;
    }
    Return-1;
    }

    // Recursive Implementation
    Public static int search (int [] a, int low, int high, int key ){
    If (high <low) return-1;
    Int mid = (low + high)/2;
    If (key = a [mid]) return mid;
    Else if (key> a [mid]) return search (a, mid + 1, high, key );
    Else return search (a, low, mid-1, key );
    }

    Public static void main (String [] args ){
    Int [] a = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
    System. out. println (search (a, 5 ));
    System. out. println (search (a, 0, a. length-1, 5 ));
    }
    }

  • Java end exam of Northeast Forestry University

    Value: 0 = 0.
     
    How to Implement output similar to 003 in java

    Use a string
    Int x;
    String str = null;
    If (x <10 ){
    Str = "00" + x;
    } Else if (x <100 ){
    Str = "0" + x;
    } Else {
    Str = String. valueOf (x );
    }

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.