1. stack and queue features a common feature (only elements can be inserted and deleted at the endpoint) 4. the two storage structures used by the stack Are (linear Storage Structure and linked list storage structure. which of the following statements about stack is true? (D). stack is a non-linear structure B. stack is a tree structure C. stack has the first-in-first-out feature D. stack has the following features. the chain table does not have the characteristics of (B). you do not have to estimate the storage space in advance. B. random Access to any element C. insert and delete elements that do not need to be moved D. the required space is proportional to the length of the linear table. the advantage of using a linked list to represent a linear table is (easy to insert or delete) 8. in a single-chain table, the purpose of adding a header node is (to facilitate the implementation of operations) 9. the main advantage of circular linked list is that (the entire linked list can be accessed from any node in the table) 10. linear table L = (a1, a2, a3 ,...... Ai ,...... An), which of the following statements is true? (D). each element has a direct front and direct back. B. A linear table must contain at least one element C. the order of the elements in the table must be from small to large or from large to small D. except for the first and last elements, each element has one and only one direct front and one direct back. if A linear table uses A chained storage structure, the address (D). must be continuous B. some addresses must be consecutive C. it must be discontinuous D. continuous discontinuous values can be 12. the sequential storage structure of linear tables and the chain storage structure of linear tables are respectively (random access storage structure and sequential access storage structure) 13. A tree is a collection of nodes. The number of root nodes is (and only 1). 14. in a full binary tree with a depth of 5, the number of leaf nodes is (31) 15. binary Trees with three knots have (5 forms) 16. if a binary tree has three leaf nodes and eight knots with a degree of 1, the total number of knots in the binary tree is (13) 17. it is known that the binary tree's post-order traversal sequence is dabec, the middle-order traversal sequence is debac, and its pre-order traversal sequence is (ce Dba) 18. if ABDEGCFH and DBGEACHF are known as the forward and central traversal of a binary tree, the backward traversal of the binary tree is (DGEBHFCA) 19. if a binary tree uses abdgcefh as its forward traversal access order and dgbaechf as its central traversal access order, then the node access order for the subsequent traversal is (gdbehfca) 20. database protection includes security control, Integrity Control, concurrency control, and data recovery.
1. in computers, algorithms refer to (accurate and complete descriptions of solutions) 2. among the following options, which of the following is NOT the basic feature (infinity) that an algorithm should possess: feasibility, certainty, poverty, and sufficient intelligence. 3. which control structures can be used for algorithms? 4. the time complexity of an algorithm is (the number of basic operations required during Algorithm Execution) 5. the space complexity of the algorithm refers to (the storage space required during execution) 6. the purpose of algorithm analysis is (to improve the efficiency of analysis algorithms) 7. which of the following statements is true? (c). the algorithm execution efficiency is independent of the data storage structure. B. the spatial complexity of an algorithm refers to the number of commands (or statements) in an algorithm program. the urgency of an algorithm means that the algorithm must be able to terminate after a finite step. the time complexity of an algorithm is the time required to execute an algorithm program. as a computer discipline, data structure mainly studies the logical structure of data, operations on various data structures, and (Data Storage Structure) 9. in the data structure, what is irrelevant to the used computer is data (c). storage Structure B. physical Structure C. logical Structure D. physical and storage structure 10. which of the following statements is false? (B). the data storage structure is closely related to the efficiency of data processing B. the data storage structure has nothing to do with the efficiency of data processing. C. data Storage The space occupied by the storage structure in the computer is not necessarily continuous d. A logical structure of data can have multiple storage structures 11. the data storage structure refers to (the logical structure of the data is expressed in the computer) 12. the logical structure of data refers to (the data structure that reflects the logical relationship between data elements) 13. according to the complexity of the relationship between the front and back parts of each data element in the data structure, the data structure is generally divided into (linear structure and nonlinear structure) 14. which of the following data structures has the memory function? (c). queue B. cyclic queue C. stack D. sequence Table 15. (B). linear Linked List B. stack C. circular linked list D. sequence Table 16. recursive Algorithms are generally implemented using queues. 17. which of the following statements about stack is true? (d). data can only be inserted into the stack. the stack can only delete data c. stack is a first-in-first-out linear table D. stack is an advanced linear table 20. the advantage of sharing a bucket by two stacks is (saving storage space and reducing the probability of overflow) 21. when an application needs to output data through a printer during execution, a print job is usually first formed and stored in a specified (Queue) in the hard disk. When the printer is idle, the job to be printed will be taken out of the service first. 22. which of the following statements about queues is true? (c). only data can be inserted in the queue. only data in the queue can be deleted. A queue is a first-in-first-out linear table D. A queue is an advanced linear table.
23. which of the following statements is true? (D). the position of each element in the linear linked list must be continuous B. the Header element in the linear linked list must be stored in front of other elements. the position of each element in the linear linked list in the bucket is not necessarily continuous, but the Header element must be stored before other elements. the position of each element in the linear linked list in the bucket is not necessarily consecutive, and the storage order of each element is arbitrary. which of the following statements is true? (A). linear table is linear structure B. stack and queue are non-linear structures C. linear Linked List is a non-linear structure D. binary Tree is a linear structure 25. linear table L = (a1, a2, a3 ,...... Ai ,...... An), which of the following statements is true? (D). each element has a direct front and direct back. B. A linear table must contain at least one element C. the order of the elements in the table must be from small to large or from large to small D. except the first element and the last element, each other element has one and only one direct front and direct back. 26. if a linear table uses a chained storage structure, the address of the available storage units in the memory is required (continuous continuity is acceptable) 27. the chain table does not have the characteristics of (B). you do not have to estimate the storage space in advance. B. random Access to any element C. insert and delete elements that do not need to be moved D. the required space is proportional to the length of the linear table. 28. the End Node of the head of a non-empty cyclic single-chain table (pointed by p), meeting (p-> next = head) 29. compared with a one-way linked list, one of the advantages of a two-way linked list is (easier to access adjacent nodes) 30. in (D), as long as you point out the location of any node in the table, you can access all the other nodes in the table from it. A. linear Single-chain table B. two-way linked list C. linear Linked List D. circular linked list 31. the following data structure is A non-linear data structure (C). queue B. linear Table C. binary Tree D. stack 32. A tree is a collection of nodes. Its root node number is (and only 1) 33. binary Trees with three knots (five forms) 34. the maximum number of knots in layer 8th on a binary tree is (128). Note: 2K-135. in a full binary tree with a depth of 5, the number of leaf nodes is (16). Note: 2n-136. in the full binary tree with a depth of 5, there are (31) nodes. Note: 2n-232. if a Complete Binary Tree has a total of 699 nodes, the number of leaf nodes in the binary tree is (350). Note: The number of total points in the Complete Binary Tree is N. If N is an odd number, the number of leaf knots is (N + 1)/2. If N is an even number, the number of leaf knots is N/2. 38. the following binary tree is set. The result of the sequential traversal of this binary tree is (B). abcdef B. DBEAFCC. abdecf d. DEBFCA39. it is known that the binary tree's post-order traversal sequence is dabec, and the middle-order traversal sequence is debac. Its pre-order traversal sequence is (cedba) 40. if ABDEGCFH and DBGEACHF are known as the forward and central traversal of a binary tree, then the backward traversal of the binary tree is (DGEBHFCA) 41. if the access order of a binary tree is abdgcefh and that of dgbaechf, the access order of the nodes in the subsequent traversal is (gdbehfca)
42. the length of a string is (the number of characters contained in the string) 43. there are two strings, p and q. Calculate the computation name (pattern matching) for the first occurrence of q in p 44. the number of edges in the connected graph of N vertices must at least be (N-1) 45. the number of edges of a strongly connected graph with N vertices must be at least (N) 46. perform sequential search for a linear table with a length of n. In the worst case, the number of comparisons required is (N) 47. the simplest way to sort data is (bubble sort) 48. assume that the linear table length is n. In the worst case, the number of comparisons required for Bubble Sorting is (n (n-1)/2) 49. on the premise that the sequence of elements to be sorted is basically ordered, the most efficient sorting method is (Bubble Sorting) 50. in the worst case, the minimum time complexity of the following sequential methods is (heap sorting) 51. hill sorting method (insert class sorting) 52. heap sorting method (select class sorting) 53. among the following sorting methods, the maximum memory size is (Merge Sorting) 54. it is known that each element in Table A is not far from its final position. To save time, 55 should be used (directly inserted for sorting. the basic features of an algorithm are feasibility and determination. Sexual, poor, and have enough intelligence.
1. An algorithm is usually composed of two basic elements: calculation and operation of data objects, and control structure of algorithms. 1. The complexity of algorithms mainly includes time complexity and space complexity. 2. The number of storage units required to implement the algorithm and the workload of the algorithm are called the space complexity and time complexity of the algorithm respectively. 3. Data Processing refers to operations on each element in a dataset in various ways, including insert, delete, search, and change operations, as well as analysis of data elements. 4. Data structure refers to a set of correlated data elements. 5. Data structures are divided into logical and storage structures. Linear Linked lists are storage structures. 6. The data structure includes the logical structure of the data and the storage structure of the data. 7. The data structure includes the logical structure of the data, the storage structure of the data, and Operation operations on the data. 8. Any relationship between data elements can be described by the forward and subsequent relationships. 9. The logical structures of data are linear and nonlinear. 10. Common storage structures include sequential, Link, index, and other storage structures. 11. The sequential storage method stores logically adjacent nodes in storage units adjacent to physical locations. 12. There are three basic stack operations: the elements of the inbound stack, the rollback stack, and the read stack top. 13. There are two basic operations for a queue: The queuing operation and the backend operation. 14. In practical applications, a stack with a chain can be used to collect all idle storage nodes in a computer storage space. A stack with a chain is called a usable stack. 15. The storage structure of stacks and queues is chained storage and sequential storage. 16. When a linear table uses a sequential storage structure for storage, its main feature is that adjacent nodes in the logical structure are still adjacent in the storage structure. 17. There are two basic operations for cyclic queue: queuing and unqueuing. Each time you perform the calculation, the team's tail pointer enters 1. 18. When the cyclic queue is not empty and the tail pointer is the opposite pointer, it indicates that the cyclic queue is full and cannot be entered into the queue. This situation is called overflow. 19. When the cyclic queue is empty, it cannot be dequeued. This is called underflow. 20. In a 25-type cyclic queue, if the first pointer is front = 16 and the last pointer is rear = 9, there are 18 elements in the cyclic queue. Note: When rear <front, the number of elements = total capacity-(front-rear); when rear> front, the number of elements = rear-front.
1. determine whether a linked list has a ring linked list: Determine whether a linked list has a ring. For example, the following linked list has a ring: for example, N1-> N2-> N3-> N4-> N5-> N2 is a linked list with loops. The starting node of the ring is n5. here is a simple solution. Set two pointers: p1 and p2. Each cycle of p1 goes one step forward, while p2 goes two steps forward. Until p2 encounters a NULL pointer or two pointers are equal to each other to end the loop. If the two pointers are equal, a ring exists.
struct link
{
int data;
link* next;
};
bool IsLoop(link* head)
{
link* p1=head, *p2 = head;
if (head ==NULL || head->next ==NULL)
{
return false;
}
do{
p1= p1->next;
p2 = p2->next->next;
} while(p2 && p2->next && p1!=p2);
if(p1 == p2)
return true;
else
return false;
}
2. the reversal of the linked list is a frequently asked question and a very basic question. For example, a linked list is like this: 1-> 2-> 3-> 4-> 5, and then 5-> 4-> 3-> 2-> 1. The easiest way to traverse the linked list is to use an auxiliary pointer to store the next element pointed to by the current pointer during the traversal process. After the pointer of the element on the current node is reversed, use the stored pointer to traverse the backend. The source code is as follows:
struct linka {
int data;
linka* next;
};
void reverse(linka*& head)
{
if(head ==NULL)
return;
linka*pre, *cur, *ne;
pre=head;
cur=head->next;
while(cur)
{
ne = cur->next;
cur->next = pre;
pre = cur;
cur = ne;
}
head->next = NULL;
head = pre;
}
There is also a method that uses recursion. The basic idea of this method is to call recursive functions to reverse the subsequent nodes before reversing the current node. The source code is as follows. However, this method has one disadvantage: The last node after the inversion will form a ring, so the next field of the node returned by the function must be set to NULL. I used a reference to change the head pointer. The source code of the algorithm is as follows:
linka* reverse(linka* p,linka*& head)
{
if(p == NULL || p->next == NULL)
{
head=p;
return p;
}
else
{
linka* tmp = reverse(p->next,head);
tmp->next = p;
return p;
}
}
3. Determine whether there are identical numbers in two arrays. Given two sorted arrays, how can we effectively determine whether the two arrays contain the same numbers? The first question comes to mind is an O (nlogn) algorithm. An array is randomly selected to traverse all elements of the array. During the traversal process, binary search is performed on each element in the first array in the other array. Use C ++ to implement the Code as follows:
bool findcommon(int a[],int size1,int b[],int size2)
{
int i;
for(i=0;i<size1;i++)
{
int start=0,end=size2-1,mid;
while(start<=end)
{
mid=(start+end)/2;
if(a[i]==b[mid])
return true;
else if (a[i]<b[mid])
end=mid-1;
else
start=mid+1;
}
}
return false;
}
Later I found an O (n) algorithm. Because both arrays are sorted. Therefore, only one traversal is required. First, set two subscripts, initialize them as the starting addresses of the two arrays respectively, and push forward in sequence. The advancing rule is to compare the numbers in two arrays. The subscript of the small array is pushed forward until the subscript of any array reaches the end of the array. If the same number is not touched yet, it indicates that the array does not have the same number.
bool findcommon2(int a[], int size1, int b[], int size2)
{
int i=0,j=0;
while(i<size1 && j<size2)
{
if(a[i]==b[j])
return true;
if(a[i]>b[j])
j++;
if(a[i]<b[j])
i++;
}
return false;
}
4. Maximum subsequence problem: given an integer sequence A1, A2,... an (may have negative numbers), evaluate A1 ~ An sub-sequence of Ai ~ Such as integer sequence-2, 11,-4, 13,-5, 2,-5,-3, 12, the maximum subsequence of-9 is 21. The simplest and easiest way to think about this is to enumerate all subsequences. Use a triple loop to obtain the sum of all subsequences in sequence and then obtain the largest one. Of course, the algorithm complexity will reach O (N ^ 3 ). Obviously, this method is not optimal. The following shows a linear algorithm implementation with an algorithm complexity of O (n). The algorithm comes from programming pearls. Before providing a linear algorithm, let's look at an algorithm optimized for the exhaustive algorithm. Its complexity is O (n ^ 2 ). In fact, this algorithm only makes some changes to the exhaustive algorithm: in fact, we do not need to re-calculate the subsequence every time. Assume that sum (I, j) is a [I]... sum (I, j + 1) = sum (I, j) + A [J + 1]. With this recursion, we can obtain the following algorithm:
int max_sub(int a[],int size)
{
int i,j,v,max=a[0];
for(i=0;i<size;i++)
{
v=0;
for(j=i;j<size;j++)
{
v=v+a[j];//Sum(i, j+1) = Sum(i, j) + A[j+1]
if(v>max)
max=v;
}
}
return max;
}
So how can we achieve linear complexity? Here we use the idea of dynamic planning. Let's take a look at the source code implementation:
int max_sub2(int a[], int size)
{
int i,max=0,temp_sum=0;
for(i=0;i<size;i++)
{
temp_sum+=a[i];
if(temp_sum>max)
max=temp_sum;
else if(temp_sum<0)
temp_sum=0;
}
return max;
}
6. Reversing strings by words is not a simple string inversion, but a string is reversed by the words in the given string, that is, the words in the string are still in the original order, each word is separated by a space. For example, here is www.fishksy.com.cn is reversed and becomes: www.fishksy.com.cn is here. If you simply flip all strings, you can traverse the strings and swap the first character with the last one, the second and the second to the last are exchanged and cyclically. In fact, if the word is reversed, you can traverse the string again based on the first time of the calendar, and reverse each word again. In this way, each word restores the original order. Char * reverse_word (const char * Str) {int Len = strlen (STR); char * restr = new char [Len + 1]; strcpy (restr, STR); int I, j; for (I = 0, j = len-1; I <j; I ++, j --) {char temp = restr [I]; restr [I] = restr [J]; restr [J] = temp;} int K = 0; while (k <Len) {I = J = K; while (restr [J]! = ''& Restr [J]! = '') J ++; k = J + 1; j --; For (; I <j; I ++, j --) {char temp = restr [I]; restr [I] = restr [J]; restr [J] = temp;} return restr;} If You Want To optimize the space and time, of course, you can change the two character string exchanges in the above Code to an exception or implementation. For example, convert char temp = restr [I]; restr [I] = restr [J]; restr [J] = temp; To restr [I] ^ = restr [J]; restr [J] ^ = restr [I]; restr [I] ^ = restr [J]; 7. If the string is reversed, it is an MSN pen question, I accidentally saw it on the Internet and used it for a moment. The question is: Given a string, a substring of this string, the first string is reversed, but the sequence of the substring remains unchanged. Example: input: first string: "This is fishsky's Chinese site: http://www.fishsky.com.cn/cn" substring: "fishsky" output: "NC/NC. MOC. fishsky. www //: Ptth: ETIS esenihc s 'fishsky Si siht "the general method is to first scan the first string on one side, then use stack to reverse it, and record the position where the substring appears. Scan the recorded sub-string again and use the stack to reverse it. The method I used is to scan the array once. If a substring is found in the scan, it is pushed to the stack. Finally, the characters in the stack Are popped up, so that the strings are restored to their original order. The source code is as follows: # include <iostream> # include <cassert> # include <stack> using namespace STD; // reverse the string 's1' doesn't the substring 'Token '. const char * reverse (const char * S1, const char * token) {assert (S1 & token); stack <char> stack1; const char * ptoken = token, * Head = S1, * rear = S1; while (* head! = '') {While (* head! = ''& * Ptoken = * head) {ptoken ++; head ++;} If (* ptoken = '') // contain the token {const char * P; For (P = head-1; P> = rear; p --) stack1.push (* P); ptoken = token; rear = head;} else {stack1.push (* rear); Head = ++ rear; ptoken = token;} Char * return_v = new char [strlen (S1) + 1]; int I = 0; while (! Stack1.empty () {return_v [I ++] = stack1.top (); stack1.pop () ;}return_v [I] = ''; return return_v;} int main (INT argc, char * argv []) {cout <"this is fishsky's Chinese site: http://www.fishsky.com.cn/cn"; cout <reverse ("this is fishsky's Chinese site: http: // www. fishsky.com.cn/cn "," fishsky "); Return 0;} 8. Delete repeated numbers in the array. The following is a sequence of numbers with variable dynamic lengths. The ending mark is 0, replace the repeated numbers with a number. For example, convert an array of, and 0 1, 2, 7, 1, 5, 0 is relatively simple. Note that this array is dynamic. So to avoid the trouble, I still use the STL vector. # Include <iostream> # include <vector> using namespace STD; // remove the duplicated numbers in an intger array, the array was end with 0; // e.g., --->, void static remove_duplicated (int A [], vector <int> & _ st) {_ St. push_back (A [0]); For (INT I = 1; _ st [_ St. size ()-1]! = 0; I ++) {if (a [I-1]! = A [I]) _ st. push_back (A [I]) ;}} of course, if you can change the original array, you don't need STL. You only need pointer operations. The following program modifies the content of the original array. Void static remove_duplicated2 (int A []) {if (a [0] = 0 | A = NULL) return; int insert = 1, current = 1; while (A [current]! = 0) {if (a [current]! = A [Current-1]) {A [insert] = A [current]; insert ++; current ++;} else current ++ ;} A [insert] = 0;} 9. How to determine whether a binary tree is a balanced binary tree? solution: Based on the definition of a balanced binary tree, if the depth difference between left and right subtree of any node cannot exceed 1, the tree is a balanced binary tree. First, compile a function to calculate the depth of a binary tree and implement it using recursion. Template <typename T> static int depth (bstreenode <t> * PBS) {If (PBS = NULL) return 0; else {int LD = depth (PBS-> left ); int RD = depth (PBS-> right); return 1 + (LD> RD? Ld: RD) ;}} The following is a function that uses recursion to determine whether the depth of the left and right subtree is different from 1 to determine whether it is a balanced binary tree: template <typename T> static bool isbalance (bstreenode <t> * PBS) {If (PBS = NULL) return true; int Dis = depth (PBS-> left) -depth (PBS-> right); If (DIS> 1 | dis <-1) return false; else return isbalance (PBS-> left) & isbalance (PBS-> right );
4. abstract class something {
Private abstract string dosomething ();
}
Is this Code incorrect?
Answer: Yes.Abstract methods cannot be modified in private mode.. Abstract METHODS refers to the specific details of the sub-class implement (Implementation). How can we block abstract method with private? (Likewise, final cannot be added before abstract method ).
5. Check where the following code segment is wrong?
Public class something {
Void dosomething (){
Private String s = "";
Int l = s. length ();
}
}
Answer: Yes. You cannot place any access modifiers (private, public, and protected) before local variables ). Final can be used to modify local variables.
(Like abstract and strictfp, final is not an access modifier. strictfp can only modify class and method rather than variable ).
6. Are there any mistakes in the code below?
Abstract class Name {
Private String name;
Public abstract boolean isStupidName (String name ){}
}
Answer: Yes. Abstract method must end with a semicolon without curly braces.