Data Structures and Algorithms (C Language) - Final Review Questions and Analysis (a lot of questions!)

Hello, I'm Ganggang classmate!
Forget the sweetheart on the first page of the code spectrum, the last page. . . . . .

welcome to readGanggang classmate's article (Follow not to get lost)

(Remember to like and follow)
You are still troubled by the code not running normally, pay attention to Ganggang classmates not to get lost and solve your troubles.
If you think that this article is so helpful to you, remember to like, follow and forward, classmate Ganggang is very grateful!

The follow-up articles are about some basic experiments on data structures. I have successfully run them. If you have any questions, please leave a message in the comment area.
Your support is the biggest driving force for Ganggang students to move forward!
**I am Ganggang classmate, a novice who is new to Internet security. ☜(ˆ▽ˆ) **
(Crazy hints like! Follow! Retweet!!! Like! Follow! Retweet!!!)

The second semester of the 2019-2020 academic year of XXX University
"Data Structure" final exam mock test answer sheet
Major: XXX Class: XXX Student ID: XXX Name: XXX
Exam time: 120
minutes Question 1, Question 2, Question 3, Question 4, Question 5, Question 6, total score
raters Words work hard! Please like + follow! !

1. Explanation of terms
1. Algorithm: An algorithm is a description of solving a specific problem. It is a finite sequence of instructions, where each instruction represents one or more operations.

2. Pattern matching algorithm: Given the main string S = "S 1 S 2 S 3 ... S n " and the pattern string T = "t 1 t 2 t 3 ... t n ", the process of finding T in S is called a pattern match. Returns the position of T in S if the match is successful, or 0 if the match fails.

3. AOV network: In a directed graph representing a project, vertices are used to represent activities, and arcs are used to represent the priority relationship between activities. Such a directed graph is called a network with vertices representing activities, or AOV network for short.

4. AOE network: In a weighted directed graph representing a project, events are represented by vertices, activities are represented by directed edges, and the weights on the edges represent the duration of activities. Such a directed graph is called an edge representing activities. network, referred to as AOE network.

5. Internal sorting: During the entire sorting process, all records to be sorted are placed in memory.

6. External sorting: Since there are too many records to be sorted, they cannot be placed in the memory at the same time, but some records need to be placed in the memory and the other part in the external memory. The entire sorting process requires multiple exchanges of data between internal and external memory to obtain the sorted result.

7. Undirected complete graph: In an undirected graph, if there is an edge between any two vertices, the graph is called an undirected complete graph.

8. Directed complete graph: A directed graph with n vertices has at most n(n-1) edges. A directed graph with n(n-1) edges is called a directed complete graph.

9. Child sibling notation: Convert the tree into a binary tree storage structure, one data field, two pointer fields, the left pointer points to the first child node, and the right pointer points to the next sibling node.
10. Abstract data type (ADT): A user-defined mathematical model that represents an application problem, and a general term for a set of operations defined on this model.

11. Data structure: A collection of data elements that have one or more specific relationships to each other.

12. Heap: A heap is a complete binary tree with the following properties : the value of each node is less than or equal to the value of its left and right child nodes (called a small root heap), or the value of each node is greater than or equal to its The values ​​of the left and right child nodes (called the big root heap).

13. Hash table: According to the set hash function H (Key) and the method of handling conflicts, map a set of keywords to a limited set of consecutive addresses, and use the keyword address as the record in the table. Storage location, this storage structure is called constructing a hash table (hash table).

14. Logical structure of data: a description of the relationship between data, it has nothing to do with the storage structure of data, the same logical structure can have multiple storage structures.

15. The physical structure of the data: also known as the storage structure, is the representation of the logical structure of the data in the computer. It includes the representation of data elements and the representation of relationships.

2. True or False
1. Regardless of whether a Huffman tree has an even or odd number of leaf nodes, the number of summary points in the tree must be an odd number. T
2. The logical structure of a binary tree can be uniquely determined by the preorder and postorder traversal sequences of the binary tree. F
3. The postfix expression of the expression a*(b+c)-d is abc+*d-. T
4. The logical order of a linear table is always consistent with the storage order. F
5. Algorithms can be described in different languages, such as C, C++, Python, etc., so algorithms are actually programs. F
6. The determinism of an algorithm means that the algorithm can have only one execution path, that is, as long as the input is the same, it can only get the same output result. T
7. A data element is the smallest unit of data. F
8.

3. Short answer questions
1. There is a stack, and the order of elements to be pushed into the stack is A, B, C, D, E. Can you get the pop-out sequence of "E, C, A, B, D"? If yes, write out the sequence of operations; if not, explain why.
can not. The characteristics of the stack are first-in, last-out. Press ABCDE into the stack, and after E is popped out of the stack, the next one should be D, not C.

