If there are less than 20 inversions in an integer array, then Insertion Sort will be the best method among Quick Sort, Heap Sort and Insertion Sort. (3分)
For a sequentially stored linear list of length , the time complexities for query and insertion are and , respectively. (3分)
In a binary search tree, the keys on the same level from left to right must be in sorted (non-decreasing) order. (3分)
and have the same speed of growth. (3分)
If keys are pushed onto a stack in the order {1, 2, 3, 4, 5}, then it is impossible to obtain the output sequence {3, 4, 1, 2, 5}. (3分)
For the quicksort implementation with the left pointer stops at an element with the same key as the pivot during the partitioning, but the right pointer does not stop in a similar case, what is the running time when all keys are equal? (5分)
Given a quadtree(四叉树) with 3 nodes of degree 2, 2 nodes of degree 3, 4 nodes of degree 4. The number of leaf nodes in this tree is __. (5分)
The result of performing three DeleteMin operations in the min-heap {1,3,2,6,7,5,4,15,14,12,9,10,11,13,8} is: (5分)
Given input { 110, 119, 7, 911, 114, 120, 122 }. Which one of the following is the result after the 2nd run of the Least Signification Digit (LSD) radix sort? (5分)
The recurrent equations for the time complexities of programs P1 and P2 are:
Then the correct conclusion about their time complexities is: (5分)
For an in-order threaded binary tree, if the pre-order and in-order traversal sequences are B E A C F D
and A E C B D F
respectively, which pair of nodes' left links are both threads? (4分)
Suppose that an array of size m
is used to store a circular queue. If the front position is front
and the current size is size
, then the rear element must be at: (5分)
To sort { 49, 38, 65, 97, 76, 13, 27, 50 } in increasing order, which of the following is the result after the 1st run of Shell sort with the initial increment 4? (5分)
Insert { 3, 8, 9, 1, 2, 6 } one by one into an initially empty binary search tree. The post-order traversal sequence of the resulting tree is: (5分)
In-order traversal of a binary tree can be done iteratively. Given the stack operation sequence as the following:
push(1), push(2), push(3), pop(), push(4), pop(), pop(), push(5), pop(), pop(), push(6), pop()
Which one of the following statements is TRUE? (5分)
Among the following sorting methods, which ones will be slowed down if we store the elements in a linked structure instead of a sequential structure? (5分)
In a complete binary tree with 1102 nodes, there must be __ leaf nodes. (5分)
To delete p
from a doubly linked list, we must do: (5分)
The function is to sort the list { r[1] … r[n]
} in non-decreasing order. Unlike selection sort which places only the minimum unsorted element in its correct position, this algorithm finds both the minimum and the maximum unsorted elements and places them into their final positions.
void sort( list r[], int n )
{
int i, j, mini, maxi;
for (i=1; i<n-i+1; i++) {
mini = maxi = i;
for( j=i+1; (3分); ++j ){
if( (3分) ) mini = j;
else if(r[j]->key > r[maxi]->key) maxi = j;
}
if( mini != i ) swap(&r[mini], &r[i]);
if( maxi != n-i+1 ){
if( (3分) ) swap(&r[mini], &r[n-i+1]);
else swap(&r[maxi], &r[n-i+1]);
}
}
}
序号 | 结果 | 得分 |
---|---|---|
0 | 答案正确 | 3 |
1 | 答案正确 | 3 |
2 | 答案正确 | 3 |
The function is to find the K
-th smallest element in a list A
of N
elements. The function BuildMaxHeap(H, K)
is to arrange elements H[1]
... H[K]
into a max-heap. Please complete the following program.
ElementType FindKthSmallest ( int A[], int N, int K )
{ /* it is assumed that K<=N */
ElementType *H;
int i, next, child;
H = (ElementType *)malloc((K+1)*sizeof(ElementType));
for ( i=1; i<=K; i++ ) H[i] = A[i-1];
BuildMaxHeap(H, K);
for ( next=K; next<N; next++ ) {
H[0] = A[next];
if ( H[0] < H[1] ) {
for ( i=1; i*2<=K; i=child ) {
child = i*2;
if ( child!=K && (3分) ) child++;
if ( (3分) )
H[i] = H[child];
else break;
}
H[i] = H[0];
}
}
return H[1];
}
序号 | 结果 | 得分 |
---|---|---|
0 | 答案正确 | 3 |
1 | 答案正确 | 3 |
You are supposed to output, in decreasing order, all the elements no less than X
in a binary search tree T
.
void Print_NLT( Tree T, int X );
where Tree
is defined as the following:
typedef struct TreeNode *Tree;
struct TreeNode {
int Element;
Tree Left;
Tree Right;
};
The function is supposed to use Output(X)
to print X
.
#include <stdio.h>
#include <stdlib.h>
typedef struct TreeNode *Tree;
struct TreeNode {
int Element;
Tree Left;
Tree Right;
};
Tree BuildTree(); /* details omitted */
void Output( int X ); /* details omitted */
void Print_NLT( Tree T, int X );
int main()
{
Tree T;
int X;
T = BuildTree();
scanf("%d", &X);
Print_NLT( T, X );
printf("End\n");
return 0;
}
/* Your function will be put here */
92 91 90 85 81 80 End
End
int array[10000]; int cnt=0; void Print_NLT( Tree T, int X ){ Inorder(T); int i; for(i=0;i<cnt;i++){ if(array[i]>=X) break; } for(int j=cnt-1;j>=i;j--) Output(array[j]); return; } void Inorder(Tree T){ if(!T) return; Inorder(T->Left); array[cnt++]=T->Element; Inorder(T->Right); }
a.c: In function ‘Print_NLT’: a.c:63:5: warning: implicit declaration of function ‘Inorder’ [-Wimplicit-function-declaration] Inorder(T); ^~~~~~~ a.c: At top level: a.c:72:6: warning: conflicting types for ‘Inorder’ void Inorder(Tree T){ ^~~~~~~ a.c:63:5: note: previous implicit declaration of ‘Inorder’ was here Inorder(T); ^~~~~~~ a.c: In function ‘BuildTree’: a.c:33:6: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^~~~~~~~~~~~~~~ a.c:35:10: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &x); ^~~~~~~~~~~~~~~ a.c: In function ‘main’: a.c:52:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &X); ^~~~~~~~~~~~~~~
测试点 | 结果 | 得分 | 耗时 | 内存 |
---|---|---|---|---|
0 | 答案正确 | 2 | 20.00 ms | 204 KB |
1 | 答案正确 | 1 | 24.00 ms | 328 KB |
2 | 答案正确 | 1 | 8.00 ms | 212 KB |
3 | 答案正确 | 1 | 10.00 ms | 200 KB |
4 | 答案正确 | 1 | 12.00 ms | 204 KB |