CN109815232A - A kind of method and system of retrieval, the data processing of the data rank using binary search tree - Google Patents
A kind of method and system of retrieval, the data processing of the data rank using binary search tree Download PDFInfo
- Publication number
- CN109815232A CN109815232A CN201811613883.8A CN201811613883A CN109815232A CN 109815232 A CN109815232 A CN 109815232A CN 201811613883 A CN201811613883 A CN 201811613883A CN 109815232 A CN109815232 A CN 109815232A
- Authority
- CN
- China
- Prior art keywords
- node
- subtree
- key
- size
- access times
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Disclose the method and system of retrieval, the data processing of a kind of data rank using binary search tree comprising subtree size size and access times freq is increased to binary search tree;If the key of present node is equal in magnitude with key's to be found, the ranking of key to be found is rank-Node.left.size, 1 is added to the access times of present node, if present node key is less than key to be found, it is searched to right subtree direction, ranking rises, i.e. the rank value of the minimum node in present node right subtree direction is that rank R is equal to rank-1-Node.left.size, if present node key is greater than key to be found, it is searched to left subtree direction, ranking is constant, until after the completion of searching, if the access times of present node are less than the access times of left subtree or right subtree node, present node and left subtree or right subtree node location are replaced.Using the position that the node more than access times is moved closer to root node as far as possible, the search efficiency of frequent query node is improved, to improve the recall precision of whole system.
Description
Technical field
The present invention relates to the technical fields of data retrieval, and in particular to a kind of data rank using binary search tree
Retrieval, data processing method and system.
Background technique
Many systems have the function of billboard, need to carry out user by integral or contribution margin or other numerical value real
When ranking.The realization of billboard is fairly simple, can store data in database, and the field that billboard needs is established rope
Draw, database can extremely efficiently inquire the data of the user of list top k.
Assuming that billboard is sorted by integral, there are also following demands by general user:
1. wanting to know the specific ranking of oneself.
2. who and how many integrals the user of close ranking be respectively with oneself.
It thus needs efficiently to inquire the ranking where specified integral, and can be inquired according to specific ranking corresponding
User information.Integration data is that real-time update changes, although can inquire function by the statistics of database, sequence, paging etc.
It is able to achieve the demand, but performance is just less efficient, database does these functions with regard to unable to do what one wishes.With mysql data
For library, for the system of ten million user, by the information of the user of order and limit keyword query specified rank, take each
Ranking test inquires average time-consuming about 10 seconds or so, can not meet the demand of system.
The data of relationship sequential storage are sized, binary chop can efficiently retrieve the data of designated value
Storage location, because of data sequential storage, it is known that position has been known that ranking.But real-time ranking, data are real-time updates,
More new data wants to continue the sequential order storage of maintenance data, it is necessary to spend bigger cost.
Summary of the invention
The invention proposes the method and systems of retrieval, the data processing of a kind of data rank using binary search tree.
In one aspect, the invention proposes a kind of search methods of data rank, comprising the following steps:
S101: subtree size size and access times freq is increased to binary search tree, and initializes key institute to be checked
Ranking rank=Root.size, present node is set to root node and starts to retrieve;
S102: judge the size relation of the key and key to be found of present node;
S103: if the key of present node and key's to be found is equal in magnitude, ranking rank x of key to be found etc.
Add 1 in rank-Node.left.size, while to the access times of present node;
S104: if present node key is less than key to be found, searching to right subtree direction, and ranking rises, that is, works as prosthomere
The ranking rank R of the minimum node of the right subtree node of point is equal to rank-1-Node.left.size, until after the completion of searching,
If the access times of present node are less than the access times of right subtree node, present node and right subtree node location are carried out
Displacement;
S105: if present node key is greater than key to be found, searching to left subtree direction, and ranking is constant, until searching
After the completion, if the access times of present node are less than the access times of left subtree node, present node and left subtree node
It is replaced position;
Wherein, key value indicates the certain field of user data, and Node.left.size indicates present node left subtree node
Number, Root.size indicate all node total numbers of binary search tree.
The key value is, for example, the integral of user, and the retrieval of ranking is carried out using the integral key of user, and the value for comparing key is looked into
The node location for finding corresponding key to be found is recalled after lookup terminates, and utilizes the access times pair of node
The node of binary tree carries out displacement adjustment, and the high node of access frequency is transferred to close to the position of root node, makes entirely to retrieve
System more efficiently carries out retrieval work.
In certain embodiments, in step S104 and step S105, after finding key to be found, step by step
Backtracking, is replaced using position of the access times to present node and left subtree or right subtree node.
In certain embodiments, in step S104 rank value during sub-tree search to the right with the change of present node
Change and successively decrease, the value subtracted is that the present node left subtree number adds 1.
In certain embodiments, this method is further comprising the steps of:
S106: repeating step S102- step S105, until present node key is equal to key to be checked or present node
For leaf node.
In certain embodiments, step S104 and step S105 replacement present node and left subtree node or right subtree
While node location, by the traversal order of former binary search tree to the son of present node and left subtree node or right subtree node
The position of node is adjusted, while the corresponding size of the node for updating adjustment.Make legacy data by the original of binary search tree
Traversal order is ranked up, and the accuracy of data rank is made to be guaranteed.
In certain embodiments, this method is further comprising the steps of: searching object according to the ranking rank of object
Information judges present node left subtree number and the size relation of size;
If present node left subtree number and size's is equal in magnitude, the information of present node is the information of object, together
When 1 is added to the access times of present node;
If present node left subtree number is less than size, Object node is in right subtree, object's position size-1-
Node.left.size, until after the completion of searching, if the access times of present node are less than the access times of right subtree node,
Present node and right subtree node location are replaced;
If present node left subtree number is greater than size, for Object node in left subtree, size is constant, completes until searching
Afterwards, if the access times of present node are less than the access times of left subtree node, present node and left subtree node location
It is replaced;
Wherein, size is the number of nodes of the object left subtree of rank, initializes size=Root.size-rank.
According to the ranking of object come the information of query object, the access times that binary search tree is ibid utilized are adjusted
It is whole, after finding object information, recall step by step, the node location of binary search tree is updated using the access times of node,
Maximize effectiveness of retrieval.
In certain embodiments, this method further includes the steps that carrying out node updates to binary search number, and node is more
New step specifically includes the step of addition node and deletion of node.Addition and deletion to node data can be safeguarded preferably
The data information of binary search tree keeps the information of data more effectively and perfect.
In a further embodiment, the step of adding node specifically includes: being found by key greater than key and a no left side
Children tree nodes or less than key and the not node of right subtree, carry out creating new node, and trace back to root node step by step, more
New size adds 1.
In a further preferred embodiment, the step of deletion of node specifically includes: finding the section for needing to delete by key
Point is rotated node to be deleted to leaf node by rotation node, is deleted, and date back root node step by step, updated
Size subtracts 1.
According to another aspect of the present invention, a kind of data processing method using binary search tree is proposed comprising
Following steps:
S601: node visit number freq value and subtree size size value are increased to the node of binary search tree;
S602: during the node checks of binary search tree, 1 is added to the access times of the node found;
S603: according to the access times freq value of father's node and left subtree node or right subtree node, judge whether into
The adjustment of the node of row binary search tree;
S604: if the value of present node is less than the value of node to be found, sub-tree search of turning right, after the completion of lookup, if father
The access times of node are less than the access times of right subtree node, then are interchangeable the position of two nodes;
S605: if the value of present node is greater than the value of node to be found, sub-tree search of turning left, after the completion of lookup, if father
The access times of node are less than the access times of left subtree node, then are interchangeable the position of two nodes.
Above scheme is adjusted node location by access times, and the node more than access times is transferred to close to root
The position of node is looked into so as to improve the search efficiency of the node by frequently being inquired in the binary search tree in data
Speed that can be most fast during looking for finds out the object to be searched, to improve for carrying out using the binary search tree
Recall precision when retrieval.
In certain embodiments, position is carried out to father's node and left subtree or right subtree node according to access times
While replacement, the traversal order for pressing former binary search tree to the corresponding child node of left subtree or right subtree and father's node is carried out
Adjustment.The whole traversal order of binary search tree is constant after guarantee replacement position, does not influence the section of original binary search tree
The traversal order of point.
In certain embodiments, step: S603-S605 is repeated, until present node becomes leaf node.Entire
The node of binary search tree is adjusted, and is distributed the node of binary search tree more reasonably, improves effectiveness of retrieval.
According to the third aspect, a kind of computer readable storage medium is proposed, is stored thereon with one or more computer journeys
Sequence, which is characterized in that one or more computer programs are subsequently can by computer the method for implementing any of the above-described when device executes.
According to fourth aspect, a kind of searching system of data rank is proposed, which includes:
Data record unit increases subtree size size value and node visit number freq to the node of binary search tree
Value, and subtree size size value and node visit number freq value are recorded;
Data query judging unit, the size relation of key and key to be found for judging present node;
Ranking searching unit, for being inquired according to key to be found ranking rank, if the key of present node with to
The key's of lookup is equal in magnitude, and the ranking rank x of key to be found is equal to rank-Node.left.size;
If present node key is less than key to be found, searched to right subtree direction, the right subtree node of present node
The ranking of minimum node is equal to rank-1-Node.left.size, until finding key to be found;
If present node key is greater than key to be found, searched to left subtree direction, ranking is constant, until finding to be checked
Until looking for key;
Node updates unit, for the node more than access times to be moved closer to the position of root node;
When the access times of present node are less than the access times of right subtree node, present node and right subtree node position
It is replaced;
When the access times of present node are less than the access times of left subtree node, present node and left subtree node position
It is replaced;
It also configures while carrying out position displacement to present node and left subtree or right subtree node according to access times,
The corresponding child node of left subtree or right subtree is adjusted by the traversal order of former binary search tree.
The data processing of binary search tree according to the present invention a kind of, data rank search method and system, to y-bend
Each node increase of search tree records it and all node total numbers in subtree, and subsequent search procedure can be according to the word
Section, calculates the ranking of query node, passes through the data of the field also available specified rank.To each section of binary search tree
Point, which increases, records accessed number, the position for moving closer to root node as far as possible more than access times, improves frequently inquiry
The search efficiency of node, to improve the recall precision of whole system.
Detailed description of the invention
Including attached drawing to provide a further understanding of embodiments and attached drawing is incorporated into this specification and is constituted this
Part of specification.Drawing illustration embodiment and together with the description principle for explaining the present invention.It will readily recognize that
To many expected advantages of other embodiments and embodiment, because described in detail below by quoting, they become by preferably
Understand.By reading a detailed description of non-restrictive embodiments in the light of the attached drawings below, other spies of the application
Sign, objects and advantages will become more apparent upon:
Fig. 1 is the method that the data rank according to an embodiment of the invention using binary search tree is retrieved;
Fig. 2 is the schematic diagram of the subtree rotation of a specific embodiment according to the present invention;
Fig. 3 is the flow chart of the search method using key data rank of a specific embodiment according to the present invention;
Fig. 4 is the stream of the method using size data retrieval object information of another specific embodiment according to the present invention
Cheng Tu;
Fig. 5 is the flow chart of the method for deletion of node according to another embodiment of the present invention;
Fig. 6 is the flow chart of the data processing method according to an embodiment of the invention for binary search tree;
Fig. 7 is a kind of searching system of data rank according to the present invention.
Specific embodiment
The application is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouched
The specific embodiment stated is used only for explaining related invention, rather than the restriction to the invention.It also should be noted that in order to
Convenient for description, part relevant to related invention is illustrated only in attached drawing.
It should be noted that in the absence of conflict, the features in the embodiments and the embodiments of the present application can phase
Mutually combination.The application is described in detail below with reference to the accompanying drawings and in conjunction with the embodiments.
The method that data rank according to an embodiment of the invention using binary search tree is retrieved, Fig. 1 are shown
The flow chart of the search method of the data rank for binary search tree of embodiment according to the present invention.As shown in Figure 1, the party
Method the following steps are included:
S101: subtree size size and access times freq is increased to binary search tree, and initializes key institute to be checked
Ranking rank=Root.size, and present node is set to root node and starts to retrieve.
S102: judge the size relation of the key and key to be found of present node.By judge the key of present node with
The size of key to be found can obtain the position of the node of key to be found and the positional relationship of present node, according to the position
The relationship of setting is searched.
S103: if the key of present node and key's to be found is equal in magnitude, ranking rank x of key to be found etc.
Add 1 in rank-Node.left.size, while to the access times of present node.The key of present node and key to be found
It is equal, indicate that present node is node to be found, the calculation formula of ranking are as follows: rank x=rank-
Node.left.size, wherein rank is initialized as node total number Root.size, the Node.left.size table of entire binary tree
Show the sum of the left subtree node of present node.
S104: if present node key is less than key to be found, searching to right subtree direction, and ranking rises, that is, works as prosthomere
The ranking rank R of the right subtree node of point is equal to rank-1-Node.left.size, until after the completion of searching, if present node
Access times be less than right subtree node access times when, present node and right subtree node location are replaced.
In the particular embodiment, present node key is less than key to be found, indicates key to be found in present node
Right subtree direction, the rank value of the minimum node in present node right subtree direction is rank R=rank-1-
Node.left.size, then remember that the node key of right subtree is that present node and key to be found are compared, repeat above step until
The key for finding node is equal with key to be found, and search procedure terminates, and is recalled, and judges the access times of node, if working as
When the access times of front nodal point are less than the access times of right subtree node, present node and right subtree node location are set
It changes.
S105: if present node key is greater than key to be found, searching to left subtree direction, and ranking is constant, until searching
After the completion, if the access times of present node are less than the access times of left subtree node, present node and left subtree node
It is replaced position;
In the particular embodiment, present node key is greater than key to be found, indicates key to be found in present node
Left subtree direction, ranking is constant, remembers that the node of left subtree is that present node and key to be found are compared, it is straight to repeat above step
Equal with key to be found to the key for finding node, search procedure terminates, and is recalled, and the ratio of the access times of node is passed through
Compared with if the access times of present node are less than the access times of left subtree node, present node and right subtree node location
It is replaced.
Wherein, key value indicates the certain field of user data, and Node.left.size indicates present node left subtree node
Number, Root.size indicate all node total numbers of binary search tree.
In the particular embodiment, which is, for example, the integral of user, carries out ranking using the integral key of user
Retrieval, the value for comparing key find the node location of corresponding key to be found and are recalled after lookup terminates, benefit
Displacement adjustment is carried out with node of the access times of node to binary tree, the high node of access frequency is transferred to close to root node
Position, so that entire searching system is more efficiently carried out retrieval work, provide more optimized y-bend for subsequent query and search
The data of search tree.
In the particular embodiment, in the schematic diagram of right subtree as shown in Figure 2 rotation, when the access time of father's node A
In the case where access times of the number less than right subtree node C, father's node A and right subtree node location of C are replaced.It should
It is noted that during progress position is replaced, it is same to the position of the child node of father's node A and right subtree node C
When be adjusted, it is ensured that the traversal order of former binary search tree remains unchanged, for example, Fig. 2 right subtree rotation schematic diagram Central Plains two
The traversal order for pitching search tree is that B-A-C1-C-C2 needs to adjust the position of C1 after node A and node C transposition
It is whole, it is ensured that the sequence of binary search tree remains B-A-C1-C-C2.It should be noted that during the adjustment, node subtree
Number may change, so there is the corresponding size of the node of adjustment to need synchronized update, be updated to the sum of left and right subtree number and add
1。
In the particular embodiment, in the schematic diagram of left subtree as shown in Figure 2 rotation, when the access time of father's node A
In the case where access times of the number less than left subtree node B, father's node A and left subtree Node B site are replaced.It should
It is noted that during progress position is replaced, it is same to the position of the child node of father's node A and left subtree node B
When be adjusted, it is ensured that the traversal order of former binary search tree remains unchanged, for example, Fig. 2 left subtree rotation schematic diagram Central Plains two
The traversal order for pitching search tree is B1-B-B2-A-C, after node A and node B transposition, will need by the position of node B2 into
Row adjustment, it is ensured that the sequence of binary search tree remains B1-B-B2-A-C.It should be noted that during the adjustment, node
The number of tree may change, so there is the corresponding size of the node of adjustment to need synchronized update, be updated to left and right subtree number it
With add 1.
By increasing each node the record of access times, recycling access times are adjusted the position of node,
The past position close to root node of node more than access times is mobile, the search efficiency for the node frequently inquired is improved in this way,
It carries out that required information can be inquired faster during data retrieval, is greatly improved the data inspection of whole system
The efficiency of rope improves more times with common database retrieval processing, while the process encoded is also very succinct, is applicable in various answer
Use scene.
Fig. 3 shows the process of the search method using key data rank of a specific embodiment according to the present invention
Figure.
This method specifically includes the following steps:
S300: beginning looking for from the root node of binary search tree, write down present node be root node, Node=Root, just
Beginningization ranking is the size rank=Root.size of whole tree.
S301: whether the key of the key value Node.key and lookup that judge present node are equal.
In the particular embodiment, key value it is corresponding be user integral, the product of user is retrieved by the integral of user
Divide the ranking in entire integration data library, more can intuitively judge the ranking of user.
S302: if the key value Node.key of present node and the key of lookup are equal, illustrate what present node was just to look for
Node adds 1 to the access times Node.freq of present node.The access times for recording present node, in this, as node tune
Whole foundation.
S303:rank subtracts the ranking that left subtree number of nodes is present node.The node total number of whole tree subtracts currently
The sum of the left subtree node of node is the ranking where present node.
S304: along opposite direction backtracking is searched, judge whether to need to adjust tree.Recall step by step upwards, judges node
Access times size relation, judge whether need be adjusted.
In the particular embodiment, judge whether binary search tree needs to adjust, sentenced according to the access times of node
It is disconnected, during backtracking, if the access times of father's node are less than the access times of the node of its left subtree or right subtree,
Then need to carry out the node of father's node and its left subtree or right subtree the displacement of position, while its left subtree or right subtree
Child node be also required to be adjusted according to the traversal order of original binary search tree, guarantee that original binary search traversal of tree is suitable
Sequence is constant, does not influence the retrieval traversal order of the data of binary search tree.
S305: finding Node, returns to rank.Indicate that present node is exactly the node to be searched, and current node
Rank value be denoted as the rank value of the node to be searched, the ranking of output node, query process terminates.
S306: the Node.key size of Key and present node are searched in judgement, if the key searched is less than present node
Node.key size, then the step of carrying out S307, enter step if the key searched is greater than the Node.key size of present node
Rapid S310.
S307: judge whether present node is not present left subtree.In key to be found less than present node Node.key's
In the case of, judge present node with the presence or absence of left subtree.If left subtree is not present in present node, S309 is entered step, if working as
There are left subtrees for front nodal point, enter step S308.
S308:Node=Node.left.Present node indicates the key searched in left subtree, note is worked as there are left subtree
The left subtree node of front nodal point is Node=Node.left, and return step S301 re-starts judgement, until find
Key is equal with the value of Node.key, and finding node or finish node, there is no left subtrees, does not find key to be found, returns
Make the return trip empty value.
S309: not finding, returns empty.It indicates that key to be found is not present in binary search tree, exports result to system
For the node for not finding the key, null value is returned.
In optional implementation of the invention, can to binary search tree carry out node addition, present node not
There are in the case where left subtree, it can be newly inserted into a key to the left sibling creation of present node, information is the new section of value
Point, and be 1 for present node and children tree nodes size and access times freq by the node initializing.It is not deposited in present node
In the case where right subtree, it can be newly inserted into a key to the right node creation of present node, information is the new node of value,
It and be present node and children tree nodes size and access times freq by the node initializing is 1.And root section is traced back to step by step
Point updates number of nodes size and adds 1.By the node addition to binary search tree, binary search tree can be updated, make two
The data for pitching search tree are more perfect, while also easily facilitating the retrieval of data.
S310: judge whether present node is not present right subtree.In key to be found greater than present node Node.key's
In the case of, judge present node with the presence or absence of right subtree.If right subtree is not present in present node, step S311 is carried out, if working as
There are right subtrees for front nodal point, then enter step S309.
S311:rank subtracts present node and left subtree number of nodes Node=Node.right.There are right sons for present node
Tree indicates the key searched in right subtree, remembers that the right subtree node of present node is that rank subtracts present node and left subtree section
Points N ode=Node.right, and return step S301 re-starts judgement, until the value of the key and Node.key found
Equal, finding node or finish node, there are right subtrees, do not find key to be found, return to null value.
During carrying out ranking inquiry using key value, by continuous cyclic query, the visit of each node is recorded
It asks number, after poll-final, the adjustment of binary search tree is carried out using the access times of node, makes the structure of binary search tree more
Adduction reason, the retrieval and inquiry of data are just more efficient.
Fig. 4 shows the method using size data retrieval object information of a specific embodiment according to the present invention
Flow chart.This method specifically includes the following steps:
S400: beginning looking for from the root node of binary search tree, write down present node be root node, Node=Root, if
Ranking to be found is that the left subtree of rank object has size node, initializes size=Root.size-rank.
S401: judge whether the number of nodes size of left subtree number of nodes and left subtree to be checked of looking for a partner in marriage is equal.
In the particular embodiment, it is the ranking to be checked looked for a partner in marriage that rank is corresponding, is retrieved by the ranking of object pair
As other information in the database, it can quickly position the position of object and obtain the relevant information of object.
S402: if the number of nodes size of the left subtree number of nodes of present node and left subtree to be checked of looking for a partner in marriage is equal, explanation
The node that present node is just to look for adds 1 to the access times Node.freq of present node.Record the access of present node
Number, in this, as the foundation of node adjustment.
S403: along opposite direction backtracking is searched, judge whether to need to adjust tree.Recall step by step upwards, judges node
Access times size relation, judge whether need be adjusted.
In the particular embodiment, judge whether binary search tree needs to adjust, sentenced according to the access times of node
It is disconnected, during backtracking, if the access times of father's node are less than the access times of the node of its left subtree or right subtree,
Then need to carry out the node of father's node and its left subtree or right subtree the displacement of position, while its left subtree or right subtree
Child node be also required to be adjusted according to the traversal order of original binary search tree, guarantee that original binary search traversal of tree is suitable
Sequence is constant, does not influence the retrieval traversal order of the data of binary search tree.
S404: finding, and returns to Node.Indicate that present node is exactly the node to be searched, and the letter of current node
Breath is denoted as the information of the node to be searched, the information of output node, and query process terminates.
S405: judging the number of nodes size of left subtree to be checked of looking for a partner in marriage and the left subtree number of nodes size of present node, if
It is the step of number of nodes size of left subtree to be checked of looking for a partner in marriage is less than the left subtree number of nodes of present node, then carries out S406, to be checked
Look for a partner in marriage left subtree number of nodes size be greater than present node left subtree number of nodes, then enter step S409.
S406: judge whether present node is not present left subtree.The number of nodes size of left subtree to be checked of looking for a partner in marriage is less than and works as
In the case where the left subtree number of nodes of front nodal point, judge present node with the presence or absence of left subtree.If left son is not present in present node
Tree, then enter step S408, if there are left subtrees for present node, enter step S407.
S407:Node=Node.left.Present node there are left subtree, indicate object to be found in left subtree, note
The left subtree node of present node is Node=Node.left, and return step S401 re-starts judgement, until left subtree section
It counts equal with the number of nodes size of left subtree to be checked of looking for a partner in marriage, finds node, export the information or finish node of the node
There is no left subtrees, do not find key to be found, export null value.
S408: not finding, returns empty.It indicates that object to be found is not present in binary search tree, exports and tie to system
Fruit is the node for not finding the object, exports null value.
S409: judge whether present node is not present right subtree.The number of nodes size of left subtree to be checked of looking for a partner in marriage is greater than and works as
In the case where the left subtree number of nodes of front nodal point, judge present node with the presence or absence of right subtree.If right son is not present in present node
Tree, then carry out step S408, if there are right subtrees for present node, enter step S410.
S410:size subtracts present node and left subtree number of nodes Node=Node.right.There are right sons for present node
Tree indicates to be checked and looks for a partner in marriage in right subtree, remembers that the right subtree node of present node is that size subtracts present node and left subtree
Number of nodes Node=Node.right, and return step S401 re-starts judgement, until left subtree number of nodes and to be found right
As the number of nodes size of left subtree is equal, node is found, there are right subtrees for the information or finish node for exporting the node, not
Object to be found is found, null value is exported.
The process that object data inquiry is carried out using the rank value of object, is inquired with using the integral of object as key
The method of object is similar, and by the continuous inquiry of binary search tree, the visit of each node is recorded in each query process
It asks number, the adjustment of binary search tree is carried out using the access times of node, keeps the structure of binary search tree more reasonable, data
Retrieval and inquiry just more efficiently, can in real time to data carry out orderly adjustment, to improve the retrieval of whole system
Efficiency.
Fig. 5 shows the flow chart of the method for deletion of node according to another embodiment of the present invention.This method is specifically wrapped
Include following steps:
S500: beginning looking for from the root node of binary search tree, finds the node Node where key.
S501: judge that Node or so node exists and left sibling freq is greater than right node.If Node or so node exist and
Left sibling freq is greater than right node, then carries out step S502, if Node or so node exists and left sibling freq is less than right node,
Then enter step S503.
S502: if Node or so node exists and left sibling freq is greater than right node, Node node is subjected to anticlockwise.
S501 is returned after rotation re-starts judgement.
In the particular embodiment, anticlockwise signal as shown in Fig. 2, Node node carry out anticlockwise when, need to be according to original
The traversal order of some binary search trees carries out the adjustment of position to corresponding child node, guarantees original binary search traversal of tree
The consistency of sequence.
S503: judge Node with the presence or absence of right node.If Node carries out step S504 there are right node, if Node is not
There are right nodes, then carry out step S505.
S504: if there are right nodes by Node, Node node is subjected to right rotation.S501 is returned after rotation and is re-started sentences
It is disconnected.
In the particular embodiment, right rotation signal as shown in Fig. 2, Node node carry out right rotation when, need to be according to original
The traversal order of some binary search trees carries out the adjustment of position to corresponding child node, guarantees original binary search traversal of tree
The consistency of sequence.
S505: Node leaf node is deleted, traces back to root node step by step, size subtracts 1.
It is rotated left and right by the node of the Node to binary search tree, the node of Node is transferred to leaf node
On, then be deleted, the traversal order of entire binary search tree is not influenced, while having been carried out more to the data of binary search tree yet
Newly, some useless nodal informations can be deleted, maintains the data validity of binary search tree.
The data processing method for binary search tree of embodiment according to the present invention.Fig. 6 is shown according to the present invention
Embodiment the data processing method for binary search tree process.As shown in fig. 6, method includes the following steps:
S601: node visit number freq value and subtree size size value are increased to the node of binary search tree, original
Left and right increases by two subtree pointers on each node of binary search tree, and there are six attributes for tool altogether for such a node, comprising:
Keyword key, other information value, the total number size of node, access times freq, left subtree left and right subtree
right。
S602: during the node checks of binary search tree, 1 is added to the access times of the node found.It utilizes
Keyword key is searched, and is begun looking for from the root node of binary search tree, and the key and key to be found of present node are passed through
Comparison, when the key of present node is equal with key to be found, indicate present node be exactly node to be found, this
When 1 is added to the access times of current node.
S603: according to the access times freq value of father's node and left subtree node or right subtree node, judge whether into
The adjustment of the node of row binary search tree.It is recorded using the increase of the access times in step S102, compares present node conduct
With the size of the access times of left subtree or the node of right subtree when father's node, judge whether the tune for needing to carry out node location
It is whole.
S604: if the value of present node is less than the value of node to be found, sub-tree search of turning right, if the access time of father's node
Number is less than the access times of right subtree node, then is interchangeable the position of two nodes.The value of present node is less than to be found
Value, value to be found is indicated in the right subtree of present node, when the access times of father's node are less than right subtree node
Access times adjust the position of two nodes, are interchangeable.
S605: if the value of present node is greater than the value of node to be found, sub-tree search of turning left, if the access time of father's node
Number is less than the access times of left subtree node, then is interchangeable the position of two nodes.The value of present node is less than to be found
Value, value to be found is indicated in the right subtree of present node, when the access times of father's node are less than right subtree node
Access times adjust the position of two nodes, are interchangeable.
By increasing each node the record of access times, recycling access times are adjusted the position of node,
The past position close to root node of node more than access times is mobile, the search efficiency for the node frequently inquired is improved in this way,
It carries out that required information can be inquired faster during data retrieval, is greatly improved the data inspection of whole system
The efficiency of rope improves more times with common database retrieval processing, while the process encoded is also very succinct, is applicable in various answer
Use scene.
The embodiment of the present invention further relates to a kind of computer readable storage medium, is stored thereon with one or more computer journeys
Sequence, one or more computer programs are subsequently can by computer the method implemented when device executes above.The computer program includes
Program code for method shown in execution flow chart.It should be noted that the computer-readable medium of the application can be
Computer-readable signal media or computer-readable medium either the two any combination.
As shown in fig. 7, showing a kind of searching system of data rank according to the present invention, which includes data record
Unit 1, data query judging unit 2, ranking searching unit 3 and node updates unit 4.
In the particular embodiment, data record unit 1 is used to increase subtree size size to the node of binary search tree
Value and node visit number freq value, and subtree size size value and node visit number freq value are recorded.By right
The record of size value and access times freq, data retrieval and node updates to binary search tree provide data basis, guarantee
The data accuracy of binary search tree.
In the particular embodiment, data query judging unit 2 is used to judge the key and key to be found of present node
Size relation.It is compared by key value of the inquiry judging unit to the node of binary search tree, judges key to be found
With the size relation of present node, to obtain the location information of key to be found, the object of lookup required for capable of quickly positioning
Position, improve effectiveness of retrieval.
In the particular embodiment, ranking searching unit 3 is for looking into ranking rank according to the key to be found
It askes, if the key of the present node and key's to be found is equal in magnitude, the ranking rank x of the key to be found
It is looked into if the present node key is less than the key to be found to right subtree direction equal to rank-Node.left.size
It looks for, the ranking of the minimum node of the right subtree node of the present node is equal to rank-1-Node.left.size, until searching
Until the key to be found, if the present node key is greater than the key to be found, searched to left subtree direction, row
Name is constant, until finding the key to be found.It can be calculated by the number of node using ranking searching unit 3, directly
Obtain the object searched ranking information, improve the efficiency of data retrieval, while also ensuring the accurate of ranking information
Property.
In the particular embodiment, node updates unit 4 is used to the node more than access times moving closer to root node
Position, if the access times of present node be less than right subtree node access times, present node and right subtree node position
It is replaced, if the access times of present node are less than the access times of left subtree node, present node and left subtree section
Point position is replaced, and is also configured in carrying out position replacement to present node and left subtree or right subtree node according to access times
While, the corresponding child node of left subtree or right subtree is adjusted by the traversal order of former binary search tree, is updated simultaneously
The corresponding size of node.It is adjusted using node of the updating unit to binary search tree, it can be the node more than access times
The position of root node is moved closer to as far as possible, is improved the search efficiency for the node frequently inquired, is made entire binary search tree
Recall precision be greatly improved.
The data processing of binary search tree according to the present invention a kind of, data rank search method and system, using pair
The node of binary tree increases by two attributes of key and freq, according to the access times freq value of node to the node of binary search tree
It is adjusted, the node more than access times freq is mobile toward root node, so that effectiveness of retrieval has been obtained great promotion, simultaneously
It can use the ranking that key value quickly positions object, and after the process of data retrieval, node be adjusted,
Search complete each time is all updated access times and node, and whole system is made to be maintained at optimal retrieval data basis
On, efficiently carry out retrieval work.
Obviously, those skilled in the art can make to the present invention without departing from the spirit and scope of the present invention
Embodiment various modifications and change.In this manner, if these modifications and changes be in claim of the invention and its
In the range of equivalent form, then the present invention, which also aims to, covers these modifications and changes.Word " comprising " is not excluded for not wanting in right
The presence for the other element or steps listed in asking.The simple thing that certain measures are recorded in mutually different dependent claims
It is real not show that the combination of these measures is consequently not used for making a profit.Any appended drawing reference in claim should not be regarded as limited to
Range.
Claims (14)
1. a kind of search method of data rank, which comprises the following steps:
S101: subtree size size and access times freq is increased to binary search tree, and initializes the key institute to be checked
Ranking rank=Root.size, and present node is set to root node and starts to retrieve;
S102: judge the size relation of the key and the key to be found of present node;
S103: if the key of the present node and key's to be found equal in magnitude, the ranking of the key to be found
Rank x is equal to rank-Node.left.size, while adding 1 to the access times of the present node;
S104: it if the present node key is less than the key to be found, is searched to right subtree direction, ranking rises, i.e. institute
The rank value for stating the minimum node in present node right subtree direction is that rank R is equal to rank-1-Node.left.size, up to
After the completion of lookup, if the access times of the present node are less than the access times of right subtree node, the present node
It is replaced with the right subtree node location;
S105: if the present node key is greater than the key to be found, searching to left subtree direction, and ranking is constant, until
After the completion of lookup, if the access times of the present node are less than the access times of left subtree node, the present node
It is replaced with the left subtree node location;
Wherein, the key value indicates that the integral of user, the Node.left.size indicate the present node left subtree node
Number, the Root.size indicate all node total numbers of binary search tree.
2. a kind of search method of data rank according to claim 1, which is characterized in that the step S104 and described
In step S105, after finding the key to be found, recall step by step, using access times to the present node with
The position of the left subtree or the right subtree node is replaced.
3. a kind of search method of data rank according to claim 1, which is characterized in that described in the step S104
Rank value is being successively decreased into the right subtree search procedure with the variation of the present node, and the value subtracted works as prosthomere to be described
Point left subtree number adds 1.
4. a kind of search method of data rank according to claim 1, which is characterized in that the method also includes following
Step:
S106: repeating step S105 described in the step S102-, until the present node key is equal to described to be checked
Key or the present node are leaf node.
5. a kind of search method of data rank according to claim 3, which is characterized in that the step S104 and described
While step S105 replaces the present node and the left subtree node or the right subtree node location, looked by former y-bend
Look for traversal of tree sequence to the position of the child node of the present node and the left subtree node or the right subtree node into
Row adjustment, while the corresponding size of node for updating the adjustment.
6. a kind of search method of data rank according to claim 1, which is characterized in that the method also includes following
Step:
The information that the object is searched according to the ranking rank of the object judges the present node left subtree number and size
Size relation;
If the present node left subtree number and the size's is equal in magnitude, the information of the present node is described right
The information of elephant, while 1 is added to the access times of the present node;
If the present node left subtree number is less than the size, the Object node is in the right subtree, the object
Position is size-1-Node.left.size, when the access times of the present node are less than the access times of right subtree node,
The present node and the right subtree node location are replaced;
If the present node left subtree number is greater than the size, the Object node is in the left subtree, the size
It is constant, when the access times of the present node are less than the access times of left subtree node, the present node and the left side
It is replaced children tree nodes position;
Wherein, size is the number of nodes of the object left subtree of the rank, initializes size=Root.size-rank.
7. a kind of search method of data rank according to claim 1, which is characterized in that the method also includes to institute
State the step of binary search number carries out node updates, the step of node updates specifically includes addition node and deletion of node
Step.
8. a kind of search method of data rank according to claim 5, which is characterized in that the step of the addition node
It specifically includes: being found by key greater than the key and without left subtree node or less than the key and not no right subtree
Node carries out creating new node, and traces back to root node step by step, updates size and adds 1.
9. a kind of search method of data rank according to claim 5, which is characterized in that the step of the deletion of node
It specifically includes: the node for needing to delete is found by key, the node to be deleted is rotated to leaf section by rotation node
Point, is deleted, and dates back root node step by step, is updated size and is subtracted 1.
10. a kind of data processing method using binary search tree, which comprises the following steps:
S601: node visit number freq value is increased to the node of binary search tree;
S602: during the node checks of binary search tree, 1 is added to the access times of the node found;
S603: according to the access times freq value of father's node and left subtree node or right subtree node, institute is judged whether to
State the adjustment of the node of binary search tree;
S604: if the value of the present node is less than the value of the node to be found, sub-tree search of turning right, if father's node
Access times be less than the right subtree node access times, then the position of described two nodes is interchangeable;
S605: if the value of the present node is greater than the value of the node to be found, sub-tree search of turning left, if father's node
Access times be less than the left subtree node access times, then the position of described two nodes is interchangeable.
11. a kind of method of data processing for binary search tree according to claim 9, which is characterized in that according to
While the access times carry out position replacement to father's node and the left subtree or the right subtree node, to institute
The corresponding child node for stating left subtree or the right subtree and father's node is adjusted by the traversal order of former binary search tree
It is whole.
12. a kind of method of data processing for binary search tree according to claim 9, which is characterized in that described
Method is further comprising the steps of, repeating said steps S603-S605, until the present node becomes leaf node.
13. a kind of computer readable storage medium is stored thereon with one or more computer programs, which is characterized in that this one or
Multiple computer programs, which are subsequently can by computer when device executes, implements method described in any one of any one of claims 1 to 11 11.
14. a kind of searching system of data rank, which is characterized in that the system comprises:
Data record unit increases subtree size size value and node visit number freq value to the node of binary search tree, and
The subtree size size value and the node visit number freq value are recorded;
Data query judging unit, the size relation of key and the key to be found for judging the present node;
Ranking searching unit, for being inquired according to the key to be found ranking rank, if the key of the present node
Equal in magnitude with the key to be found, the ranking rank x of the key to be found is equal to rank-
Node.left.size;
If the present node key is less than the key to be found, searched to right subtree direction, the right son of the present node
The ranking of the minimum node of tree node is equal to rank-1-Node.left.size, until finding the key to be found;
If the present node key is greater than the key to be found, searched to left subtree direction, ranking is constant, until finding
Until the key to be found;
Node updates unit, for the node more than access times to be moved closer to the position of root node;
When the access times of the present node are less than the access times of right subtree node, the present node and the right side
It is replaced children tree nodes position;
When the access times of the present node are less than the access times of left subtree node, the present node and the left side
It is replaced children tree nodes position;
It also configures in carrying out position to the present node and the left subtree or the right subtree node according to the access times
While setting replacement, the traversal order for pressing former binary search tree to the corresponding child node of the left subtree or the right subtree is carried out
Adjustment.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811613883.8A CN109815232B (en) | 2018-12-27 | 2018-12-27 | Method and system for retrieving and processing data ranking by using binary search tree |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811613883.8A CN109815232B (en) | 2018-12-27 | 2018-12-27 | Method and system for retrieving and processing data ranking by using binary search tree |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109815232A true CN109815232A (en) | 2019-05-28 |
CN109815232B CN109815232B (en) | 2022-03-18 |
Family
ID=66602551
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811613883.8A Active CN109815232B (en) | 2018-12-27 | 2018-12-27 | Method and system for retrieving and processing data ranking by using binary search tree |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109815232B (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110413228A (en) * | 2019-07-09 | 2019-11-05 | 江苏芯盛智能科技有限公司 | A kind of mapping table management method, system and electronic equipment and storage medium |
CN111367947A (en) * | 2020-03-09 | 2020-07-03 | 北京奇艺世纪科技有限公司 | Information retrieval method and device, electronic equipment and storage medium |
CN113449003A (en) * | 2021-07-07 | 2021-09-28 | 京东科技控股股份有限公司 | Information query method and device, electronic equipment and medium |
CN113535171A (en) * | 2021-07-23 | 2021-10-22 | 上海米哈游璃月科技有限公司 | Information searching method, device, equipment and storage medium |
CN116107932A (en) * | 2023-04-13 | 2023-05-12 | 摩尔线程智能科技(北京)有限责任公司 | Data queue updating method and device, storage medium and electronic equipment |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20100070457A1 (en) * | 2008-09-16 | 2010-03-18 | Arun Kejariwal | Efficient Data Layout Techniques for Fast Machine Learning-Based Document Ranking |
CN102315979A (en) * | 2010-07-05 | 2012-01-11 | 国讯新创软件技术有限公司 | Method and device for monitoring network flow |
CN104036531A (en) * | 2014-06-16 | 2014-09-10 | 西安交通大学 | Information hiding method based on vector quantization and bintree |
CN105512320A (en) * | 2015-12-18 | 2016-04-20 | 北京金山安全软件有限公司 | User ranking obtaining method and device and server |
CN106294545A (en) * | 2016-07-22 | 2017-01-04 | 中国农业银行股份有限公司 | The access method of a kind of tree structure data and device |
-
2018
- 2018-12-27 CN CN201811613883.8A patent/CN109815232B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20100070457A1 (en) * | 2008-09-16 | 2010-03-18 | Arun Kejariwal | Efficient Data Layout Techniques for Fast Machine Learning-Based Document Ranking |
CN102315979A (en) * | 2010-07-05 | 2012-01-11 | 国讯新创软件技术有限公司 | Method and device for monitoring network flow |
CN104036531A (en) * | 2014-06-16 | 2014-09-10 | 西安交通大学 | Information hiding method based on vector quantization and bintree |
CN105512320A (en) * | 2015-12-18 | 2016-04-20 | 北京金山安全软件有限公司 | User ranking obtaining method and device and server |
CN106294545A (en) * | 2016-07-22 | 2017-01-04 | 中国农业银行股份有限公司 | The access method of a kind of tree structure data and device |
Non-Patent Citations (1)
Title |
---|
马博韬等: ""红黑树算法研究综述"", 《网络新媒体技术》 * |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110413228A (en) * | 2019-07-09 | 2019-11-05 | 江苏芯盛智能科技有限公司 | A kind of mapping table management method, system and electronic equipment and storage medium |
CN110413228B (en) * | 2019-07-09 | 2022-10-14 | 江苏芯盛智能科技有限公司 | Mapping table management method and system, electronic equipment and storage medium |
CN111367947A (en) * | 2020-03-09 | 2020-07-03 | 北京奇艺世纪科技有限公司 | Information retrieval method and device, electronic equipment and storage medium |
CN113449003A (en) * | 2021-07-07 | 2021-09-28 | 京东科技控股股份有限公司 | Information query method and device, electronic equipment and medium |
CN113449003B (en) * | 2021-07-07 | 2024-04-16 | 京东科技控股股份有限公司 | Information query method, device, electronic equipment and medium |
CN113535171A (en) * | 2021-07-23 | 2021-10-22 | 上海米哈游璃月科技有限公司 | Information searching method, device, equipment and storage medium |
CN113535171B (en) * | 2021-07-23 | 2024-03-08 | 上海米哈游璃月科技有限公司 | Information searching method, device, equipment and storage medium |
CN116107932A (en) * | 2023-04-13 | 2023-05-12 | 摩尔线程智能科技(北京)有限责任公司 | Data queue updating method and device, storage medium and electronic equipment |
Also Published As
Publication number | Publication date |
---|---|
CN109815232B (en) | 2022-03-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109815232A (en) | A kind of method and system of retrieval, the data processing of the data rank using binary search tree | |
US9454599B2 (en) | Automatic definition of entity collections | |
CN108920716B (en) | Data retrieval and visualization system and method based on knowledge graph | |
Raimond et al. | Automatic Interlinking of Music Datasets on the Semantic Web. | |
US20100106713A1 (en) | Method for performing efficient similarity search | |
CN104598647B (en) | A kind of tree graph search and the method for matching article | |
CN102023989A (en) | Information retrieval method and system thereof | |
CN103608812A (en) | Query optimization techniques for business intelligence systems | |
JP2004518226A (en) | Database system and query optimizer | |
US20150100605A1 (en) | Determining collection membership in a data graph | |
KR20090028758A (en) | Methods and apparatus for reusing data access and presentation elements | |
CN113535788B (en) | Ocean environment data-oriented retrieval method, system, equipment and medium | |
CN106227788A (en) | Database query method based on Lucene | |
CN101833568A (en) | Web data management system | |
CN108829651A (en) | A kind of method, apparatus of document treatment, terminal device and storage medium | |
CN110795526B (en) | Mathematical formula index creating method and system for retrieval system | |
Bleifuß et al. | DBChEx: Interactive Exploration of Data and Schema Change. | |
Zheng et al. | Searching activity trajectory with keywords | |
CN110263108B (en) | Keyword Skyline fuzzy query method and system based on road network | |
CN111782663A (en) | Aggregation index structure and aggregation index method for improving aggregation query efficiency | |
CN109460467B (en) | Method for constructing network information classification system | |
CN113360496B (en) | Method and device for constructing metadata tag library | |
CN104537047A (en) | Garment basic sample plate retrieval system based on Lucene | |
CN106682129B (en) | Hierarchical concept vectorization increment processing method in personal big data management | |
CN107273464B (en) | Distributed measurement similarity query processing method based on publish/subscribe mode |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |