Chapter VII summarizes the data structure

Chapter VII of the study is to find the main content.

First, the basic concept has to find (1) a lookup table (2) key (3) Find (4) dynamic and static lookup table lookup table (5) the average length

 

Second, linear table lookup

  1, sequential search

    (1) from one end of the keyword table is sequentially recorded and compared to a given value, and when the key of a record is equal to a given value, the search is successful; otherwise, if the post-scan the entire table, not found keywords and equal to the reference records, the lookup fails

    (2) time complexity of O (n)

    (3) Advantages: simple algorithm, no requirement for table structure, regardless of whether the record order can be applied by Keyword

    (4) disadvantages: large average search length, low search efficiency

  2, binary search

    (1) satisfies an orderly, sequential storage available

    (2)T(n)=O(log2(n)),S(n)=O(1)  

    (3) storing the unordered sequence: T (n-) = O (nlog (n-)) + O (log 2 (n-)) = O (nlog 2 (n-))

    (4) on the chain stores: binary search may be applied, but not in log 2 within the (n) time complexity, because there is no random access

    (5) binary search scenarios limitations (for static lookup):

      ① sequential storage

      ② for ordinal data

      ③ small amount of data is not time-consuming operation, and comparison, no bipartite

      ④ the amount of data is not too large (exceeds the available contiguous space of memory)

  Third, the tree table lookup

  1, binary sort tree

    (1) Condition:

      ① left subtree root node is less than, greater than the root right subtree

      ② left subtree is a binary sort tree

      ③ right subtree is the binary sort tree

    (2) process:

      ① Find

      ② insert

      ③ create

      ④ Delete

  2, the insertion order to generate different results for different

    (1) is preferably: O (log 2 n-)

    (2) Worst: O (n)

  Fourth, find the hash table

  1, the main research questions

    (1) how to construct a hash function

    (2) how to deal with conflict

  2, the rules of good hash function

    (1) To calculate the simple function, each corresponding to a keyword only with a hash address

    (2) be a function of range over a long table range, the calculated hash address distribution should be uniform, as much as possible to reduce conflicts

 

Share PTA chapter title is a question of practice:

7-1 QQ application and login account (30 points)
 

QQ achieve new account applications and a simplified version of the old account login function. The biggest challenge is: It is said that QQ number has 10 digits of.

Input formats:

Firstly, input a positive integer N ( ≤), and then gives N-line instructions. Each command format is: "command (blanks) QQ number (blank) password." He said to be a new application number a QQ, followed by the new account number and password which command character is "N" (on behalf of New); command symbol to "L" (on behalf of Login) when the representation is old account login, followed login information . A QQ number is not more than 10, but greater than 1000 (said boss QQ number 1001) integer. Password is not less than 6, no more than 16, the string does not include spaces.

Output formats:

For each instruction, the corresponding information is given:

1) If the new application account is successful, the output "New: the OK";
2) number if the new application already exists, then the output "ERROR: Exist";
3) If the old account login is successful, the output "Login: OK";
4) If the old QQ account number does not exist, then the output "eRROR: not exist";
5) If the old account password is wrong, the output "eRROR: wrong PW".

Sample input:

5
L 1234567890 [email protected]
N 1234567890 [email protected]
N 1234567890 [email protected]
L 1234567890 myQQ@qq
L 1234567890 [email protected]

Sample output:

ERROR: Not Exist
New: OK
ERROR: Exist
ERROR: Wrong PW
Login: OK


code show as below:
#include <the iostream> 
#include <Map>
 the using  namespace STD; 
 
typedef struct 
{ 
    String name;
     String Secret; 
} QQ;     // definition of a structure comprising a username and password 
 
QQ A [ 100005 ];    // open up space for the maximum structure 
 
int main () 
{ 
    int n-;   // custom parameter 
    CIN n->>;    // number of input command 
     
    map < String , String > Search;     // Create a map container easily account and password match 
     
    int I, J;     // defined parameters
     
    char Demand;     // define parameters determined character 'L' and 'N' 
     
    for (I = 0 ; I <n-; I ++ ) 
    { 
        CIN >> Demand;   // input command type 
         
        IF (Demand == ' N ' ) // If the new account is 
        { 
            CIN >> A [I] .name >> A [I] .secret;     // enter the account password 
             
            IF (search.find (A [I] .name) search.end == ())   / / If the account does not exist 
            { 
                Search [a [I] .name] = a [I] .secret;   // to map container insert account and the corresponding password 
                 
                COUT << "New: the OK " << endl;   // output statement 
            }
             the else     // If the account exists 
            { 
                COUT << " ERROR: Exist A " << endl; // output statement 
            } 
        } 
         
        the else  IF (Demand == ' L ' )     // If the old account 
        { 
            CIN >> A [I] .name >> A [I] .secret;     // enter the account password 
             
            IF (search.find (A [I] .name) search.end == () ) cout << " ERROR: Not Exist " << endl;   //If the account does not exist, the output statement 
             
            the else     // If the account exists 
            {
                 IF (Search [A [I] .name] == A [I] .secret) COUT << " the Login: the OK " << endl;   // enter the password is correct, the output statement 
                the else cout << " eRROR: wrong PW " << endl; // enter the wrong password, the output statement 
            } 
        } 
    } 
     
    return  0 ; 
}

Difficulty of the subject is not difficult, the complexity of the program is not large, the most important thing is to be divided into many categories, clear logic to compare, but doing it is relatively simple.

 

Learning experience: Find the words to use in the future development will be more, I think everywhere use to find, the feeling is very practical and very important one thing.

The algorithm to find my grasp is not particularly good, the next stage should be to strengthen the understanding of its algorithm.

 

Recommended learning materials:

1. Daniel blog about B- tree presentation: https: //blog.csdn.net/u013411246/article/details/81088914

2. The method for dealing with conflict: https: //www.cnblogs.com/ch122633/p/9062827.html

 

Guess you like

Origin www.cnblogs.com/fengwanthousand/p/10963111.html