Some data structures and algorithms
1. Assume that the execution time of statement S is O (1), then execute the following program for a short time ()
For (I = 1; I <= N; I ++)
For (j = I; j <= N; j ++)
S;
A.o (N)
B .o (N2)
C. O (N * I)
D. O (n + 1)
2.
Two-digit array a [10... 20, 5... 10] data is stored in the primary order. Each Data Element occupies 4 storage units. The storage address of a [10] [5] is 1000, then the address of a [18] [9] is ()
A.m. 1208
B. 1212
C. 1368
D. 1364.
3.
If the maximum stack length is 3 and the inbound stack sequence is 1, 2, 3, 4, 5, 6, it is impossible to obtain that the stack sequence is ()
A. 1, 2, 3, 4, 5, 6
B. 2, 1, 3, 4, 5, 6
C. 3, 4, 2, 1, 5, 6
D .,
4. There are 98 sorted sequence elements. The maximum number of comparisons is () When binary lookup is used ()
A. 49
B. 15
C. 20
D. 7
5.
Hash indicates an effective data structure used for data storage. The search complexity of Hash tables depends on the validity of the Hash value algorithm. In the best case, the query complexity of Hash tables is ()
A.o (1)
B .o (logn)
C. O (n)
D. O (nlogn)
Part 2 Software Engineering
1. Software Capability Maturity Model CMM is divided into () Maturity level
A. 3
B. 4
C. 5
D. 6
2.
Tests can be divided into black box tests and white box tests based on whether you understand the internal structure of the software. Consider the PDL statement of the following algorithm. If you want to perform a white box test with full path coverage, you need () paths.
Do ehile records remain
Read record;
If record field 1 = 0
Then process record;
Store in buffer;
Increment counter;
Elseif record field 2 = 0
Then reset counter;
Else process record;
Store in file;
Endif
Endif
Enddo
A. 4
B. 5
C. 6
D. 7
3.
According to the stages of the waterfall model, software testing can be divided into unit testing, integration testing, and system testing. Which of the following tests does not belong to the system test ()
A. Stress Testing
B. Interface Test
C. Function Testing
D. Security Testing
E. Performance Testing
4. The design of test cases is an important stage of testing. When should the system test case be designed ()
A. Requirement completion
B. Complete the detailed design
C. Complete Encoding
D. Submit the system for testing after system integration is completed.
5.
In the UML method, multiple types of graphs are used to help design. Which of the following figures are not UML graphics types ()
A. Class Diagram
B. Object relationship diagram
C. Sequence Diagram
D. activity diagram
Part 3 Java language and others
1. Which of the following is the short value range :()
A.-27 --- 27-1
B .0 --- 216-1
C.-215 --- 215-1
D.-231---231-1
2. Which of the following is an invalid identifier :()
A. $ persons
B. TwoUsers
C. * point
D. _ endline
3. If float x = 1, y = 2, Z = 3, the value of the expression y + = z --/+ + X is ()
A.m. 3.5
B. 3
C. 4
D. 5
4. Which of the following keywords can be used for local variable modification or class variable modification ()
A. Public
B. Transient
C. Static
D. Finally
5. How many Java objects are constructed using the following statements? ()
String S = new string ("AAA ");
A. 1
B. 2
C. 3
6. Which of the following statements are true ()
A. Equals () method determines whether the reference value points to the same object
B. = operator determines whether the content and type of two different objects are consistent
C. Equal () method returns true only when the content of the two objects is consistent.
D. Class file Rewriting Method equals () returns true when the content and type of two different objects are consistent.
7.
If an object only declares that the cloneable interface is implemented, but does not declare the clone method, can the external system call its clone method? ()
A. Yes
B. No
C. Uncertainty
8.
In the C/S structure, if the server accepts and Processes requests, which of the following statements about the server's request processing mode is false ()
A. in single-threaded mode, the server uses a single thread to process all requests, which may cause blocking.
B.
The server can create a thread for each request to process the request, which is more stable than the single-thread mode.
C.
In Thread Pool Mode, when the maximum number of threads is used and no threads are available in the thread pool, the server will block or reject the processing of a request.
9.
When Swing is used as the interface, if a JButton is placed in a JFrame, which layout manager should be used if the height of the JButton is affected and the width is not affected when the JFrame is changed? ()
A. FlowLayout
B. CardLayout
C. North and South of BorderLayout
D. East and West of BorderLayout
E. GridLayout
10. The following state is owned by EntityBean, while StatelessBean does not ()
A. Pool state
B. Readiness
C. nonexistent state
D. passive state
11. Which of the following statements about the database paradigm are false ()
A. if multiple data items are represented as A field using A large String, the first paradigm is not satisfied.
B. Meet the database paradigm to make the database more efficient
C. If a higher paradigm is satisfied, the lower-level paradigm must be satisfied first.
D. The second paradigm of the database requires that all data in the table that is not directly related to all keys be split into other tables.
12.
Consider the requirements: including information about students, courses, and instructors. The student information includes the Student name and age address. The course information includes the course number, course name, and course credits. The instructor information includes the teacher's name and address. A student can take multiple courses, and multiple students can take multiple optional courses. A teacher can teach multiple courses, and each course can be taught by multiple teachers. If you use relational databases and meet the requirements of the second paradigm, You need to design a table ().
A. 3
B. 4
C. 5
D. 6
13.
To speed up database search, you need to add indexes to the data table. Which of the following statements about indexes are false ()
A. in the clustering index, the physical order of the row in the table is the same as the logical order of the index key value.
B. Using indexes will reduce the efficiency of data update.
C. In most database systems, each table can have only one clustering index.
D. Consider this SQL statement: Select S. name, S. age from Student S where
S. address = "Chengdu". If we create a composite index (age, address) for the Student table, the efficiency of the preceding query can be improved.
Part 4 Q &
1. Briefly describe the main processes and functions of a Linux driver.
2. Please list an example of time-for-space or space-for-time in the software.
3. Briefly describe the differences between processes and threads.
4. What is the purpose of static? (Please specify at least two types)
5. What is the use of ifndef/define/endif in the header file?
6. What will the program output?
Char * RetMenory (void)
{
Char p [] = "hellow world ";
Return p;
}
Void Test (void)
{
Char * str = NULL;
Str = RetMemory ();
Printf (str );
}
7. What is the difference between reference and pointer?
8. Describe the basic features of the Real-Time System
9. Are global variables and local variables different in memory? If so, what is the difference?
10. What is a balanced binary tree?
11. What causes stack overflow?
12. What functions cannot be declared as virtual functions?
13. What is the time complexity of the bubble sort algorithm?
14. What is the difference between # include <filename. h> and # include "filename. h?
15. Write the if statement for comparing float x with "zero value.
16. What are the Process Scheduling Policies in the operating system?
17. What network protocol does the Internet use? What is the main hierarchy of the protocol?
18. What protocol does the physical and IP address translation use for the Internet?
19. What are the IP address encoding components?
Write a program that requires the function: Calculate the sum of the three numbers in different combinations with 1, 2, 5 and 100.
For example, the first 100 is a combination, and the fifth one and the 19th five are a combination .... Please use C ++.
Answer: The easiest algorithm to come up with is:
Set x to the number of 1, y to the number of 2, z to the number of 5, and number to the combination.
Note that 0 <= x <=, 0 <= y <= 50, 0 <= z = 20, so you can program it:
Number = 0;
For (x = 0; x <= 100; x ++)
For (y = 0; y <= 50; y ++)
For (z = 0; z <= 20; z ++)
If (x + 2 * y + 5 * z) = 100)
Number ++;
Cout <number <endl;
The above program has to cycle 100*50*20 times in total, and the efficiency is too low.
In fact, this question is an obvious mathematical problem, not simply a programming problem. My solution is as follows:
Because x + 2y + 5z = 100
So x + 2y = 100-5z, and z <= 20 x <= 100 y <= 50
So (x + 2y) <= 100, and (x + 5z) is an even number
Perform a loop on z. The possible values of x are as follows:
Z = 0, x = 100, 98, 96,... 0
Z = 1, x = 95, 93,..., 1
Z = 2, x = 90, 88,..., 0
Z = 3, x = 85, 83,..., 1
Z = 4, x = 80, 78,..., 0
......
Z = 19, x = 5, 3, 1
Z = 20, x = 0
Therefore, the total number of combinations is an even number less than 100 + an odd number less than 95 + an even number less than 90 + an odd number less than... + 5 + 1,
That is:
(51 + 48) + (46 + 43) + (41 + 38) + (36 + 33) + (31 + 28) + (26 + 23) + (21 + 18) + (16 + 13) + (11 + 8) + (6 + 3) + 1
The number of even numbers (including 0) within an even m can be expressed as m/2 + 1 = (m + 2)/2
An odd number within an odd m can also be expressed as (m + 2)/2
Therefore, the total number of combinations can be programmed as follows:
Number = 0;
For (int m = 0; m <= 100; m + = 5)
{
Number + = (m + 2)/2;
}
Cout <number <endl;
This program only needs to loop 21 times and two variables to get the answer, which is much more efficient than the above program.
Double ---- just because of some simple mathematical analysis
This once again proves that the computer program = Data Structure + algorithm, and the algorithm is the soul of the program.
When the software is used to implement the current situation, you must select the resource limits, user requirements, and development time limits that meet the current requirements.
The optimal algorithm under the specified conditions. Instead, you must use the easiest algorithm to compile a program immediately.
This is not the behavior of a professional R & D personnel.
So, isn't that easy-to-think algorithm completely useless? No, this algorithm can be used to verify the new algorithm.
In the debugging phase, this is very useful. In many large companies, such as Microsoft, this method is adopted:
In the trial phase, some important programs that require good algorithms are implemented. When such good algorithms are complex
It is easy to think of algorithms to verify this program. If the results of the two algorithms are inconsistent (and the algorithm that is most likely to come up
Is correct), it indicates that the optimization algorithm has a problem and needs to be modified.
For example:
# Ifdef debug
Int simple ();
# End if
Int optimize ();
......
In a function:
{
Result = optimize ();
Assert (result = simple ());
}
In this way, in the debugging phase, if the results of the simple algorithm and the optimization algorithm are inconsistent, the assertion will be played. At the same time
But does not contain bulky simple () functions. -- Any large-scale engineering software must be designed in advance.
Good debugging means, and here we mention a useful method.
A student's information is: name, student ID, gender, age, and other information. Use a linked list to link these student information,
Give an age, and delete the student information whose age is equal to age in some linked lists.
# Include "stdio. h"
# Include "conio. h"
Struct stu {
Char name [20];
Char sex;
Int no;
Int age;
Struct stu * next;
} * Linklist;
Struct stu * creatlist (int n)
{
Int I;
// H indicates the first node, p indicates the previous node, and s indicates the current node.
Struct stu * h, * p, * s;
H = (struct stu *) malloc (sizeof (struct stu ));
H-> next = NULL;
P = h;
For (I = 0; I <n; I ++)
{
S = (struct stu *) malloc (sizeof (struct stu ));
P-> next = s;
Printf ("Please input the information of the student: name sex no age \ n ");
Scanf ("% s % c % d", s-> name, & s-> sex, & s-> no, & s-> age );
S-> next = NULL;
P = s;
}
Printf ("Create successful! ");
Return (h );
}
Void deletelist (struct stu * s, int)
{
Struct stu * p;
While (s-> age! =)
{
P = s;
S = s-> next;
}
If (s = NULL)
Printf ("The record is not exist .");
Else
{
P-> next = s-> next;
Printf ("Delete successful! ");
}
}
Void display (struct stu * s)
{
S = s-> next;
While (s! = NULL)
{
Printf ("% s % c % d \ n", s-> name, s-> sex, s-> no, s-> age );
S = s-> next;
}
}
Int main ()
{
Struct stu * s;
Int n, age;
Printf ("Please input the length of seqlist: \ n ");
Scanf ("% d", & n );
S = creatlist (n );
Display (s );
Printf ("Please input the age: \ n ");
Scanf ("% d", & age );
Deletelist (s, age );
Display (s );
Return 0;
}
2. Implement a function to convert the characters in a string from small to uppercase.
# Include "stdio. h"
# Include "conio. h"
Void uppers (char * s, char * us)
{
For (; * s! = '\ 0'; s ++, us ++)
{
If (* s> = 'A' & * s <= 'Z ')
* Us = * s-32;
Else
* Us = * s;
}
* Us = '\ 0 ';
}
Int main ()
{
Char * s, * us;
Char ss [20];
Printf ("Please input a string: \ n ");
Scanf ("% s", ss );
S = ss;
Uppers (s, us );
Printf ("The result is: \ n % s \ n", us );
Getch ();
}
Enter a random number to determine whether it is a symmetric number (the number of input files) (such as 3,121,123 ). String library functions cannot be used.
/*************************************** ************************
1.
Function Name: wannry
Function: determines the number of input files (, 35653)
Input: Number of long integers
Output: If the return value is 1 esle 0
**************************************** **************************/
Unsigned char handle ry (long n)
{
Long I, temp;
I = n; temp = 0;
While (I) // No need to see the length problem, change the number to a high or low bit
{
Temp = temp * 10 + I % 10;
I/= 10;
}
Return (temp = n );
}
Method 1
/*
---------------------------------------------------------------------------
Function:
Determines whether the string is a return number.
Implementation:
First, convert the string to a positive integer, and then combine the positive integers in reverse order into a new positive integer.
Input:
Char * s: string to be judged
Output:
None
Return Value:
0: Correct; 1: the string to be judged is empty; 2: the string to be judged is not a number;
3: the string is not a return number; 4: the string to be judged overflows.
----------------------------------------------------------------------------
*/
Unsigned IsSymmetry (char * s)
{
Char * p = s;
Long nNumber = 0;
Long n = 0;
Long nTemp = 0;
/* Determine whether the input is empty */
If (* s = \ '\ 0 \')
Return 1;
/* Convert the string to a positive integer */
While (* p! = \ '\ 0 \')
{
/* Determine whether the character is a number */
If (* P <\ '0 \ '| * P> \ '9 \')
Return 2;
/* Determine whether a positive integer overflows */
If (* P-\ '0 \ ')> (4294967295-(nNumber * 10 )))
Return 4;
NNumber = (* P-\ '0 \ ') + (nNumber * 10 );
P ++;
}
/* Combine the numbers in reverse order and directly copy the code of the Experts upstairs. No exception */
N = nNumber;
While (N)
{
/* Determine whether a positive integer overflows */
If (n % 10)> (4294967295-(ntemp * 10 )))
Return 3;
Ntemp = ntemp * 10 + N % 10;
N/= 10;
}
/* Compare whether the inverse number is equal to the original number */
If (nNumber! = Ntemp)
Return 3;
Return 0;
}
Method 2
/*
---------------------------------------------------------------------------
Function:
Determines whether the string is a return number.
Implementation:
First obtain the length of the string, and then compare whether the corresponding characters of the string are the same
Input:
Char * s: string to be judged
Output:
None
Return Value:
0: Correct; 1: the string to be judged is empty; 2: the string to be judged is not a number;
3: the string is not a return number.
----------------------------------------------------------------------------
*/
Unsigned IsSymmetry_2 (char * s)
{
Char * p = s;
Int nLen = 0;
Int I = 0;
/* Determine whether the input is empty */
If (* s = \ '\ 0 \')
Return 1;
/* Get the string length */
While (* p! = \ '\ 0 \')
{
/* Determine whether the character is a number */
If (* p <\ '0 \ '| * p> \ '9 \')
Return 2;
NLen ++;
P ++;
}
/* The length is not an odd number or a return number */
If (nLen % 2 = 0)
Return 4;
/* The length is 1, that is, the return number */
If (nLen = 1)
Return 0;
/* Compare whether the corresponding characters are the same in sequence */
P = s;
I = nLen/2-1;
While (I)
{
If (* (p + I )! = * (P + nLen-i-1 ))
Return 3;
I --;
}
Return 0;
}
2 ~ 2000 of all prime numbers. There is enough memory and the requirement is as fast as possible
Answer:
Int findvalue [2000] = {2 };
Static int find = 1;
Bool adjust (int value)
{
Assert (value> = 2 );
If (value = 2) return true;
For (int I = 0; I <= find; I ++)
{
If (value % findvalue [I] = 0)
Return false;
}
Findvalue [find ++];
Return true;
}
1. printf output problems
Printf ("% d", total); // This is right
Printf (total); // This is wrong
Printf ("hello"); // but this is right
2. Length of Integer type
Char 1 subsection, 8 digits
Unsigned short [int]
[Signed] short int
Short 2 bytes, 16 bits
[Signed] int
Unsigned int
The Int type contains four subsegments in VC, which are 32-bit, 16-bit, and 2 bytes.
Long [int]
Unsigned long [int]
The long type is both 32-bit and 4-byte.
Float 32, 4
Double 64, 8
Long double, 16
Char 8, a byte, stores the ASCII code of the characters.
3. Locate and correct the error
Char * my_cpy (char * SRC, int Len ){
Char Dest [1024];
Memcpy (DEST, SRC, Len );
Return DEST;
}
Is there a problem with the above function? If it is pointed out, if not, the function description is provided.
Answer:
1. Array should be initialized
2. Memcpy does not determine whether the request is out of bounds. Therefore, we should determine whether the request is out of bounds before calling.
3. Rest should not be returned, because this array is applied within the function, so the function will disappear after it ends, and the pointer will also become a "Wild Pointer", so it points to an Invalid Address
Last relatively hidden
Char * memcpy (char * DEST, const char * SRC, int Len)
{
Char * pdest = (char *) DEST;
Char * psrc = (char *) SRC;
Int Pos;
For (Pos = 0; POS {
Pdest [POS] = psrc [POS];
}
Return (char *) pdest;
}
The local problem is that the pointer is not determined to be illegal assert (DEST! = NULL | SRC! = NULL); condition is
Flase display
Write a memcpy function without calling other functions. The function prototype is
Void * memcpy (void * DEST, void * SRC, size_t length );
----------- Make good use of assertions ---------
/* Memcpy ── copy memory blocks that do not overlap */
Void memcpy (void * pvto, void * pvfrom, size_t size)
{
Void * pbto = (byte *) pvto;
Void * pbFrom = (byte *) pvFrom;
ASSERT (pvTo! = NULL & pvFrom! = NULL );
/* Does the memory block overlap? If they overlap, use memmove */
ASSERT (pbTo> = pbFrom + size | pbFrom> = pbTo + size );
While (size --> 0)
* PbTo ++ = * pbFrom ++;
Return (pvTo );
}
-----------------------
Common Function programming:
Char * strcpy (char * strDest, const char * strSrc)
{
ASSERT (strDest! = NULL & strSrc! = NULL );
Char * addr = strDest;
While (* strDest ++ = * strSrc ++)
NULL; // NULL can be omitted, but it is more conducive to compiler error discovery.
}
Return addr;
}
Void * memcpy (void * dest, const void * src, int count)
{
ASSERT (dest! = NULL & src! = NULL );
For (int I = 0; I <cout; I ++)
{
Dest [I] = SRC [I];
}
}
Int strcmp (const char * str1, const char * str2)
{
While (str1! = NULL & str2! = NULL)
{
If (* str1 <* str2) Return-1;
Else if (* str1> * str2) return 1;
Else {str1 ++; str2 ++ ;}
}
If (str1 = NULL & str2! = NULL)
Return-1;
Else if (str1! = NULL & str2 = NULL)
Return 1;
Else return 0;
}
// Way2: more compact
Int strcmp (const char * str1, const char * str2)
{
Int I = strlen (str1 );
Int J;
For (j = 0; j <= I; j ++)
{
If (str1 [J]> str2 [J]) return 1; // If str2 terminates, then str2 [J] = 0,
Str1 [J]> str2 [J], return 1;
Else if (str1 [J] <str2 [J]) Return-1;
Else if (str1 [J] = '\ 0') return 0;
}
}
// Way3: optimize again.
Int strcmp (const char * str1, const char * str2)
{
While (1)
{
If (* str1> * str2) return 1;
Else if (* str1 <* str2) Return-1;
Else if (* str1 = '\ 0') return 0;
Str1 ++; str2 ++;
}
}