是否有高效(log n)数据结构,可以开展以下工作:
- Return the smallest element that is greater or equal to a given key
- Exchange this element with a smaller one and rearrange the structure accordingly
元素的数量是众所周知的,在寿命期间不会改变。
是否有高效(log n)数据结构,可以开展以下工作:
元素的数量是众所周知的,在寿命期间不会改变。
您可执行balanced binarymoto 。 Red-Black大树
一家红黑树有O(log(n))时间复杂,用于搜索、插入和删除。
你们必须作一些修改,以归还最小的、大于或等于特定关键因素。 但这一数据结构是由我猜测的。
回答后,你可以使用双双双向树。 该法典可能有所帮助。
首先,你们必须找到树中的 no子。
private Node<Key, Value> find (Node<Key, Value> node, Key key){
if (node == null) return null;
int comp = comparator.compare(key, node.key);
if (comp < 0) return find(node.left, key);
else if(comp > 0) return find(node.right, key);
else return node;
}
既然我们有 no子,我们就应当找到最小的钥匙,但比起关键点更重要或更平等,这意味着,如果 no子有权利的话,那将是一个更大的关键,但如果右 no不成,我们就必须归还钥匙。
private Node<Key, Value> min(Node<Key, Value> node){
if (node.left == null) return node;
else return min(node.left);
}
public Key ceiling(Key key){
Node<Key, Value> node = find(root, key);
if (node.right == null) return node.key;
return min(node.right).key;
}
您询问的第二个项目是在你去除儿童身上的 no子时发生的,因此,它涉及他权利子女的小孩,并插入他的位置。
private Node<Key, Value> remove(Node<Key, Value> node, Key key){
if (node == null){
throw new NoSuchElementException();
}
int comp = comparator.compare(key, node.key);
if (comp > 0) node.right = remove(node.right, key);
else if (comp < 0) node.left = remove(node.left, key);
else{ //Found the node to remove
if (node.right == null) return node.left; //Does not have right child. (if even does not have left child return null)
else if (node.left == null) return node.right; //Does not have left child.
else{ //Has right and left children
Node<Key, Value> lower = min(node.right); //The lower node of its right child node
node.key = lower.key;
node.value = lower.value;
remove(node.right, lower.key); //Remove the lower node that remains in the tree
}
}
return node;
}
How to implement a double linked list with only one pointer? It takes O(1) time to find the prev and next Node. struct Node { int val; Node* p; };
Currently we are filtering and sorting data with a datatable. /// <summary> /// Filters the data table and returns a new data table with only the filtered rows. /// </summary>...
How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...
I need to store a 2d matrix containing zip codes and the distance in km between each one of them. My client has an application that calculates the distances which are then stored in an Excel file. ...
According to various sources, such as Wikipedia and various .edu websites found by Google, the most common ways for a hash table to resolve collisions are linear or quadratic probing and chaining. ...
I have an ASP.NET web application and I want to be able to take items from a master list and store them temporarliy into one of four other lists. The other lists need to survive post backs so that ...
I am a new student in the compilers world ^_^ and I want to know is legal represent negative number in the stack. For example: infix: 1-5=-4 postfix: 15- The statements are: push(1) push(5) x=...
I am trying to figure out what type of structure or container I should use for a quick project. I need to have an unknown number of sets that will be entered from the GUI (each one will have a name, ...