Arrays and Generalized Tables - Chapter 5 - Analysis of Problems in "Data Structure Problems" - Yan Weimin Wu Weimin Edition

Problem Set Analysis Part

Chapter 5 Arrays and Generalized Tables

——"Data Structure Questions" - Yan Weimin. Wu Weimin Edition

       Source code instruction   link ☛☛☛  "Data Structure-C Language Edition" (Yan Weimin, Wu Weimin version) textbook source code + exercise set analysis instructions

       Textbook Source Code Compilation   Link☛☛☛  "Data Structure" Textbook Source Code Compilation

         Links to the full analysis of the exercise set ☛  "Data Structure Problem Set" Exercise Analysis Collection

 

      Related test data download  link☛Data package

 

      The storage directory of this exercise document: Data Structure\▼Analysis of Matching Exercises\▼05 Arrays and Generalized Tables

      The storage directory of the source code in the document: data structure\▼Analysis of supporting exercises\▼05 Arrays and generalized tables\▼Exercise test document-05

      Source code test data storage directory: data structure\▼Analysis of supporting exercises\▼05 Arrays and generalized tables\▼Exercise test document-05\Data

 

1. Basic knowledge questions

5.1❶ Assuming that there is a two-dimensional array A 6 × 8 , each element is stored in adjacent 6 bytes, the memory is addressed by bytes, and the starting storage position (base address) of A is known to be 1000, calculate:

(1) The volume (ie storage) of array A;

(2) The address of the first byte of the last element a 57 of array A;

(3) When stored in rows, the address of the first byte of element a 14 ;

(4) The address of the first byte of element a 47 when stored in columns.

 

5.2❶ Assuming that the integer array A 9 × 3 × 5 × 8 is stored according to the low subscript priority , the byte address of the first element is 100, and each integer occupies four bytes. What is the storage address of the following elements?

        (1) a0000               (2) a1111               (3) a3125               (4) a8247

 

5.3❶ List all elements a ijkl in the array A 2 × 2 × 3 × 3 in order according to the high-subscript priority storage method (the rightmost subscript is the main order), in order to simplify the expression, you can only list (i, j, k, l) sequence.

 

5.4❶ Rewrite Equation (5-3) in Section 5.3.1 of the textbook into an equation form.

 

5.5❸ With an upper triangular matrix (a ij ) n × n , store its upper triangular elements in the array B[m] row by row (m is sufficiently large), so that B[k]=a ij , and k=f 1 (i)+f 2 (j)+c. Try to derive functions f 1 , f 2 and constant c (requiring that f 1 and f 2 do not contain constant terms).

 

5.6❷ Given a tridiagonal matrix (a ij ) n × n , store the elements on its three diagonals in the array B[3][n], so that the element B[u][v]=a ij , try Derive the formula for subscript transformation from (i, j) to (u, v).

 

5.7❸ Given a tridiagonal matrix (a ij ) n × n , store the elements of its three diagonals in the array B[3n-2] row by row, so that B[k]=a ij , find:

        (1) Use i, j to represent the subscript transformation formula of k;

        (2) Use k to represent the subscript transformation formula of i and j.

 

5.8 ❸ Assume a quasi-diagonal matrix

 

        Stored in the one-dimensional array B[4m] as follows:

 

        Write the conversion formula for finding k from a pair of subscripts (i, j).

 

5.9❷已知A为稀疏矩阵,试从空间和时间角度比较采用两种不同的存储结构(二维数组和三元组表)完成求运算的优缺点。

 

5.10❷求下列广义表操作的结果:

        (1) GetHead【(p, h, w)】;

        (2) GetTail【(b, k, p, h)】;

        (3) GetHead【((a, b), (c, d))】;

        (4) GetTail【((a, b), (c, d))】;

        (5) GetHead【GetTail【((a, b), (c, d))】】;

        (6) GetTail【GetHead【((a, b), (c, d))】】;

        (7) GetHead【GetTail【GetHead【((a, b), (c, d))】】】;

        (8) GetTail【GetHead【GetTail【((a, b), (c, d))】】】.

        注意:【】是函数的符号。

 

5.11❷利用广义表的GetHead和GetTail操作写出如上题的函数表达式,把原子banana分别从下列广义表中分离出来。

        (1) L1 = (apple, pear, banana, orange);

        (2) L2 = ((apple, pear), (banana, orange));

        (3) L3 = (((apple), (pear), (banana), (orange)));

        (4) L4 = (apple, (pear), ((banana)), (((orange))));

        (5) L5 = ((((apple))), ((pear)), (banana), orange);

        (6) L6 = ((((apple), pear), banana), orange); 

        (7) L7 = (apple, (pear, (banana), orange));

 

5.12❷按教科书5.5节中图5.8所示结点结构,画出下列广义表的存储结构图,并求它的深度。

        (1) ((()),a,((b,c),(),d),(((e)))) 

        (2) ((((a),b)),(((),(d)),(e,f))) 

 

5.13❷已知以下各图为广义表的存储结构图,其结点结构和5.12题相同。写出各图表示的广义表。

 

5.14❸已知等差数列的第一项为a1,公差为d,试写出该数列前n项的和S(n)(n≥1)的递归定义。

 

5.15❹写出求给定集合的幂集的递归定义。

 

