Data structure review material 2__ data structure

Source: Internet
Author: User
Tags arithmetic data structures

[1.1] What is a data structure? What are the three aspects of a discussion about data structures?

correct answer: The
"answer" data structure refers to And the relationship between each other. Recorded as: data structure = {D, R}. where d is a data object and R is a limited set of relationships between all data members in the object. The discussion about data structure generally involves the following three aspects: ① data members and their logical relationship with each other, also known as the logical structure of data, referred to as structure, the ② data members are extremely related to the storage representation in the computer memory, also known as the physical structure of the data, referred to as the storage structure; ③ The action applied to the data structure. The logical structure of data is to describe the data from the logical relationship, which is not matter with the storage of the data, and is independent of the computer storage. Therefore, the logical structure of data can be regarded as a data model abstracted from specific problems, and a view of application of data. The storage structure of data is the implementation of logical data structures in computer memory (also known as images), which is computer-dependent and a physical view of the data. The operation of data is a set of operations defined on the logical structure of the data, each of which has a set of operations. such as search, insert, delete, update, sort, and so on.
27.

[1.2] According to the growth rate of n from small to large order the following functions

(2/3) n, (3/2) n, n2, nn, n!, 2n, N, log2n, N3

Correct answer:
log2n < n < N2 < N3 < (2/3) n < (3/2) n < 2n < n! < nn
28.

[1.4] Analyze the time complexity of the following statement segment execution, and give reasons.

(1) for (i=1;i<=n;i++)

for (j=1;j<=n;j++)

s++;

(2) for (i=1;i<=n;i++)

for (j=i;j<=n;j++)

s++;

Correct answer:
(1) Time complexity of O (N2). A double for loop statement, in which the outer loop is n times, for each outer loop, the inner loop s++; The statement executes N times. The total s++; The statement executes N2 times, the time complexity is O (n2) (2) and the time complexity is O (N2). A double for loop statement, in which the outer loop is n times, for each outer loop, the inner loop s++; The number of statement executions is changing. In the 1th outer loop, the inner loop s++; The statement executes N times, the 2nd outer Loop, the inner loop s++; The number of statements executed is n-1; the 3rd outer loop, the inner loop s++; The number of executions is n-2 times; In the nth outer loop, the inner loop is s++; The number of statements executed is 1 times. In short, "s++;" Statement Total execution n+ (n-1) + (n-2) +......+2+1=1/2n (n+1) times, Time complexity O (n2)
 
 
29.

[2.1] Linear table of two storage structure order table and linked list:

(1) Two kinds of storage represents the main advantages and disadvantages?

(2) If there are n linear tables coexisting simultaneously, and the length of each table in the process changes dynamically, the total number of linear tables will automatically change. In this case, what kind of storage structure should be chosen. Give explanations.     (3) If the total number of linear tables is basically stable and is rarely inserted and deleted, but requires the fastest access to the elements in the linear table, then what kind of storage structure should be used. Give explanations.

correct answer:
(1) Sequential storage Indicates that the data element is stored in a contiguous storage space for sequential access or (by subscript) direct access. It has high storage efficiency and fast access speed. However, once the space size is defined, it will not change during the entire run of the program, so it is not easy to expand. At the same time, when inserting or deleting, in order to maintain the original order, the average need to move half (or nearly half) elements, modification efficiency is not high. The storage space represented by the link store is generally allocated and released dynamically during the program's operation, and there is no storage overflow problem as long as there is room in the memory. At the same time, when inserting and deleting, it is necessary to keep the original physical order of the data elements, so that you need not move the data, just modify their link pointers, and the modification is more efficient. However, accessing the data elements in the table can only be accessed in chain order, so the access efficiency is not high. (2) Choose the chain-type storage structure. It can dynamically request memory space, not affected by the length of the table (that is, the number of elements in the table), insert, delete time complexity is O (1). (3) Select the sequential storage structure. Sequential tables can be accessed randomly, with a time complexity of O (1).
 
 
.

[2.2] writes the sequence of data elements in a single-linked list with HL as the table-head pointer after the execution of the following function has been called.

void  AA (Lnode * & HL)

{

      initlist (HL);

      insertrear (hl,30);

      insertrear (hl,50);

int  A[5] = {15,8,9,26,12};

for (int  i=0;  i<5;  i++)   Insertfront (Hl,a[i]);

 }

