-
It's detailed. public class test ;
Iterate through the array. for (int i = 0; i < 1;) to define the number of counters for a platform.
int count = 1;
Compare each element after the i with the i element.
for (int j = i + 1;j
if (j == - 1) {
i = j;
If it is equal, it means that it is a platform and the counter is +1
if (b[i] == b[j])
count++;
If it's not a platform, J is the new element, assign J to I, and stop this loop.
else {
i = j;
break;
Each time the same is given to the tree for comparison, and the larger one is copied to numif (num < count).
num = count;;
-
I don't know if there are other prerequisites for your question, this should be said to be the worst, and the insertion point is in the middle of the existing n, at this time it is at most n-1 times, if it is n ordered keywords, use sequential search, do not limit any conditions, then find the insertion point at least 1 time, compare at most n times, of course, if the ordered sequence is stored sequentially, looking for this insertion point can be found in half, and the best and worst average of the number of comparisons becomes log2n.
-
In addition to selecting the top element of the pile, it is also necessary to ensure that the root of all subtrees meets the standard of the heap (the root is the smallest of the three nodes (small top heap, descending) and the largest (large top heap, ascending)). The heap adjustment is a top-down sequence in a basically ordered state. At this point, it's all you need.
-
Because of o(n 2), for single-linked lists, some fast sorting algorithms cannot be used, and can only be directly inserted into the o(n 2) level sorting algorithm to achieve answer sorting. Because it is an ordered single-linked list, then every time it is inserted into the end of the linked list, then each insertion must be swept from the beginning to the end, and then 1+2+3+.m = o(m2) like this.
An ordered linked list is a rule that arranges data in a node in an orderly manner, such as incrementing, decreasing, or other rules that meet certain conditions, starting from the head node to the end of the linked list. A one-way linked list (single-linked list) is a type of linked list, which is characterized by the fact that the link direction of the linked list is one-way, and the access to the linked list starts from the head through sequential reading; A linked list is a list constructed using pointers; It is also known as a node list, because a linked list is assembled from individual nodes; Each node has a pointer member variable that points to the next node in the list;
A list is made up of nodes, with the head pointer pointing to the first node that becomes the header node and ending with the last pointer to null.
-
Only one auxiliary space is needed, which can be named temp, to record the value of the root node on the binary tree of the current operation, and compare it with the left and right child nodes, such as the large top stack, if the temp is less than the value of the left and right child nodes, then do further operations such as swapping, and also need to use recursive thinking.
-
Landlord,There is no doubt that the time complexity of the stack is logn,So why is the time complexity of the pile not logn?,It's very simple,When you build the pile, you see if you call the function of the stack many times.,It's definitely not just logn.,If you start building the pile from the last parent node at the bottom,Then we can roughly calculate:
If there are n nodes, then the height is h=logn, and each parent node of the last layer only needs to be lowered by 1 time at most, the penultimate layer only needs to be lowered by 2 times at most, and the vertex needs to be lowered by h times at most, and the parent node of the last layer has 2 (h-1), and the penultimate layer has 2 (h-2), and the vertex is only 1 (2 0), so the total time complexity is s = 1 * 2 (h-1) +2 * 2 (h-2) +h-1) *2 1 + h * 2 0
After substituting h into s = 2n - 2 - log2(n), the approximate time complexity is o(n).
-
When you build the pile, you see if you call the stacking function many times, then it must not be just logn, if you start the stack from the last parent node at the bottom, then we can roughly calculate:
If there are n nodes, then the height is h=logn, each parent node of the last layer only needs to be lowered by 1 time at most, the penultimate layer only needs to be lowered by 2 times at most, and the vertices need to be lowered by h times at most, and the parent nodes of the last layer have 2 (h-1), and the penultimate layer has 2 (h-2), and there are only 1 (2 0) vertices, so the total time complexity is s = 1 * 2 (h-1) +2 * 2 (h-2) +h-1) *2 1 + h * 2 0 After substituting h, s= 2n - 2 - log2(n), the approximate time complexity is o(n).
Heapsort refers to a sorting algorithm designed by using the data structure of heap tree (heap), which is a kind of selection sorting. You can use the characteristics of arrays to quickly locate the elements of a specified index. The heap is divided into large root heaps and small root heaps, which are complete binary trees.
The requirement of the large root heap is that the value of each node is not greater than the value of its parent node, i.e. a[parent[i]] = a[i]. In the non-descending sorting of arrays, the big root heap needs to be used, because according to the requirements of the big root heap, the largest value must be at the top of the heap.
Robert W Floyd and J Williams, winners of the 1991 Computer Pioneer Award and professors in the Department of Computer Science at Stanford University, co-invented the famous Heap sort algorithm in 1964
Heap sorting makes it easy to pick the record with the largest (or smallest) keyword in the current unordered area, taking advantage of the fact that the top record of the large root heap (or small root heap) is the largest (or smallest) keyword.
-
In addition to selecting the top elements of the heap, it is necessary to ensure that the root of all subtrees meets the criteria of the heap (the root is the smallest of the three nodes (small top heap, descending) and the largest (large top heap, ascending)).
Heap adjustment is a top-down sequence in a largely ordered state. In this case, you only need to pay attention to whether the branches on the top-down movement path still meet the criteria of the heap after the swap.
There is a significant difference between the two processes, and the natural time complexity is different.
-
When two numbers are entered, the output result of any two numbers is jolly, and the title says that any sequence that contains only a single element must have an "interesting jump", but it does not say that any two numbers are "interesting jumps".
When i=1 (second cycle), if (b[i-1]-b[i]!=1&&i>1) is best written as if (i>1&&b[i-1]-b[i]!=1) This form, because I think that when you mean i<=1, you meet the condition of "interesting jump", so you don't need to judge b[i-1]-b[i]!
1 is true or false, but according to your original formulation, when i = 1 ten, b[i-1]-b[i]!The truth of =1 is to be judged, and when you judge it, you also access an uninitialized space---b[i-1], when i=1, b[i-1]=b[0], b[0], you are not initialized in the program, it is a random value.
Hope, thank you!
-
a。(In the heap.)
If the original record is close to positive order or reverse order, then the dao heap sort is used, and if the original record is out of order, it is best to use fast sort
C is wrong. The original problem of c is that in the following sorting method, the time complexity is not affected by the initial state of the data, and it is always o(n2) that is directly selected to sort
-
I obviously answered the proof of the o(n) complexity of the process, so how could I jump to this question.
-
The purpose of the heap is to make sure that the root node is the largest or smallest (as you want) and that all nodes with children are larger or smaller (as you want).
n 2: It means that there are n 2 or n 2+1 nodes, and these nodes have children, and the complete binary tree has this rule.
The reason for reverse order is to make sure that all the children are compared to the parent node, otherwise how do you make sure that the root node meets the requirements? His children are still changing.
Finally, your question is a bit wrong: (n 2, 0] or [n 2, 0] depends on whether it is divisible or not.
-
First of all, the heap sorting is aimed at an array that does not meet the characteristics of the largest heap at all (no elements are placed in the 0 position), first of all, we must start by adjusting each non-leaf node from back to front (that is, the penultimate layer), this is used to build the heap (that is, let the wrong regularity become a certain regularity), if you ignore another large branch tree from front to back, a path goes black, and the heap cannot be established correctly; The reason why the back can be adjusted from front to back is that only the top one has been replaced, and the other branches are all satisfied with the largest heap.
void heap_sort(int *list, int n)}
-
First of all, there are two ways to sort the heap and build the pile. sinking method and floating method; From [n, 1] you need to use the swim method to float, if [n 2, 1] you need to use the sink method; Starting from n 2, using the sinking method, when the nth 2nd position is determined, the positions of the two child nodes n and n+1 are also determined, so only half of the elements of the array need to be compared; If you take the swim method, you need to iterate through the array entirely;
Comparatively speaking, of course, the sink is used as the sorting method. For suggestions, please refer to the content of the priority queue in Chapter 2 of the Sedgewick Algorithm.
-
If you want to get the smallest first k elements in a sequence containing n elements, it is best to use what sorting algorithm is heap sorting.
Heap sorting is a sorting algorithm designed by using heap data structure, heap sorting is a kind of selective sorting, the average time complexity is O(nlogn), and the heap sorting is unstable.
Heap sorting is a complete binary tree with the following properties: the value of each node of the large top pile is greater than or equal to the value of its left and right child nodes, or the value of each node of the small top pile is less than or equal to the value of its left and right child nodes.
-
Heap sorting.
It takes n 2 sinking operations to build the pile, and k sinking operations are required to extract the smallest k elements, and the complexity is less than o (n + klogn).
If the space is sufficient, cardinality sorting can be used, and the complexity is o(n).
-
Bubbling sort, this one is the most commonly used.
As a professional who has worked for 5 years, I don't know if I am an old driver, but I hope it can be of some use. I believe that most of the newcomers are full of vigor and want to show their strength and open up a world in the workplace, and the newcomers will also read some books that talk about the rules of the workplace, learn some less talk and more things, and report diligently, which is of course very good, but what I want to say is that there are many kinds of enterprises, and there are different cultures between enterprises, different departments also have their own style of doing things, and the boss's work habits are not the same. Quickly integrate into the environment. Carefully experience the company's corporate culture, the working atmosphere of the department, the general working habits of the colleagues around you, and the work style of the boss, you must quickly learn these unspoken rules to integrate into the collective, rather than becoming an outlier. >>>More
It's called New Balance
The top running shoe brand in the United States, one of the four major jogging shoe brands in the world, is higher grade than Nike. >>>More
What kind of antivirus software do you use? Kill with Rising. Analyze it with 360.
It seems that I see a lot of anonymous questioners asking questions about my brother, dear, are they all you? If so, I won't go through them all. >>>More
Water is made up of H20 molecules - What is the matter with ions CO2 is made up of CO2 molecules Where do C4+ ions O2- ions come from? If sulfurous acid is generated in the reaction, it will generally become SO2+H2O, you know what the reaction produces, you are a junior high school, and you do not have high requirements for redox reactions, which generally does not need you to judge.