Special training [JavaSE (arrays and lists)]

A topic

A.方便运算

B.方便存储

C.提高运算速度

D.减少存储空间

Analysis: Option D

AC, all aspects of computing benefits

B, if the adjacency list, but also keep a pointer, and no convenient storage

D, regardless of adjacency matrix or adjacency list are saving space

 

Topic two



正确

错误

Analysis: correct

Investigation of the matrix (the lower half of the triangle portion) are sequentially added element according to the elements of each row of the array, the required number of elements in front A64.

A00

A01 A11

……

...... A64

The calculation of the number of columns: 1 + 0 + 2 + 3 + 4 + 5 + 6 + 5 elements, 25 elements as a result, the A64 corresponding to M [25].

 

Topic three


A.BA+141

B.BA+180

C.BA+222

D.BA+225

 Analysis: Option A

Note that the array is start counting from 1. (4 * 10 + 7) = 141 * 3

 

Title four



A.4

B.5

C.9

D.10

Analysis: Option A

strlen (str) required length of the string is encountered \ 0 is the end of the calculation, not \ 0, and starts counting from one. 1234 \ 0 so that a length of 4.

 

Title five



A.s 和 p 完全相同

B.数组 s 中的内容和指针变量 p 中的内容相等

C.s 数组长度和 p 所指向的字符串长度相等

D.*p 和 s[0]值相等


Analysis: Option D

A wrong, * p is a pointer, the pointer to the string and is a different concept;

B wrong, s is the value of the contents of the array "china" Fu, p is char pointer should point to an object of type char address, i.e. the address of s

C uncertain, but it sounds like a wrong bit, said earlier, there may be an array of length s is 6 (comprising a terminator '\ 0') length of the string, p is 5 points, it may be point p just a character, the length is 1? ?

D affirmed matter, * p is to take the contents of the address pointed ---- char 'c', s [0] means that it is the first character 'c'.

 

Title six



A.没区别

B.行优先快

C.列优先快

D.2种读取方式速度为随机值,无法判断

 Analysis: Option B

If the array is large, then it should be row-fast, because the array is a row-priority stored in memory, in a virtual memory environment, if the entire array is not the words in memory may be longer than the column of priority to reduce the number of memory to be swapped out. Even if the entire array in memory, column-major access a [i] [j] have calculated a multiplication, just add a line of priority on it, this can be ignored.

 

Title seven



A.120

B.150

C.100

D.80

 Analysis: Option B

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20

Like the above table, each grid can be said to be a rectangle, when the operator is seeking a combination of these sides:

Take two edges vertically, C (6,2). Sideways to take the two edges C (5,2)

So the result is: C (6,2) * C (5,2) = 15 * 10 = 150 

 

Title eight



A.j=r[j].next

B.j=j+1

C.j=j->next

D.j=r[j]->next

   

Analysis: Option A

First, a list of the next node with the next pointer to be accessed, B negative

The current node is r [j], may be excluded C

r [j] is not the current node pointer to the current node, thus using r [j] .next

 

 Nine topics



A.数组从栈中分配空间,链表从堆中分配空间

B.数组插入或删除元素的时间复杂度O(n),链表的时间复杂度O(1)

C.数组利用下标定位,时间复杂度为O(1),链表定位元素时间复杂度O(n)

D.对于add和remove,ArrayList要比LinkedList快

Analysis: ABC election

To say that there is an array of ambiguity, static array is opened in the stack memory, the list is generally allocated on the heap space, except for a static list

 

Title ten



A.原地逆序

B.头部插入

C.返回中间节点

D.返回头部节点

E.选择随机节点

Parsing: ACE

A option, if the array is half as long as the traversing element on it, flipping idea is similar string in reverse, but if you want to complete the list in reverse order, even if only modify pointer also put all the elements traversed, so the contrast or array faster than a linked list.

Just insert a linked list node B, for an array of n elements move

Access intermediate node C options array by array [length / 2] access, the linked list to find the intermediate node sequentially.

The first node are the same D

E is a linear array of sequentially stored in the table, with respect to the list in terms of the main advantages is the subscript can be any element by the random access array.

 

Title eleven



180

720

120

540

 

Analysis: Option A

Simple probabilistic

First of all there are 6 positions

First row N, U 6 * 5 = 30 kinds

Then row Y, Y has only four pit 3 * 4/2 = 6 kinds

The last two positions to the O, O, so a total of 6 * 30 = 180 kinds.

 

Twelve topics



16902

16904

14454

以上答案均不对

 

Analysis: Option A

The first 58 elements of line 32 is represented as a [32,58], but we used to write a [31] [57]

First, a two-dimensional array can be represented as A [60] [70] (60 rows 70 columns)

a[   31,57   ]

In order main column: (57 * 60 + 31) * 2 + 10000 = 16902

In the main line sequence: (70 + 31 * 57) + 10000 = 14454 * 2

 

Topic thirteen