5.16❸试利用C语言中的增量运算“++”和减量运算“--”写出两个非负整数a和b相加的递归定义。

 

5.17❸  已知顺序表L含有n个整数,试分别以函数形式写出下列运算的递归算法:

       (1) 求表中的最大整数;

       (2) 求表中的最小整数;

       (3) 求表中n个整数之和;

       (4) 求表中n个整数之积;

       (5) 求表中n个整数的平均值。

 

 

二、算法设计题

数组

5.18❺设计一个算法,将数组An中的元素A[0]至A[n-1]循环右移k位,并要求只用一个元素大小的附加存储,元素移动或交换次数为O(n)。

 

5.19❹若矩阵Am×n中的某个元素aij是第i行中的最小值,同时又是第j列中的最大值,则称此元素为该矩阵中的一个马鞍点。假设二维数组存储矩阵Am×n,试编写求出矩阵中所有马鞍点的算法,并分析你的算法在最坏情况下的时间复杂度。

 

5.20❺类似于以一维数组表示一元多项式,以m维数组:(aj1j2jm),0≤ji≤n,i=1,2,…,m,表示m元多项式,数组元素ae1e2em表示多项式中x1e1x2e2…xmem的系数。例如,和二元多项式x2+3xy+4y2-x+2相应的二维数组为:

 

        试编写一个算法将m维数组表示的m元多项式以常规表示的形式(按降幂顺序)输出。可将其中一项ckx1e1x2e2…xmem印成ckx1Ee1x2Ee2…xmEem(其中m,ck和ej(j=1,2,…,m)印出它们具体的值),当ck或ej(j=1,2,…,m)为1时,ck的值或“E”和ej的值可省略不印。

 

三元组顺序表(稀疏矩阵)

5.21❹假设稀疏矩阵A和B均以三元组顺序表作为存储结构。试写出矩阵相加的算法,另设三元组表C存放结果矩阵。

 

5.22❹假设稀疏矩阵A和B均以三元组顺序表作为存储结构。试写出满足以下条件的矩阵相加的算法:假设三元组顺序表A的空间足够大,将矩阵B加到矩阵A上,不增加A,B之外的附加空间,你的算法能否达到O(m+n)的时间复杂度?其中m和n分别为A,B矩阵中非零元的数目。

 

行逻辑链接的顺序表(稀疏矩阵)

5.23❷三元组顺序表的一种变型是,从三元组顺序表中去掉行下标域得到二元组顺序表,另设一个行起始向量,其每个分量是二元组顺序表的一个下标值,指示该行中第一个非零元素在二元组顺序表中的起始位置。试编写一个算法,由矩阵元素的下标值i,j求矩阵元素。试讨论这种方法和三元组顺序表相比有什么优缺点。

 

稀疏矩阵

5.24❷三元组顺序表的另一种变型是,不存矩阵元素的行、列下标,而存非零元在矩阵中以行为主序时排列的顺序号,即在LOC(0, 0)=1,l=1时按教科书5.2节中公式(5-2)计算出的值。试写一算法,由矩阵元素的下标值i,j求元素的值。

 

5.25❸若将稀疏矩阵A的非零元素以行序为主序的顺序存于一维数组V中,并用二维数组B表示A中的相应元素是否为零元素(以0和1分别表示零元素和非零元素)。例如,

        可用V=(15, 22, -6, 9)和表示。

        试写一算法,实现在上述表示法中实现矩阵相加的运算。并分析你算法的时间复杂度。

 

十字链表(稀疏矩阵)

5.26❸试编写一个以三元组形式输出用十字链表表示的稀疏矩阵中非零元素及其下标的算法。

 

5.27❹试按教科书5.3.2节中定义的十字链表存储表示编写将稀疏矩阵B加到稀疏矩阵A上的算法。

 

广义表

5.28❹采用教科书5.6节中给出的m元多项式的表示方法,写一个求m元多项式中第一变元的偏导数的算法。

5.29❹采用教科书5.6节中给出的m元多项式的表示方法,写一个m元多项式相加的算法。

 

5.30❸试按表头、表尾的分析方法重写求广义表的深度的递归算法。

 

5.31❸试按教科书5.5节图5.10所示结点结构编写复制广义表的递归算法。

 

5.32❹试编写判别两个广义表是否相等的递归算法。

 

5.33❹试编写递归算法,输出广义表中所有原子项及其所在层次。

 

5.34❺试编写递归算法,逆转广义表中的数据元素。

        例如:将广义表

(a, ((b, c), ()), (((d), e), f))

        逆转为:

((f, (e, (d))), ((), (c, b)), a)。

 

5.35❺假设广义表按如下形式的字符串表示。

(a1, a2, …, an)    n≥0

    其中ai或为单字母表示的原子,或为广义表;n=0时为只含空格字符的空表( )。

    试按教科书5.5节图5.8所示链表结点结构编写,按照读入的一个广义表字符串建立其存储结构的递归算法。

 

5.36❺试按教科书5.5节图5.8所示存储结构,编写按上题描述的格式输出广义表的递归算法。

 

5.37❺试编写递归算法,删除广义表中所有值等于x的原子项。

 

5.38❹试编写算法,依次从左至右输出广义表中第l层的原子项。

        例如:广义表(a, (b, (c)), (d))中的a为第一层的原子项;b和d为第二层的原子项;c为第三层的原子项。

Guess you like

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