2. Fill in the keywords 17, 49, 29, 38 in the hash table with a length of 11, the hash function is H(key)=key MOD 11, and the hashing is performed twice .
insert image description here

3. In array A, the length of each element is 2 bytes, the range of row subscript i is from 1 to 8, the range of column subscript j is from 1 to 10, and it is continuously stored in the memory from the first address SA, How many cells are required to store this array? How many cells are needed to store one row and one column of data?
(bytes can be simply understood as units) to
store this array at least: 8X10X2=160 units
(8+10-1) x2=34 units

4. Write two different breadth-first traversal sequences in the following figure, starting from the V 1 vertex.
insert image description here
V 1 V 2 V 3 V 4 V 6 V 5 V 7
V 1 V 3 V 2 V 4 V 6 V 5 V 7
(The answer to this question is not unique)

5. It is known that the total number of nodes in a complete binary tree is 19, how many nodes are in the last layer, and explain why.
In a complete binary tree, it is easy to know that the i-level complete binary tree has at most 2 i -1 nodes. Suppose the complete binary tree has a total of h layers, it is easy to know that each layer of nodes in the first h-1 layer is full, and 2 4 -1<19<2 5 -1, so the complete binary tree has 5 layers, and the last layer The number of nodes is 19 - (2 4 -1) = 4

6. What is the depth of a complete binary tree with 65 nodes? (The depth of the root is 1)
directly into the formula [log 2 (n+1)] (need to round up), the solution depth is 7

7. Store all nodes in the complete binary tree layer by layer in a one-dimensional array R[1...N] in the order from left to right by the method of sequential storage. If the node R[i] has a right child, its right child is?
The right child is: R[2i+1] The left child is: R[2i]

8. If the in-order traversal sequence of a binary tree is ABCDEFG and the post-order traversal sequence is BDCAFGE, what is the number of nodes in its left subtree?
Construct the binary tree, and the answer comes out.
insert image description here
Easy to understand with pictures, the answer is 4

9. Suppose the tree T has 3 nodes of degree 3 and 2 nodes of degree 2, and the rest are leaf nodes, then the leaf tree in T is? Try to explain why.
insert image description here
10. D=(D, R), where D={1 2 3 4 5 6}, R={(1,2),(1,4),(2,3),(2,4),( 3,4),(3,5),(3,6),(4,6)} The structure is?
A. Set B. Linear table C. Tree D. Graph
Select D
to satisfy many-to-many
insert image description here
11. When inserting a node pointed to by S into a chain stack whose top pointer is HS, execute
A.HS->next =S
BS->next=HS->next;HS->next=S
CS->next=HS;HS=S
DS->next=HS;HS=->nextChoose
C

12. What are the initialization, empty and full conditions of the circular queue? How to find the actual length of the circular queue?
Initialization: front=rear=0;
Empty: front=rear;
Full: (rear+1)%maxsize=front;
Actual length: (rear-front+maxsize)%maxsize;
13. If the input sequence of a stack is 1, 2, 3...n, the first element of the output sequence is n, can you determine what the kth output element is? If you can't explain why.
can be determined. Because the first output sequence is n, then the first n-1 elements are pushed onto the stack in turn, so the Kth element is n-k+1.
14. Use one statement to delete the successor node of the node pointed to by P in the singly linked list.
P->next=p->next->next;
15.for(i=0;i<m;i++)
for(j=0;j<n;j++)
A [i] [j] =i*j
What is the event complexity of the above statement?
O(n 2 )

Fourth, drawing and algorithm application
1. Construct the triple table of the sparse matrix in the following figure.
insert image description here
insert image description here
2. Sequence {36, 98, 14, 23, 83, 13, 28}, construct a binary sorting tree.
insert image description here
3. Write out the results of each quicksort of the sequence {36, 98, 14, 23, 83, 13, 28}.
insert image description here

4. Given a set of weights {3, 6, 9, 14, 8, 5, 4, 19, 25}, design the corresponding Huffman tree, and calculate the weighted path length. 5. Use Dijkstra's algorithm to find the shortest path from
insert image description here
vertex V 0 to other vertices.
insert image description here

insert image description here

6. For the known sequence {05 13 19 21 37 56 64 75 80 88 90}, write the search times and search traces for the two elements "88" and "68" respectively.
Find "88": find 3 times Find track: 56, 80, 88
Find "68": Find 4 times Find track: 56, 80, 64, 75

7. For the given sequence {40 28 6 72 100 3 54 1 80 91 38}, construct a binary sorting tree with "40" as the root node.
(1) Draw a binary sorting tree.
(2) Draw the binary sorting tree after deleting the node "72".
insert image description here

8. Given the key sequence {22 37 45 10 32 25 38}, construct a balanced binary tree. Ask to write clearly about the process.
insert image description here