correct answer:
(12,26,9,8,15 , 30,50)
 
 
31.[2.3] Try to design an algorithm that iterates through a single linked list, reversing the link direction of all nodes in the list. A table header pointer to the list of reversal results is required to point to the last node in the original list.
correct answer:
Te Mplatevoid List:: Inverse () {if (first==null) return; listnode*p=first->link,*pr=null; while (p!=null) {first->link=pr;//reversal First pointer pr=first;first=p;p=p->link;//pointer move forward} first->link=pr; }
32.

[2.5] Judging the correctness of the following statements, give reasons for the statements that are judged to be false.

(1) The address of the memory unit assigned to a single linked list must be contiguous.

(2) compared with the sequential table, sequential access on the linked list has low efficiency.

(3) Insert an element into the sequential table, averaging about half of the elements to be moved.

(4) In a circular single-linked list with a header node, the pointer to any one node cannot be empty. (5) In the order table with n elements, the average number of times to move the nodes to delete any one element is n-1.

Correct answer:
(1) error. The address of a memory cell assigned to a single linked list can be discontinuous. (2) error. Sequential access to sequential tables and linked lists is an O (n) of the algorithm's time complexity. (3) correct. (4) correct. (5) error. Removing the 1th element moves the number of nodes to n-1, removing the last element without a node move. The average number of move nodes required to delete any element is the case of deleting about half of the elements, for N/2
33.

[3.1] A sparse matrix is known as shown in the following figure: (see textbook Chapter III, "Exercise 3-1")

0 4 0 0 0 0 0

0 0 0-3 0 0 1

8 0 0 0 0 0 0

0 0 0 5 0 0 0

0-7 0 0 0 2 0

0 0 0 6 0 0 0

A sparse matrix with 6 rows of x7 columns

(1) write its ternary linear table;

(2) gives its sequential storage representation;

(3) A ternary linear table and sequential storage representation of its transpose matrix are given;

Correct answer:
(1) ((1,2,4), (2,4,-3), (2,7,1), (3,1,8), (4,4,5), (5,2,-7), (5,6,2), (6,4,6)) (2) 1 2 2 3 4 5 5 6 2 4 7 1 4 2 6 4 4-3 1 8 5-7 2 6 (3) ((1,3,8), (2,1,4), (2,5,-7), (4,2,-3), (4,4,5), (4,6,6), (6,5, 2), (7,2,1)) 1 2 2 4 4 4 6 7 3 1 5 2 4 6 5 2 8 4-7-3 5 6 2 1
 
 
.

[3.3] calculates the length and depth of each of the following generalized tables, respectively. (See textbook Chapter III, "Exercise 3.2")

(1) a= (())

(2) b= (a,b,c)

(3) c= (A, (b, (c)))

(4) d= ((b), (c,d))

(5) e= (A, (b, (C,d)), (E))

(6) f= ((A, (b, (), C), (((d), E))

Correct answer:
(1) A: Length: 1 Depth: 2 (2) B: Length: 3 Depth: 1 (3) C: Length: 2 Depth: 3 (4) D: Length: 2 Depth: 2 (5) E: Length: 3 Depth: 3 (6) F: Length: 1 Depth: 4
 
 

[3.4] Set a={1,2,3},b={3,4,5}, the following results are obtained:

(1) A + B (set of and)

(2) A * B (intersection of the set)

(3) A-A (difference of set)

correct answer:
(1) The a+b={1,2,3,4,5} (2) Set of Intersection a*b={3} (3) Sets of the difference a-b={1, 2}
 
 
.

[4.1] writes the following suffix form of the infix expression:

(1)  a * B * C

(2) (A + B) * D + E/(F + A * D) + C

correct answer:
The suffix form of each infix expression is as follows: (1) A B * C * (2) ab+d*efad*+/+c+
 
 
PNs.

[4.2] The known suffix arithmetic expression is:

8 + 3 * 4 7-*/@

    writes out the corresponding infix arithmetic expression and calculates its value.

correct answer: infix expression (24+8) *3/((10-7)) value 8
 
 
A.

[4.3] If the stack has an element sequence of 123456, then the stack sequence of 435612 and 135426 can be obtained. And explain why you can't get it or how to get it.

correct answer: can get 135426 of the stack sequence because [1, 1, 2, 3, 3, 4, 5, 5, 4, 2, 6, 6 out] conform to the operational rules on the stack. Cannot get 435612 of the stack sequence, because [1, 2, 3, 4, 4, 3, 5, 5, 6, 6 out] conform to the operating rules on the stack, and then only [2 out, 1 out] to get 435621, not a stack sequence of 435612.
 
 
39.[5.1] fills in each tree with the number of nodes N (n>1), the height of the tree with the smallest height. How many leaf nodes it has. Number of branch nodes. What is the height of the height of the largest tree? How many leaf nodes it has. Number of branch nodes.
correct answer:
Node When the number is N, the height of the smallest tree is 1, there are 2 layers, it has n-1 leaf nodes, 1 branch nodes, the height of the largest tree is n-1, there are n layers, it has 1 leaf nodes, n-1 branch nodes.
 
 
40.[5.2] It is known that there are 8 leaf nodes in the 8th layer of the complete binary tree, and the total number of leaf nodes of the complete binary tree. Describes the calculation process.
correct answer:
8th There are 8 nodes in the complete binary tree has 8 layers, the above 7 layers each layer node is full, the 7th Layer node is 2i-1=27-1=64, where 4 nodes have 8 nodes, the complete binary Tree leaf node =64-4+8=68
 
 
in.

[5.5] judgment question

(  ) 1. Two the key value of each node in the fork tree is greater than the key value of all nodes of its left non-empty empty tree (if present), and is less than the key value of all nodes of its right non-empty tree (if any).

(  ) 2. The number of nodes in the two fork tree is 2k-1-1, where k is the depth of the tree.  

(  ) 3. Two all nodes in the tree, if there is no non-empty left subtree, there is no non-empty right subtree.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.