xyz123ABC

z123ABC

xy123ABC

出错

 

Analysis: Option D

Original code is wrong : p1 and p2 point to the string constant, the constant region, it can not be operated; arrays can be changed, but when the array with a string initialized to remember the array length plus 1, because the default string the end of a '\ 0'; the second point to note is that, p1 strcat function have sufficient space to accommodate the length of the string connection p1 and p2.

The following code can be modified to:

char p1[7] = "123";

char p2[] = "ABC";

char str[50] = "xyz";

strcpy(str + 2, strcat(p1, p2));

printf("%s\n", str);

result:

 

Topic fourteen



"I love this game"

"I love thi"

"I love"

"I"

Analysis: Option D

Spaces will encounter the input cin end, it is generally used as the input string getline (including spaces)

 

Topic fifteen



O(1)

O(log2n)

O(n)

O(n^2)

 Analysis: Option C

We use the first plug-in or plug the end of formula create lists need only traverse cycle can be achieved, the time complexity is O (n)

Linear table is the most basic, the simplest and most commonly used data structures. A linear relationship between the tables is one to one relationship between data elements, i.e. in addition to the first and last data element, other data elements are connected end to end (note that most of these words only for the linear form , but not all. For example, on the circulation list logical hierarchy table is also a linear (chain stores belonging to the storage hierarchy), but the tail pointer points to the last data element of the first node).

List is a physical memory cell non-continuous, non-sequential storage structure , the logical order of the data elements is achieved by the link pointer in the linked list order. Chain by a series of nodes (each node element is called a linked list), with the node can be dynamically generated at runtime. Each node consists of two parts: a data field storing data elements, and the other is stored under a node address pointer field. Compared to a linear sequence structure table, a linked list insert and delete operations more convenient

 

Topic sixteen



对

错

Analysis: Option B

An array of suitable storage structures and for full binary tree complete binary tree.

 

Topic seventeen



n-i,n-i+1

n-i+1,n-i

n-i,n-i

n-i+1,n-i+1

 Analysis: Option A

Delete the i-th elements: (i-1 is the i-th element)

0, ... i-1, i, ... n-1: the number of elements moving in i ~ n-1 = n-1-i + 1 = ni

I-th element before insertion elements: (i-1 is the i-th element)

0, ..., i-1, i, ..., n-1: the mobile number of elements i-1 ~ n-1 in = n-1- (i-1) + 1 = n-i + 1

 

Topic eighteen



8 100

100 8

100 100

8 8

 Analysis: Option A

string_a is a char-pointer, a 64-bit system, sizeof (char *) = 8

string_b is a char-array, a 64-bit system, sizeof (char) = 1, therefore the value of a total of 100 100

 

Topic nineteen



(rear-front+m)%m

rear-front+1

(front-rear+m)%m

(rear-front)%m

 Analysis: Option A

The number of elements in the circular queue calculation is fixed, i.e. (Tail - Head)% of the length, but since it is a circular queue may be less than the end of the head, so to add the length of the tail - the head holder is a positive integer, and then to the length of the remainder, i.e., the number of elements

The relevant conditions and formulas circular queue: 
the tail pointer is rear, is a head-front, which is the maximum length QueueSize circular queue 
1. Empty Team conditions: REAR == Front 
2. Team full condition: (rear + 1)% QueueSIze Front == 
3. calculating queue length: (+ REAR-Front QueueSize)% QueueSize 
4. enqueue: (+ REAR. 1)% QueueSize 
5. the dequeue: (front + 1)% QueueSize

 

Topic twenty



a [] ="abcdefg";

a="abedefg";

*p="abcdefg";

p="abcdefg ";

 Analysis: Option D

The string assigned to an array of characters: ****************************************** when a string directly assigned **** 1. definitions. char a [10] = "hello"; define but not by assignment, i.e., the following illegal: char a [10]; a [10] = "hello"; ************** ******************************** 2. Using strcpy. char a [10]; strcpy (a, "hello"); *********************************** 3. *********** with the pointer. char * p; p = "hello"; here, the first letter of the string returned pointer address assigned to p. In addition the following illegal: char a [10]; a = "hello"; a point already allocated in the stack 10 character spaces, can point to the data area "hello" constant. Can be understood as an address is a constant, not variable, p is a variable address. 4. The array ********************************************** characters one by one assignment.

 

Topic twenty-one



11

12

13

14

 Analysis: election c

Huffman tree is also called optimal binary tree, the bigger weights closer the point of the root, cause the entire tree right minimum value

Method: Select the minimum value as the point about two nodes, as a parent node, and then, sequentially selects the smallest two points and the configuration of the rest of the parent node, Huffman tree is formed

Left value is 0, the right is 1

Huffman coding is to add the minimum value of the respective points

It is calculated by multiplying the value of the length of the path length of the respective points together

Example a (3), b (2), l (1), i (1)