9. Give the logical structure of a tree T=(N, R), where: N={A,B,C,D,E,F,G,H,I,J,K},R={r }, r={(A,B),(B,E),(B,F),(F,G),(F,H),(A,C),(C,I),(C, J),(J,K),(A,D)} Try to answer the following questions: (with A as the root node) (1) Which is the parent node of F? (2) Which are the descendants of B? (3) What is the depth of the subtree rooted at node C?
insert image description here

It can be obtained from the figure (1) B (2) EFGH (3) 3

10. Construct a Huffman tree with weights {3 7 8 2 6 10 14} 7 nodes, and calculate the weighted path length WPL. Requirement: Construct in the order that the weight of the root node of the left subtree of each node is less than or equal to the weight of the root node of the right subtree.
insert image description here
11. A message, the original text is: AMCADEDDMCCAD. Now we need to convert the original text into 01 string and send it to the other party. In order to save resources, we hope that the length of the translated 01 string is as short as possible. Try to design a coding scheme and compare the scheme with isometric coding.
insert image description here

5. Algorithm Design

1. The head insertion method creates a linked list.

void create(node *head,int a[],int n)//数组a[]中是带存储的元素 
{
    
       node *p;int i;
 node *m=(node*)malloc(sizeof(node));//动态分配内存 
 m->next=NULL;//m相当于头节点 
 for(i=0;i<n;i++)
 {
    
     p=(node*)malloc(sizeof(node));//待插入的新结点 
  p->data=a[i];//将数组中的元素赋值 
  p->next=m->next; //头插法 
  m->next=p;//头插法 
 } 
}

2. halved search algorithm

int search(table *ST)//折半查找 在动态数组上查找 
{
    
     int low=0,high=ST->length-1,key,mid;//高、低位指针初始化 
 scanf("%d",&key);//待查找关键字 
 while(low<=high)// 当low>high时循环结束 
 {
    
     mid=(low+high)/2;
  if(key==ST->data[mid])
    return mid+1;//输出的是该关键字是 
  else if(key<ST->data[mid])
    high=mid-1;//转换区域 
  else
    low=mid+1;//转换区域 
 }
} 

3. Design an algorithm to judge whether the doubly circular linked list L is symmetric.

int duichen(node *head)
{
    
     node *p;node *q;
 p=head->next;
 q=head->rior;//rior为前指针域 
 while(p!=q&&p->next!=q)
 {
    
     if(p->data==q->data)
  {
    
     p=p->next;
   q=q->next;
  }
  else
    return 0;
 }
 return 1;
} 

4. Using sequentially stored strings, design an algorithm to delete consecutive j characters from position i.

int sqstring_delete(sqstring* str1,sqstring* str2)
{
    
     int i,j,k;
 str2->length=0;
 str2->data=(char*)malloc((str1->length-j+1)*sizeof(char));
 if(i<=0||i>str1->length||i+j-1>str1->length||j<=0)
   return 0;
 for(k=0;k<i-1;k++)
   str2->data[k]=str1->data[k];
 for(k=i+j-1;k<str->length;k++)
   str2->data[k-j]=str1->data[k];
 str2->length=str1->length-j; 
 return 1;
} 

5. In-place inversion of a singly linked list

void nizhi(node* head)
{
    
       node* p;node* q;
 p=head->next;
 head->next=NULL;
 while(p!=NULL)
 {
    
     q=p->next;
  p->next=head->next;
  head->next=p;
  p=q;
 }
}

6. Simple selection sort

void SelectSort(sqlist *L)
{
    
     int i,j,k,temp;
 for(i=1;i<L->length;i++)
 {
    
     k=i;
  for(j=1+i;j<=L->length;i++)
    if(L->data[k]>L->data[j])
      k=j;
  if(k!=j)
  {
    
     temp=L->data[i];
   L->data[i]=L->data[k];
   L->data[k]=temp;
  }
 }
}

7. Insert an element x into the circular queue.

int forqueue_charu(forqueue* qu,int x)
{
    
       if((qu->rear==qu->front&&qu->flag==1)||(qu->rear==qu->maxsize-1&&qu->front==-1))
   return 0;//队列已满
 qu->rear=(qu->rear+1)%qu->maxsize;
 qu->data[qu->rear]=x;
 qu->flag=1; 
 return 1;
}

8. Remove an element in a singly linked list and return it.

int list_shanchu(node *head,int i,int *e)
{
    
     int j;
 node *p=head;
 for(j=0;j<i-1;j++)
 {
    
     if(p==NULL)
    return 0;
  p=p->next;
 }
 node *q=p->next;
 *e=q->data;
 p->next=q->next;
 fre(q);
 return e;
}

Your support is the biggest driving force for Ganggang students to move forward!
I'm Ganggang classmate, a novice who is new to Internet Security. ☜(ˆ▽ˆ)
(crazy hintlike! focus on! Forward! ! ! like! focus on! Forward! ! !

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324322049&siteId=291194637