Length is 3 (l + i) + 2b + 1a; abli put into their corresponding 3211 is 13

 

 

Topic twenty-two



[(j-1)*n+i-1]*d

[(j-1)*n+i]*d

[(j-1)*n+i+1]*d

[(j-1)*n+i-2]*d

 Analysis: Option A

11      
21 22    
31 32 33  
41 42 43 44
1      
2 3    
4 5 6  
7 8 9 10

For the above A4x4 matrix, the first matrix index that identifies the matrix, the second matrix corresponding to the identified position of the target element in the matrix should be kept in a one-dimensional array, one-dimensional array stored triangle is [0,10] , so that d = 1

For A [(j-1) * n + i-1] * d, the result calculated by the priority order of the column: 0,1,5,2,6,10,3,7,11,15;

For B [(j-1) * n + i] * d, the result calculated by the priority order of the column: 1,2,6,3,7,11,4,8,12,16;

For C [(j-1) * n + i + 1] * d, the result calculated by the priority order of the column: 2,3,7,4,8,12,5,9,13,17;

For D [(j-1) * n + i-2] * d, the result calculated by the priority order of the column: -1,0,4,1,5,9,2,6,10,14;

So the actual answer be [i * (i-1) / 2 + j] * d

 

Topic twenty-three



i*m+j

j*m+i

i*m+j-1

i*m+j+1

Parsing: D

The difference between the target position and a lower, index starts from 0, 1 starts from the position

Directly to a [0] [0] is substituted, i.e., i = 0, j = 0. Only i * m + j + 1 = 1

 

Topic twenty-four



每次分区后,先处理较短的部分

每次分区后,先处理较长的部分

与算法每次分区后的处理顺序无关

以上三者都不对

 Analysis: Option A

In the quick sort, it is necessary to process a recursive left sub-segment, respectively, to be understood that the depth of recursion depth saved system stack, the first processing segment reprocessing short length segment, the time complexity can be reduced;

If you press long recursive priority, then the short recursion will remain in the stack until the completion of a long process. Short priority, then, no longer recursive calls, as a whole, he is saved on the stack, so less recursion stack of recursive data retention.

 

Topic twenty-five



int ch<='9'  '0'

char   ch<='9'  '0'

char   ch<='9'  0

int ch<='9'  0

 Analysis: election AB

This problem is not rigorous, AB output all right. Anyway, have to do type conversion, it does not matter which comparative advantage

A, returns the char, so if the conditions which do implicit type conversions: int char converted into digital

B, return int, then when assigning the main char variables do type conversion, int turn char

1

2

3

4

5

6

int fun(char ch)

{

    if(ch>='0'&& ch<='9')

        return'9'-(ch-'0');

    return ch;

}

 

Topic twenty-six



drop table book;

truncate table book;

delete from book;

del *from book;

Analytical: AD election

A: drop table book is to delete the entire table, subject potential meant to delete the data in the table rather than delete the entire table. A therefore wrong.
B: truncate table book is to delete the data in the table, delete faster than delete, can not withdraw (rollback).
C: delete from book delete data in the data table, you can rewind, you can add where clause.
D: syntax error.

 

Topic twenty-eight



find

gzip

grep

sort

Analysis: Option C

grep command is a powerful text search tool, you can use a regular expression search text, and print out the matching rows. grep stands for Global Regular Expression Print, represents the global regular expression version, its usage rights for all users. find only match a single character.

 

Topic twenty-nine



LOC(A[0][0])+(i*m+j)

LOC(A[0][0])+(i*n+j)

LOC(A[0][0])+[(i-1)*n+j-1]

LOC(A[0][0])+[(i-1)*m+j-1]

Analysis: Option B

The priority line is first stored row, the first row of the first memory of n, then the second row, the n, it is b

 

Topic thirty



scanf("%s", str);

str[] = getch();

gets(str);

str = gets();

Analysis: Option C

gets (name or character array pointer)

gets to accept spaces, tabs and carriage return Tab.

and sacnf function gets, after the automatic receiving the string '\ 0'

scanf can not enter spaces

 

Topic thirty-one



数组和链表都可以随机访问

数组的插入和删除可以 O(1)

哈希表没有办法做范围检查

以上说法都不正确

Analysis: Option B

An array of static memory allocation, linked lists dynamically allocated memory;

An array of continuous, discontinuous linked list in memory;

Array elements in the stack area, the list of elements in the heap area;

Using array subscripts positioning, time complexity is O (1), the positioning element list time complexity O (n);

Insert or delete the element array time complexity of O (n), the list of time complexity O (1).

 

Topic thirty-two



对

错

 Analysis: Option B

Generalized non-empty elements of the table or is an integral atom, or a generalized non-empty table, note appreciated that the subject elements may be generalized table is empty.

 

 

 

 

                 ......................... continuously updated in

Published 31 original articles · won praise 1 · views 1274

Guess you like

Origin blog.csdn.net/qq_45824565/article/details/104433089