四川大学网络学院-数据结构课程设计-参考答案

合集下载

2022年四川大学计算机科学与技术专业《数据结构与算法》科目期末试卷A(有答案)

2022年四川大学计算机科学与技术专业《数据结构与算法》科目期末试卷A(有答案)

2022年四川大学计算机科学与技术专业《数据结构与算法》科目期末试卷A(有答案)一、选择题1、将两个各有N个元素的有序表归并成一个有序表,其最少的比较次数是()。

A.NB.2N-1C.2ND.N-12、从未排序序列中依次取出一个元素与已排序序列中的元素依次进行比较,然后将其放在已排序序列的合适位置,该排序方法称为()排序法。

A.插入B.选择C.希尔D.二路归并3、以下数据结构中,()是非线性数据结构。

A.树B.字符串C.队D.栈4、在下列表述中,正确的是()A.含有一个或多个空格字符的串称为空格串B.对n(n>0)个顶点的网,求出权最小的n-1条边便可构成其最小生成树C.选择排序算法是不稳定的D.平衡二叉树的左右子树的结点数之差的绝对值不超过l5、向一个栈顶指针为h的带头结点的链栈中插入指针s所指的结点时,应执行()。

A.h->next=sB.s->next=hC.s->next=h;h->next=sD.s->next=h-next;h->next=s6、排序过程中,对尚未确定最终位置的所有元素进行一遍处理称为一趟排序。

下列排序方法中,每一趟排序结束时都至少能够确定一个元素最终位置的方法是()。

Ⅰ.简单选择排序Ⅱ.希尔排序Ⅲ.快速排序Ⅳ.堆排Ⅴ.二路归并排序A.仅Ⅰ、Ⅲ、Ⅳ B.仅Ⅰ、Ⅱ、Ⅲ C.仅Ⅱ、Ⅲ、Ⅳ D.仅Ⅲ、Ⅳ、Ⅴ7、下列选项中,不能构成折半查找中关键字比较序列的是()。

A.500,200,450,180 B.500,450,200,180C.180,500,200,450 D.180,200,500,4508、每个结点的度或者为0或者为2的二叉树称为正则二叉树。

n个结点的正则二叉树中有()个叶子。

A.log2nB.(n-1)/2C.log2n+1D.(n+1)/29、有关二叉树下列说法正确的是()。

A.二叉树的度为2B.一棵二叉树的度可以小于2C.二叉树中至少有一个结点的度为2D.二叉树中任何一个结点的度都为210、对n个记录的线性表进行快速排序为减少算法的递归深度,以下叙述正确的是()。

《c数据结构》课程设计答案

《c数据结构》课程设计答案

《c数据结构》课程设计答案一、教学目标本课程的教学目标是使学生掌握C数据结构的基本概念、原理和方法,能够运用C语言实现简单的数据结构,并具备一定的编程实践能力。

1.掌握基本数据结构(如数组、链表、栈、队列、树、图等)的定义、特点和应用场景。

2.理解数据结构的算法和操作,能够分析数据结构的性能。

3.掌握C语言的基本语法和编程技巧,能够编写结构清晰、可读性强的C代码。

4.能够运用C语言实现基本数据结构,并进行调试和优化。

5.具备一定的编程实践能力,能够独立完成简单的数据结构相关项目。

情感态度价值观目标:1.培养学生的团队合作意识和沟通能力,能够积极参与小组讨论和协作。

2.培养学生的问题解决能力和创新精神,能够主动思考和探索数据结构的优化方案。

3.培养学生对编程的兴趣和热情,增强对计算机科学领域的探索欲望。

二、教学内容根据课程目标,本章节的教学内容主要包括以下几个方面:1.C语言基础:介绍C语言的基本语法、数据类型、运算符、控制语句等,为学生编写数据结构代码打下基础。

2.基本数据结构:讲解数组、链表、栈、队列、树、图等基本数据结构的定义、特点和应用场景,并通过C语言实现和示例代码进行演示。

3.数据结构算法和操作:介绍各种数据结构的常用算法和操作,如排序、查找、插入、删除等,并通过C语言实现和示例代码进行演示。

4.数据结构性能分析:讲解数据结构的性能评价指标,如时间复杂度和空间复杂度,能够分析不同数据结构的性能优缺点。

5.编程实践:通过实际案例和项目,让学生运用C语言实现数据结构,并进行调试和优化,培养学生的编程实践能力。

三、教学方法为了达到课程目标,本章节将采用多种教学方法进行教学,包括:1.讲授法:教师通过讲解和演示,系统地传授数据结构的基本概念、原理和方法。

2.讨论法:学生进行小组讨论,引导学生主动思考和探索数据结构的问题解决方案。

3.案例分析法:通过分析实际案例和项目,让学生运用数据结构解决实际问题,培养学生的实践能力。

川大软院计网选择题答案Chapter1(含答案)

川大软院计网选择题答案Chapter1(含答案)

In the following options, which does not define in protocol ( D )A the format of messages exchanged between two or more communicatingentitiesB the order of messages exchanged between two or more communicatingentitiesC the actions taken on the transmission of a message or other eventD the transmission signals are digital signals or analog signalsIn the following options, which is defined in protocol ( A )A the actions taken on the transmission and/or receipt of a message or othereventB the objects exchanged between communicating entitiesC the content in the exchanged messages\D the location of the hostsAn application can rely on the connection to deliver all of its data without error and in the proper order. The sentence describes (C ).A flow controlB congestion-controlC reliable data transferD connection-oriented serviceThe Internet’s connection-oriented service has a name, it is ( A ).A TCP$B UDPC TCP/IPD IPThe Internet’s connectionless service is called ( B ).A TCPB UDPC TCP/IPD IP.Which of the following nodes belongs to the network coreCA. a Web ServerB. a Host with Win2003 ServerC. a Router with NAT serviceD. a Supernode on Skype NetworkIn the Internet, the equivalent concept to end systems is ( )A.A hostsB serversC clientsD routers)In the Internet, end systems are connected together by ( C ).A copper wireB coaxial cableC communication linksD fiber opticsEnd systems access to the Internet through its (C ).A modemsB protocolsC ISP,D socketsIn the following options, which belongs to the network core ( B )A end systemsB routersC clientsD serversEnd systems, packet switches, and other pieces of the Internet, run ( D ) that control the sending and receiving of information within the Internet.A programs#B processesC applicationsD protocolsThe internet allows ( D ) running on its end systems to exchange data with each other.A clients applicationsB server applicationsC P2P applicationsD distributed applications.The protocols of various layers are called ( A ).A the protocol stackB TCP/IPC ISPD network protocolIn the OSI reference model, the upper layers of the OSI model are, in correct orderD ASession, application, presentationBSession, presentation, applicationCSession, application, presentation, physical`DApplication, presentation, sessionThe lower layers of the OSI model are, in correct orderDAphysical, system, network, logicalBphysical, logical, network, systemCphysical, transport, network, data linkDphysical, data link, network, transportThe Internet Protocol (IP) generally corresponds to which OSI layerA ANetwork (layer three)^BTransport (layer four)CData link (layer two)DSession (layer five)What layer of the OSI model is designed to perform error detection functionsB APhysicalBData linkCNetworkDtransport。

川大数据结构课程设计

川大数据结构课程设计

川大数据结构课程设计一、课程目标知识目标:1. 学生能够理解数据结构的基本概念,掌握线性表、栈、队列、树和图等常见数据结构的特点与应用。

2. 学生能够描述不同数据结构在解决实际问题中的优势与局限,并分析其时间复杂度和空间复杂度。

3. 学生能够运用所学知识设计简单算法,解决实际问题。

技能目标:1. 学生能够运用C/C++等编程语言实现常见数据结构及其基本操作。

2. 学生能够运用数据结构知识对实际问题进行分析,选择合适的数据结构并编写相应算法。

3. 学生能够运用调试工具和技巧,优化程序性能,提高代码质量。

情感态度价值观目标:1. 学生通过学习数据结构,培养严谨的逻辑思维和问题分析能力。

2. 学生能够认识到数据结构在实际应用中的重要性,激发对计算机科学的兴趣和热情。

3. 学生在团队协作和讨论中,培养良好的沟通能力和合作精神。

课程性质:本课程为计算机科学与技术专业的基础课程,旨在帮助学生掌握数据结构的基本原理和方法,为后续算法分析与设计、软件工程等课程打下基础。

学生特点:大一、大二学生,具备一定的编程基础,对数据结构有一定了解,但尚不深入。

教学要求:注重理论与实践相结合,通过案例分析和实际编程,使学生更好地理解和掌握数据结构知识。

同时,注重培养学生的逻辑思维和问题解决能力,提高其计算机素养。

二、教学内容1. 线性表:介绍线性表的定义、特点和基本操作,包括顺序存储和链式存储结构,分析其优缺点及适用场景。

教材章节:第2章 线性表内容安排:2学时2. 栈与队列:讲解栈和队列的基本概念、操作及应用,分析其时间复杂度和空间复杂度。

教材章节:第3章 栈和队列内容安排:2学时3. 树与二叉树:阐述树和二叉树的基本概念、性质、存储结构及遍历方法,介绍哈夫曼树、平衡二叉树等特殊树及其应用。

教材章节:第4章 树和二叉树内容安排:4学时4. 图:介绍图的定义、存储结构、遍历方法以及最小生成树、最短路径等算法。

教材章节:第5章 图内容安排:4学时5. 排序算法:讲解常见排序算法,如冒泡排序、插入排序、快速排序等,分析其时间复杂度和稳定性。

数据结构03-04期末考试B答案

数据结构03-04期末考试B答案

四川大学期末考试题解答(2003-2004学年第二学期)课程名: 数据结构(B) 计算机科学与技术专业适用人数:学院: 专业: 教师姓名:姓名: 学号: 成绩:一、设n个人围坐在一个圆桌周围,现在从第s个人开始报数,数到第m个人,让他出局;然后从出局的下一个人重新开始报数,数到第m个人,再让他出局,……,如此反复直到所有的人全部出局为止。

下面要解决的Josephus问题是:对于任意给定的n, s和m,求出这n个人的出局序列。

请以n = 9, s = 1, m = 5为例,人工模拟Josephus的求解过程以求得问题的解。

(9分)【解答】出局人的顺序为5, 1, 7, 4, 3, 6, 9, 2, 8。

二、列出右图所示二叉树的叶结点、分支结点和每个结点的层次。

(9分)【解答】二叉树的叶结点有⑥、⑧、⑨。

分支结点有①、②、③、④、⑤、⑦。

结点①的层次为0;结点②、③的层次为1;结点④、⑤、⑥的层次为2;结点⑦、⑧的层次为3;结点⑨的层次为4。

三.线性表可用顺序表或链表存储。

试问:(9分)(1) 两种存储表示各有哪些主要优缺点?(3分)(2) 如果有n个表同时并存,并且在处理过程中各表的长度会动态发生变化,表的总数也可能自动改变、在此情况下,应选用哪种存储表示?为什么?(3分)(3) 若表的总数基本稳定,且很少进行插入和删除,但要求以最快的速度存取表中的元素,这时,应采用哪种存储表示?为什么?(3分)【解答】(1) 顺序存储表示是将数据元素存放于一个连续的存储空间中,实现顺序存取或(按下标)直接存取。

它的存储效率高,存取速度快。

但它的空间大小一经定义,在程序整个运行期间不会发生改变,因此,不易扩充。

同时,由于在插入或删除时,为保持原有次序,平均需要移动一半(或近一半)元素,修改效率不高。

链接存储表示的存储空间一般在程序的运行过程中动态分配和释放,且只要存储器中还有空间,就不会产生存储溢出的问题。

同时在插入和删除时不需要保持数据元素原来的物理顺序,只需要保持原来的逻辑顺序,因此不必移动数据,只需修改它们的链接指针,修改效率较高。

数据结构(第4版)习题及实验参考答案数据结构复习资料完整版(c语言版)

数据结构(第4版)习题及实验参考答案数据结构复习资料完整版(c语言版)

数据结构(第4版)习题及实验参考答案数据结构复习资料完整版(c语言版)数据结构基础及深入及考试习题及实验参考答案见附录结论1、数据的逻辑结构是指数据元素之间的逻辑关系。

即从逻辑关系上描述数据,它与数据的存储无关,是独立于计算机的。

2、数据的物理结构亦称存储结构,是数据的逻辑结构在计算机存储器内的表示(或映像)。

它依赖于计算机。

存储结构可分为4大类:顺序、链式、索引、散列3、抽象数据类型:由用户定义,用以表示应用问题的数据模型。

它由基本的数据类型构成,并包括一组相关的服务(或称操作)。

它与数据类型实质上是一个概念,但其特征是使用与实现分离,实行封装和信息隐蔽(独立于计算机)。

4、算法:是对特定问题求解步骤的一种描述,它是指令的有限序列,是一系列输入转换为输出的计算步骤。

5、在数据结构中,从逻辑上可以把数据结构分成(C)A、动态结构和表态结构B、紧凑结构和非紧凑结构C、线性结构和非线性结构D、内部结构和外部结构6、算法的时间复杂度取决于(A)A、问题的规模B、待处理数据的初态C、问题的规模和待处理数据的初态线性表1、线性表的存储结构包括顺序存储结构和链式存储结构两种。

2、表长为n的顺序存储的线性表,当在任何位置上插入或删除一个元素的概率相等时,插入一个元素所需移动元素的平均次数为(E),删除一个元素需要移动的元素的个数为(A)。

A、(n-1)/2B、nC、n+1D、n-1E、n/2F、(n+1)/2G、(n-2)/23、“线性表的逻辑顺序与存储顺序总是一致的。

”这个结论是(B)A、正确的B、错误的C、不一定,与具体的结构有关4、线性表采用链式存储结构时,要求内存中可用存储单元的地址(D)A、必须是连续的B、部分地址必须是连续的C一定是不连续的D连续或不连续都可以5、带头结点的单链表为空的判定条件是(B)A、head==NULLB、head->ne某t==NULLC、head->ne某t=headD、head!=NULL6、不带头结点的单链表head为空的判定条件是(A)A、head==NULLB、head->ne某t==NULLC、head->ne某t=headD、head!=NULL7、非空的循环单链表head的尾结点P满足(C)A、p->ne某t==NULLB、p==NULLC、p->ne某t==headD、p==head8、在一个具有n个结点的有序单链表中插入一个新结点并仍然有序的时间复杂度是(B)A、O(1)B、O(n)C、O(n2)D、O(nlog2n)数据结构(第4版)习题及实验参考答案9、在一个单链表中,若删除p所指结点的后继结点,则执行(A)A、p->ne某t=p->ne某t->ne某t;B、p=p->ne某t;p->ne某t=p->ne某t->ne某t;C、p->ne某t=p->ne某t;D、p=p->ne某t->ne某t;10、在一个单链表中,若在p所指结点之后插入所指结点,则执行(B)A、->ne某t=p;p->ne某t=;B、->ne某t=p->ne某t;p->ne某t=;C、->ne某t=p->ne某t;p=;D、p->ne某t=;->ne某t=p;11、在一个单链表中,已知q是p的前趋结点,若在q和p之间插入结点,则执行(C)A、->ne某t=p->ne某t;p->ne某t=;B、p->ne某t=->ne某t;->ne某t=p;C、q->ne某t=;->ne某t=p;D、p->ne某t=;->ne某t=q;12、在线性结构中,第一个结点没有前趋结点,其余每个结点有且只有1个前趋结点。

数据结构(c语言版)课后习题答案完整版

数据结构(c语言版)课后习题答案完整版

数据结构(c语言版)课后习题答案完整版数据结构(C语言版)课后习题答案完整版一、数据结构概述数据结构是计算机科学中一个重要的概念,用来组织和存储数据,使之可以高效地访问和操作。

在C语言中,我们可以使用不同的数据结构来解决各种问题。

本文将提供完整版本的C语言数据结构的课后习题答案。

二、顺序表1. 顺序表的定义和基本操作顺序表是一种线性表,其中的元素在物理内存中连续地存储。

在C 语言中,我们可以通过定义结构体和使用指针来实现顺序表。

以下是顺序表的一些基本操作的答案:(1)初始化顺序表```ctypedef struct{int data[MAX_SIZE];int length;} SeqList;void InitList(SeqList *L){L->length = 0;}```(2)插入元素到顺序表中```cbool Insert(SeqList *L, int pos, int elem){if(L->length == MAX_SIZE){return false; // 顺序表已满}if(pos < 1 || pos > L->length + 1){return false; // 位置不合法}for(int i = L->length; i >= pos; i--){L->data[i] = L->data[i-1]; // 向后移动元素 }L->data[pos-1] = elem;L->length++;return true;}```(3)删除顺序表中的元素```cbool Delete(SeqList *L, int pos){if(pos < 1 || pos > L->length){return false; // 位置不合法}for(int i = pos; i < L->length; i++){L->data[i-1] = L->data[i]; // 向前移动元素 }L->length--;return true;}```(4)查找顺序表中的元素```cint Search(SeqList L, int elem){for(int i = 0; i < L.length; i++){if(L.data[i] == elem){return i + 1; // 找到元素,返回位置 }}return -1; // 未找到元素}```2. 顺序表习题解答(1)逆置顺序表```cvoid Reverse(SeqList *L){for(int i = 0; i < L->length / 2; i++){int temp = L->data[i];L->data[i] = L->data[L->length - 1 - i]; L->data[L->length - 1 - i] = temp;}}```(2)顺序表元素去重```cvoid RemoveDuplicates(SeqList *L){for(int i = 0; i < L->length; i++){for(int j = i + 1; j < L->length; j++){if(L->data[i] == L->data[j]){Delete(L, j + 1);j--;}}}}```三、链表1. 单链表单链表是一种常见的链式存储结构,每个节点包含数据和指向下一个节点的指针。

四川大学网络教育《数据结构》第二次作业答案

四川大学网络教育《数据结构》第二次作业答案

首页- 我的作业列表- 《数据结构》第二次作业答案欢迎你,你的得分:76.0完成日期:2014年01月09日18点12分说明:每道小题括号里的答案是您最高分那次所选的答案,标准答案将在本次作业结束(即2014年03月13日)后显示在题目旁边。

一、单项选择题。

本大题共25个小题,每小题2.0 分,共50.0分。

在每小题给出的选项中,只有一项是符合题目要求的。

若有序表为(b, c, d, e, f, g, q, r, s, t),则在二分查找关键字b的过程中,先后进行比较的关键字依次为()。

1( A )f,c,bf,d,bg,c,bg,d,b在对n个关键字进行直接选择排序的过程中,每一趟都要从无序区选出最小关键字元素,则在进行第i趟排序之前,无序区中元素的个数为()。

2( D )ii+1n-in-i+1若用邻接矩阵表示一个有向图,则其中每一列包含的″1″的个数为()。

3( A )图中每个顶点的入度图中每个顶点的出度图中每个顶点的度图中连通分量的数目一散列表长度m为100,采用除留余数法构造散列函数,即H(K)=K%P (P<=m),,为使散列函数具有较好的性能,P的选择应是()。

4( D )991009793二维数组A[8][9]按行优先顺序存储,若数组元素A[2][3]的存储地址为1087,A[4][7]的存储地址为1153,则数组元素A[6][7]的存储地址为()。

5( A )1207120912111213对关键字序列(56, 23, 78, 92, 88, 67, 19, 34)进行增量为3的一趟希尔排序的结果为()。

6( D )(19, 23, 56, 34, 78, 67, 88, 92) )(23, 56, 78, 66, 88, 92, 19, 34)(19, 23, 34, 56, 67, 78, 88, 92)(19, 23, 67, 56, 34, 78, 92, 88对线性表,在下列哪种情况下应当采用链表表示?( )7( A )经常需要随机地存取元素经常需要进行插入和删除操作表中元素需要占据一片连续的存储空间表中元素的个数不变一个栈的输入序列为1 2 3,则下列序列中不可能是栈的输出序列的是( )。

(完整版)数据结构课后习题答案

(完整版)数据结构课后习题答案

第1章绪论1.简述下列概念:数据、数据元素、数据项、数据对象、数据结构、逻辑结构、存储结构、抽象数据类型。

答案:数据:是客观事物的符号表示,指所有能输入到计算机中并被计算机程序处理的符号的总称。

如数学计算中用到的整数和实数,文本编辑所用到的字符串,多媒体程序处理的图形、图像、声音、动画等通过特殊编码定义后的数据。

数据元素:是数据的基本单位,在计算机中通常作为一个整体进行考虑和处理。

在有些情况下,数据元素也称为元素、结点、记录等。

数据元素用于完整地描述一个对象,如一个学生记录,树中棋盘的一个格局(状态)、图中的一个顶点等。

数据项:是组成数据元素的、有独立含义的、不可分割的最小单位。

例如,学生基本信息表中的学号、姓名、性别等都是数据项。

数据对象:是性质相同的数据元素的集合,是数据的一个子集。

例如:整数数据对象是集合N={0,±1,±2,…},字母字符数据对象是集合C={‘A’,‘B’,…,‘Z’,‘a’,‘b’,…,‘z’},学生基本信息表也可是一个数据对象。

数据结构:是相互之间存在一种或多种特定关系的数据元素的集合。

换句话说,数据结构是带“结构”的数据元素的集合,“结构”就是指数据元素之间存在的关系。

逻辑结构:从逻辑关系上描述数据,它与数据的存储无关,是独立于计算机的。

因此,数据的逻辑结构可以看作是从具体问题抽象出来的数学模型。

存储结构:数据对象在计算机中的存储表示,也称为物理结构。

抽象数据类型:由用户定义的,表示应用问题的数学模型,以及定义在这个模型上的一组操作的总称。

具体包括三部分:数据对象、数据对象上关系的集合和对数据对象的基本操作的集合。

2.试举一个数据结构的例子,叙述其逻辑结构和存储结构两方面的含义和相互关系。

答案:例如有一张学生基本信息表,包括学生的学号、姓名、性别、籍贯、专业等。

每个学生基本信息记录对应一个数据元素,学生记录按顺序号排列,形成了学生基本信息记录的线性序列。

《数据结构》四川大学_期终复习试题+答案

《数据结构》四川大学_期终复习试题+答案

四川大学“精品课程”计算机科学与技术专业(本科)《数据结构与算法分析》课程考试说明与模拟试卷第一部分考试说明数据结构与算法分析》是计算机科学与技术专业统设的一门重要的必修专业基础课,它主要研究数据的各种逻辑结构和在计算机中的存储结构,还研究对数据进行的插入、查找、删除、排序、遍历等基本运算或操作以及这些运算在各种存储结构上具体实现的算法。

由于本课程的主教材采用C++语言描述算法,期末卷面考试也采用C++语言描述,因而要求在做平时作业和上机实验操作时用C++开发工具(如:Visual C++或C++ Builder或Borland C++)。

下面按照主教材中各章次序给出每章的具体复习要求,以便同学们更好地进行期末复习。

第一章绪论重点掌握的内容:1. 数据结构的二元组表示,对应的图形表示,序偶和边之间的对应关系。

2. 集合结构、线性结构、树结构和图结构的特点。

3. 抽象数据类型的定义和表示方法。

4. 一维和二维数组中元素的按下标和按地址的访问方式以及相互转换,元素地址和数组地址的计算,元素占用存储空间大小和数组占用存储空间大小的计算。

5. 普通函数重载和操作符函数重载的含义,定义格式和调用格式。

6. 函数定义中值参数和引用参数的说明格式及作用,函数被调用执行时对传送来的实际参数的影响。

7. 算法的时间复杂度和空间复杂度的概念,计算方法,数量级表示。

8. 一个简单算法的最好、最差和平均这三种情况的时间复杂度的计算。

对于本章的其余内容均作一般掌握。

第二章线性表重点掌握的内容:1. 线性表的定义及判别和抽象数据类型的描述,线性表中每一种操作的功能,对应的函数名、返回值类型和参数表中每个参数的作用。

2. 线性表的顺序存储结构的类型定义,即List类型的定义和每个域的定义及作用。

3. 线性表的每一种运算在顺序存储结构上实现的算法,及相应的时间复杂度。

4.链接存储的概念,线性表的单链接和双链接存储的结构,向单链表中一个结点之后插入新结点或从单链表中删除一个结点的后继结点的指针链接过程。

川大软院计网选择题答案Chapter4(含答案)

川大软院计网选择题答案Chapter4(含答案)

CHAPTER 4: NETWORK LAYER1.Which of the following groups belongs to network layer protocol? _____D____A.IP, TCP and UDPB.ARP, IP, and UDPC.FTP, IMAP and IPD.ICMP, BGP, and RIP2.The 3-PDU is named as ____C_____A.messageB.packetC.datagramD.segment3.In a datagram network, the forwarding decision is based on the value of the____B field in the packet header.A.source addressB.destination addressbelD.None of the choices are4.HOL blocking happens on ____A_____A.input portB.output portC.switching fabricsD.all of above5.If no free buffers in router, the arriving packets will be: AA.droppedB.queuedC.returnedD.marked6.During normal IP packet forwarding at a router, which of the following packetfields are updated? ____C____A.Source IP addressB.Destination IP addressC.ChecksumD.Destination port number7.Which of the following IP address doesn’t belong to the 202.115.32.0/25 network?______D___A.202.115.32.1B.202.115.32.11C.202.115.32.120D.202.115.32.1298.You are given an IP network of 192.168.5.0 and told that you need to separatethis network into sub networks that can support a maximum of 30 hosts per subnet.This will help alleviate congestion on the network. What subnet mask can you use to create the subnets necessary to meet the given criteria? ___C______A.255.255.255.0B.255.255.255.128C.255.255.255.224D.255.255.255.2409.An IP datagram of 1500 bytes (20 byte of IP header plus 1480 bytes of IP payload)arrives at a router and must be forwarded to a link with an MTU of 500 bytes.Thus the router has to fragment the datagram. To the last fragment, the value of offset should be _____D____A.1440B.1000C.186D.18010.IP is a ____C_____ protocol.A.connection-oriented unreliableB.connection-oriented reliableC.connectionless unreliableD.connectionless reliable11.Which ICMP message type is the basis for the Traceroute utility?BA.Echo RequestB.TTL expiredC.Host UnreachableD.Fragment Reassembly Time Exceed12.Routers in the path are not allowed to _________________B__________.A.fragment the packet they receiveB.change source or destination addressC.decapsulate the packetD.All of the choices are correct13.____B_____ allows a site to use a set of private addresses for internalcommunication and a set of global Internet addresses for communication with the rest of the world.A.DHCPB.NATC.ICMPD.None of the choices are correct14.How many bits are there in IPv6 ? ______C___A.32B.64C.128D.25615.In CIDR notation, which of the following networks contains host 192.168.14.2?CA.192.168.10.0/22B.192.168.11.0/21C.192.168.12.0/23D.192.168.13.0/2416.What is the limited broadcast address corresponding to the node with thefollowing IP address: 131.15.46.59?DA.131.15.46.255B.131.15.255.255C.255.255.255.255D.None of the above17.In classful IP addressing, how many network bits does 125.140.128.16 have?AA.8B.16C.24D.3218.What is the broadcast IP address for 193.140.141.128 / 26 ?DA.193.140.141.128B.193.140.141.127C.255.255.255.63D.193.140.141.19119.What’s a network? From IP address perspective they can physically reach eachother without intervening router and the device interfaces with: CA.same IP addressB.same TCP port #C.same network part of IP addressD.same host part of IP address20.The Internet’s network layer has three major components, the first component isthe IP protocol, the second component is the routing protocol, the final component is____.DA.forwardingB.address translationC.checkD.ICMP21.IP addressing assigns an address to 223.10.198.250/29, the network address forthis network is____.A()A.223.10.198.248B.223.10.198.250C.223.10.198.0D.223.10.0.022.There are two 16-bit integers: 1110 0110 0110 0110, 1101 0101 0101 0101. Theirchecksum isA____.A.0100010001000011B.1011101110111100C.1111111111111111D.100000000000000023.The use of hierarchy in routing tables can __A______ the size of the routingtables.A.reduceB.increaseC.neither reduce nor increaseD.None of the choices are correct24.Which of the following protocol doesn’t belong to intra-AS routing protocol?_____B____A.RIPB.BGPC.OSPFD.IRAP25.Which of the following protocol belongs to intra-AS routing protocol?______A___A.RIPB.BGPC.DV (Distance Vector)D.LS (Link State)26.In OSPF network, a ____B_____ belongs to both an area and the backbone.A.internal routerB.area border routerC.boundary routerD.backbone router27._A___ is an inter-domain routing protocol using path vector routing.A.BGPB.RIPC.OSPFD.None of the choices are correct28.RIP uses the services of ___C____.A.TCPB.IPC.UDPD.None of the choices are correct29.The Routing Information Protocol (RIP) is an intra-domain routing based on_______A__ routing.A.distance vectorB.link stateC.path vectorD.all of the above30.Which of the following algorithm has the so called count-to-infinity problem?CA.Flooding algorithmB.Link-state algorithmC.Distance vector algorithmD.None of the above。

川大软件数据结构选择题库

川大软件数据结构选择题库

川大软件数据结构选择题库Chapter 1 Data Structures and Algorithms: Instructor's CD questions1. The primary purpose of most computer programs isa) to perform a mathematical calculation.*b) to store and retrieve information.c) to sort a collection of records.d) all of the above.e) none of the above.2. An integer is a*a) simple typeb) aggregate typec) composite typed) a and be) none of the above3. A payroll records is aa) simple typeb) aggregate typec) composite type*d) a and be) none of the above4. Which of the following should NOT be viewed as an ADT?a) listb) integerc) array*d) none of the above5. A mathematical function is most like a*a) Problemb) Algorithmc) Program6. An algorithm must be or do all of the following EXCEPT:a) correctb) composed of concrete steps*c) ambiguousd) composed of a finite number of stepse) terminate7. A solution is efficient ifa. it solves a problem within the require resource constraints.b. it solves a problem within human reaction time.c. it solves a problem faster than other known solutions.d. a and b.*e. a and c.f. b and c.8. An array isa) A contiguous block of memory locations where each memory location stores a fixed-length data item.b) An ADT composed of a homogeneous collection of data items, each data item identified by a particular number.c) a set of integer values.*d) a and b.e) a and c.f) b and c.9. Order the following steps to selecting a data structure to solve a problem.(1) Determine the basic operations to be supported.(2) Quantify the resource constraints for each operation.(3) Select the data structure that best meets these requirements.(4) Analyze the problem to determine the resourceconstraints that anysolution must meet.a) (1, 2, 3, 4)b) (2, 3, 1, 4)c) (2, 1, 3, 4)*d) (1, 2, 4, 3)e) (1, 4, 3, 2)10. Searching for all those records in a database with key value between 10 and 100 is known as:a) An exact match query.*b) A range query.c) A sequential search.d) A binary search.Chapter 2 Mathematical Preliminaries: Instructor's CD questions1. A set has the following properties:a) May have duplicates, element have a position.b) May have duplicates, elements do not have a position.c) May not have duplicates, elements have a position.*d) May not have duplicates, elements do not have a position.2. A sequence has the following properties:*a) May have duplicates, element have a position.b) May have duplicates, elements do not have a position.c) May not have duplicates, elements have a position.d) May not have duplicates, elements do not have a position.3. For set P, the notation |P| indicates*a) The number of elements in P.b) The inverse of P.c) The powerset of P.d) None of the above.4. Assume that P contains n elements. The number of sets in the powerset of P isa) nb) n^2*c) 2^nd) 2^n - 1e) 2^n + 15. If a sequence has n values, then the number of permutations for that sequence will bea) nb) n^2c) n^2 - 1d) 2^n*e) n!6. If R is a binary relation over set S, then R is reflexive if*a) aRa for all a in S.b) whenever aRb, then bRa, for all a, b in S.c) whenever aRb and bRa, then a = b, for all a, b in S.d) whenever aRb and aRc, then aRc, for all a, b, c in S.7. If R is a binary relation over set S, then R is transitive ifa) aRa for all a in S.b) whenever aRb, then bRa, for all a, b in S.c) whenever aRb and bRa, then a = b, for all a, b in S.*d) whenever aRb and aRc, then aRc, for all a, b, c in S.8. R is an equivalence relation on set S if it is*a) reflexive, symmetric, transitive.b) reflexive, antisymmetric, transitive.c) symmetric, transitive.d) antisymmetric, transitive.e) irreflexive, symmetric, transitive.f) irreflexive, antisymmetric, transitive.9. For the powerset of integers, the subset operation defines*a) a partial order.b) a total order.c) a transitive order.d) none of the above.10. log nm is equal toa) n + m*b) log n + log mc) m log nd) log n - log m11. A close-form solution isa) an analysis for a program.*b) an equation that directly computes the value of a summation.c) a complete solution for a problem.12. Mathematical induction is most likea) iteration.*b) recursion.c) branching.d) divide and conquer.13. A recurrence relation is often used to model programs witha) for loops.b) branch control like "if" statements.*c) recursive calls.d) function calls.14. Which of the following is not a good proof technique.a) proof by contradiction.*b) proof by example.c) proof by mathematical induction.15. We can use mathematical induction to:a) Find a closed-form solution for a summation.*b) Verify a proposed closed-form solution for a summation.c) Both find and verify a closed-form solution for a summation.Chapter 3 Algorithm Analysis: Instructor's CD questions1. A growth rate applies to:a) the time taken by an algorithm in the average case.b) the time taken by an algorithm as the input size grows.c) the space taken by an algorithm in the average case.d) the space taken by an algorithm as the input size grows.e) any resource you wish to measure for an algorithm in the averagecase.*f) any resource you wish to measure for an algorithm as the input size grows.2. Pick the growth rate that corresponds to the most efficient algorithm as n gets large:a) 5n*b) 20 log nc) 2n^2d) 2^n3. Pick the growth rate that corresponds to the most efficient algorithm when n =4.a) 5nb) 20 log nc) 2n^2*d) 2^n4. Pick the quadratic growth rate.a) 5nb) 20 log n*c) 2n^2d) 2^n5. Asymptotic analysis refers to:a) The cost of an algorithm in its best, worst, or average case.*b) The growth in cost of an algorithm as the input size grows towards infinity.c) The size of a data structure.d) The cost of an algorithm for small input sizes6. For an air traffic control system, the most important metric is:a) The best-case upper bound.b) The average-case upper bound.*c) The worst-case upper bound.d) The best-case lower bound.e) The average-case lower bound.f) The worst-case lower bound.7. When we wish to describe the upper bound for a problem we use:*a) The upper bound of the best algorithm we know.b) The lower bound of the best algorithm we know.c) We can't talk about the upper bound of a problem because there canalways be an arbitrarily slow algorithm.8. When we describe the lower bound for a problem we use:a) The upper bound for the best algorithm we know.b) the lower bound for the best algorithm we know.c) The smallest upper bound that we can prove for the bestalgorithmthat could possibly exist.*d) The greatest lower bound that we can prove for the best algorithm that could possibly exist.9. When the upper and lower bounds for an algorithm are the same, we use:a) big-Oh notation.b) big-Omega notation.*c) Theta notation.d) asymptotic analysis.e) Average case analysis.f) Worst case analysis.10. When performing asymptotic analysis, we can ignore constants and low order terms because:*a) We are measuring the growth rate as the input size gets large.b) We are only interested in small input sizes.c) We are studying the worst case behavior.d) We only need an approximation.11. The best case for an algorithm refers to:a) The smallest possible input size.*b) The specific input instance of a given size that gives the lowest cost.c) The largest possible input size that meets the required growth rate.d) The specific input instance of a given size that gives the greatestcost.12. For any algorithm:*a) The upper and lower bounds always meet, but we mightnot know what they are.b) The upper and lower bounds might or might not meet.c) We can always determine the upper bound, but might not be able to determine the lower bound.d) We can always determine the lower bound, but might not be able to determine the upper bound.13. If an algorithm is Theta(f(n)) in the average case, then it is:a) Omega(f(n)) in the best case.*b) Omega(f(n)) in the worst case.c) O(f(n)) in the worst case.14. For the purpose of performing algorithm analysis, an important property of a basic operation is that:a) It be fast.b) It be slow enough to measure.c) Its cost does depend on the value of its operands.*d) Its cost does not depend on the value of its operands.15. For sequential search,a) The best, average, and worst cases are asymptotically the same.*b) The best case is asymptotically better than the average and worst cases.c) The best and average cases are asymptotically better than the worst case.d) The best case is asymptotically better than the average case, and the average case is asymptotically better than the worst case.Chapter 4 Lists, Stacks and Queues: Instructor's CD questions1. An ordered list is one in which:a) The element values are in sorted order.*b) Each element a position within the list.2. An ordered list is most like a:a) set.b) bag.*c) sequence.3. As compared to the linked list implementation for lists, thearray-based list implementation requires:a) More spaceb) Less space*c) More or less space depending on how many elements are in the list.4. Here is a series of C++ statements using the list ADT in the book.L1.append(10);L1.append(20);L1.append(15);If these statements are applied to an empty list, the result will look like:a) < 10 20 15 >*b) < | 10 20 15 >c) < 10 20 15 | >d) < 15 20 10 >e) < | 15 20 10 >f) < 15 20 10 | >5. When comparing the array-based and linked implementations, the array-based implementation has: *a) faster direct access to elements by position,but slower insert/delete from the current position.b) slower direct access to elements by position,but faster insert/delete from the current position.c) both faster direct access to elements by position, and faster insert/delete from the current position.d) both slower direct access to elements by position, and slower insert/delete from the current position.6. For a list of length n, the linked-list implementation's prevfunction requires worst-case time:a) O(1).b) O(log n).*c) O(n).d) O(n^2).7. Finding the element in an array-based list with a given key valuerequires worst case time:a) O(1).b) O(log n).*c) O(n).d) O(n^2).8. In the linked-list implementation presented in the book, a headernode is used:*a) To simplify special cases.b) Because the insert and delete routines won't work correctly withoutit.c) Because there would be no other way to make the current pointerindicate the first element on the list.9. When a pointer requires 4 bytes and a data element requires 4bytes, the linked list implementation requires less space thanthe array-based list implementation when the array would be:a) less than 1/4 full.b) less than 1/3 full.*c) less than half full.d) less than 2/3 full.e) less than 3/4 fullf) never.10. When a pointer requires 4 bytes and a data element requires 12bytes, the linked list implementation requires less space than the array-based list implementation when the array would be: *a) less than 1/4 full.b) less than 1/3 full.c) less than half full.d) less than 2/3 full.e) less than 3/4 fullf) never.11. When we say that a list implementation enforces homogeneity, wemean that:a) All list elements have the same size.*b) All list elements have the same type.c) All list elements appear in sort order.12. When comparing the doubly and singly linked list implementations,we find that the doubly linked list implementation*a) Saves time on some operations at the expense of additional space.b) Saves neither time nor space, but is easier to implement.c) Saves neither time nor space, and is also harder toimplement.13. We use a comparator function in the Dictionary class ADT:a) to simplify implementation.*b) to increase the opportunity for code reuse.c) to improve asymptotic efficiency of some functions.14. All operations on a stack can be implemented in constant timeexcept:a) Pushb) Popc) The implementor's choice of push or pop (they cannot both beimplemented in constant time).*d) None of the above.15. Recursion is generally implemented usinga) A sorted list.*b) A stack.c) A queue.Chapter 5 Binary Trees: Instructor's CD questions1. The height of a binary tree is:a) The height of the deepest node.b) The depth of the deepest node.*c) One more than the depth of the deepest node.2. A full binary tree is one in which:*a) Every internal node has two non-empty children.b) all of the levels, except possibly the bottom level, are filled.3. The relationship between a full and a complete binary tree is:a) Every complete binary tree is full.b) Every full binary tree is complete.*c) None of the above.4. The Full Binary Tree Theorem states that:*a) The number of leaves in a non-empty full binary tree is one more than the number of internal nodes.b) The number of leaves in a non-empty full binary tree is one less than the number of internal nodes.c) The number of leaves in a non-empty full binary tree is one half of the number of internal nodes.d) The number of internal nodes in a non-empty full binary tree is one half of the number of leaves.5. The correct traversal to use on a BST to visit the nodes in sortedorder is:a) Preorder traversal.*b) Inorder traversal.c) Postorder traversal.6. When every node of a full binary tree stores a 4-byte data field,two 4-byte child pointers, and a 4-byte parent pointer, the overhead fraction is approximately:a) one quarter.b) one third.c) one half.d) two thirds.*e) three quarters.f) none of the above.7. When every node of a full binary tree stores an 8-byte data field andtwo 4-byte child pointers, the overhead fraction is approximately:a) one quarter.b) one third.*c) one half.d) two thirds.e) three quarters.f) none of the above.8. When every node of a full binary tree stores a 4-byte data fieldand the internal nodes store two 4-byte child pointers, the overhead fraction is approximately:a) one quarter.b) one third.*c) one half.d) two thirds.e) three quarters.f) none of the above.9. If a node is at position r in the array implementation for acomplete binary tree, then its parent is at:*a) (r - 1)/2 if r > 0b) 2r + 1 if (2r + 1) < nc) 2r + 2 if (2r + 2) < nd) r - 1 if r is evene) r + 1 if r is odd.10. If a node is at position r in the array implementation for acomplete binary tree, then its right child is at:a) (r - 1)/2 if r > 0b) 2r + 1 if (2r + 1) < n*c) 2r + 2 if (2r + 2) < nd) r - 1 if r is evene) r + 1 if r is odd.11. Assume a BST is implemented so that all nodes in the left subtreeof a given node have values less than that node, and all nodes in the right subtree have values greater than or equal to that node.When implementing the delete routine, we must select as its replacement:a) The greatest value from the left subtree.*b) The least value from the right subtree.c) Either of the above.12. Which of the following is a true statement:a) In a BST, the left child of any node is less than the right child,and in a heap, the left child of any node is less than the right child.*b) In a BST, the left child of any node is less than the right child,but in a heap, the left child of any node could be less than or greater than the right child.c) In a BST, the left child of any node could be less or greater than the right child, but in a heap, the left child of any node must beless than the right child.d) In both a BST and a heap, the left child of any node could be either less than or greater than the right child.13. When implementing heaps and BSTs, which is the best answer?a) The time to build a BST of n nodes is O(n log n), and the time to build a heap of n nodes is O(n log n).b) The time to build a BST of n nodes is O(n), and the time tobuild a heap of n nodes is O(n log n).*c) The time to build a BST of n nodes is O(n log n), and the time to build a heap of n nodes is O(n).d) The time to build a BST of n nodes is O(n), and the time tobuild a heap of n nodes is O(n).14. The Huffman coding tree works best when the frequencies forletters area) Roughly the same for all letters.*b) Skewed so that there is a great difference in relative frequencies for various letters.15. Huffman coding provides the optimal coding when:a) The messages are in English.b) The messages are binary numbers.*c) The frequency of occurrence for a letter is independent of its context within the message.d) Never.Chapter 6 Binary Trees: Instructor's CD questions1. The primary ADT access functions used to traverse a general tree are:a) left child and right siblingb) left child and right child*c) leftmost child and right siblingd) leftmost child and next child2. The tree traversal that makes the least sense for a general treeis:a) preorder traversal*b) inorder traversalc) postorder traversal3. The primary access function used to navigate the general tree when performing UNION/FIND is:a) left childb) leftmost childc) right childd) right sibling*e) parent4. When using the weighted union rule for merging disjoint sets, the maximum depth for any node in a tree of size n will be:a) nearly constant*b) log nc) nd) n log ne) n^25. We use the parent pointer representation for general trees to solve which problem?a) Shortest pathsb) General tree traversal*c) Equivalence classesd) Exact-match query6. When using path compression along with the weighted union rule for merging disjoint sets, the average cost for any UNION or FIND operation in a tree of size n will be:*a) nearly constantb) log nc) nd) n log n7. The most space efficient representation for general trees will typically be:a) List of children*b) Left-child/right siblingc) A K-ary tree.8. The easiest way to represent a general tree is to:a) convert to a list.*b) convert to a binary tree.c) convert to a graph.9. As K gets bigger, the ratio of internal nodes to leaf nodes:*a) Gets smaller.b) Stays the same.c) Gets bigger.d) Cannot be determined, since it depends on the particular configuration of the tree.10. A sequential tree representation is best used for:*a) Archiving the tree to disk.b) Use in dynamic in-memory applications.c) Encryption algorithms.d) It is never better than a dynamic representation.Chapter 7 Internal Sorting: Instructor's CD questions1. A sorting algorithm is stable if it:a) Works for all inputs.*b) Does not change the relative ordering of records with identical key values.c) Always sorts in the same amount of time (within a constant factor) for a given input size.2. Which sorting algorithm does not have any practical use?a) Insertion sort.*b) Bubble sort.c) Quicksort.d) Radix Sort.e) a and b.3. When sorting n records, Insertion sort has best-case cost:a) O(log n).c) O(n log n).d) O(n^2)e) O(n!)f) None of the above.4. When sorting n records, Insertion sort has worst-case cost:a) O(log n).b) O(n).c) O(n log n).*d) O(n^2)e) O(n!)f) None of the above.5. When sorting n records, Quicksort has worst-case cost:a) O(log n).b) O(n).c) O(n log n).*d) O(n^2)e) O(n!)f) None of the above.6. When sorting n records, Quicksort has average-case cost:a) O(log n).b) O(n).*c) O(n log n).d) O(n^2)e) O(n!)f) None of the above.7. When sorting n records, Mergesort has worst-case cost:a) O(log n).*c) O(n log n).d) O(n^2)e) O(n!)f) None of the above.8. When sorting n records, Radix sort has worst-case cost:a) O(log n).b) O(n).c) O(n log n).d) O(n^2)e) O(n!)*f) None of the above.9. When sorting n records with distinct keys, Radix sort has a lower bound of:a) Omega(log n).b) Omega(n).*c) Omega(n log n).d) Omega(n^2)e) Omega(n!)f) None of the above.10. Any sort that can only swap adjacent records as an average case lower bound of:a) Omega(log n).b) Omega(n).c) Omega(n log n).*d) Omega(n^2)e) Omega(n!)f) None of the above.11. The number of permutations of size n is:a) O(log n).c) O(n log n).d) O(n^2)*e) O(n!)f) None of the above.12. When sorting n records, Selection sort will perform how many swaps in the worst case?a) O(log n).*b) O(n).c) O(n log n).d) O(n^2)e) O(n!)f) None of the above.13. Shellsort takes advantage of the best-case behavior of which sort? *a) Insertion sortb) Bubble sortc) Selection sortd) Shellsorte) Quicksortf) Radix sort14. A poor result from which step causes the worst-case behavior for Quicksort? *a) Selecting the pivotb) Partitioning the listc) The recursive call15. In the worst case, the very best that a sorting algorithm can dowhen sorting n records is:a) O(log n).b) O(n).*c) O(n log n).e) O(n!)f) None of the above.Chapter 8 File Processing and External Sorting: Instructor's CD questions1. As compared to the time required to access one unit of data frommain memory, accessing one unit of data from disk is:a) 10 times faster.b) 1000 times faster.c) 1,000,000 time faster.d) 10 times slower.e) 1000 times slower.*f) 1,000,000 times slower.2. The most effective way to reduce the time required by a disk-based program is to:a) Improve the basic operations.*b) Minimize the number of disk accesses.c) Eliminate the recursive calls.d) Reduce main memory use.3. The basic unit of I/O when accessing a disk drive is:a) A byte.*b) A sector.c) A cluster.d) A track.e) An extent.4. The basic unit for disk allocation under DOS or Windows is:a) A byte.b) A sector.*c) A cluster.d) A track.e) An extent.5. The most time-consuming part of a random access to disk is usually: *a) The seek.b) The rotational delay.c) The time for the data to move under the I/O head.6. The simplest and most commonly used buffer pool replacement strategy is:a) First in/First out.b) Least Frequently Used.*c) Least Recently Used.7. The C++ programmer's view of a disk file is most like:*a) An array.b) A list.c) A tree.d) A heap.8. In external sorting, a run is:*a) A sorted sub-section for a list of records.b) One pass through a file being sorted.c) The external sorting process itself.9. The sorting algorithm used as a model for most external sorting algorithms is:a) Insertion sort.b) Quicksort.*c) Mergesort.d) Radix Sort.10. Assume that we wish to sort ten million records each 10 bytes long (for a total file size of 100MB of space). We have working memory of size 1MB, broken into 1024 1K blocks. Usingreplacement selection and multiway merging, we can expect to sort this file using how many passes through the file?a) About 26 or 27 (that is, log n).b) About 10.c) 4.*d) 2.Chapter 9 Searching: Instructor's CD questions1. Which is generally more expensive?a) A successful search.*b) An unsuccessful search.2. When properly implemented, which search method is generally the most efficient for exact-match queries?a) Sequential search.b) Binary search.c) Dictionary search.d) Search in self-organizing lists*e) Hashing3. Self-organizing lists attempt to keep the list sorted by:a) value*b) frequency of record accessc) size of record4. The 80/20 rule indicates that:a) 80% of searches in typical databases are successful and 20% are not.*b) 80% of the searches in typical databases are to 20% of the records. c) 80% of records in typical databases are of value, 20% are not.5. Which of the following is often implemented using a self-organizing list? *a) Buffer pool.b) Linked list.c) Priority queue.6. A hash function must:*a) Return a valid position within the hash table.b) Give equal probability for selecting an slot in the hash table.c) Return an empty slot in the hash table.7. A good hash function will:a) Use the high-order bits of the key value.b) Use the middle bits of the key value.c) Use the low-order bits of the key value.*d) Make use of all bits in the key value.8. A collision resolution technique that places all records directlyinto the hash table is called:a) Open hashing.b) Separate chaining.*c) Closed hashing.d) Probe function.。

数据结构课程设计参考答案a组课案

数据结构课程设计参考答案a组课案

/*二叉树的层次遍历*/#include<stdio.h>#include<stdlib.h>#include<conio.h>#include<string.h>#define TREEMAX 50typedef struct node{char data;struct node *lchild;struct node *rchild;} Node;// 递归创建二叉树Node *CreateBT(){Node *t;char x;scanf("%c", &x);fflush(stdin);if(x=='#')t=NULL;else{t=new Node;t->data=x;printf("\t\t请输入%c结点的左子结点: ",t->data);t->lchild=CreateBT();printf("\t\t请输入%c结点的右子结点: ",t->data);t->rchild=CreateBT();}return t;}// 递归先序遍历二叉树void Preorder(Node *T){if(T){printf("%3c",T->data);Preorder(T->lchild);Preorder(T->rchild);}}// 递归中序遍历二叉树void Inorder(Node *T){if(T){Inorder(T->lchild);printf("%3c",T->data);Inorder(T->rchild);}}// 递归后序遍历二叉树void Postorder(Node *T){if(T){Postorder(T->lchild);Postorder(T->rchild);printf("%3c",T->data);}}// 非递归先序遍历二叉树void noRecursivePreorder(Node *T) {Node *St[TREEMAX],*p;int top=-1;if(T!=NULL){top++;St[top]=T;while(top>-1){p=St[top];top--;printf("%c",p->data);if(p->rchild!=NULL){top++;St[top]=p->rchild;}if(p->lchild!=NULL){top++;St[top]=p->lchild;}}printf("\n");}}// 非递归中序遍历二叉树void noRecursiveInorder(Node *T){Node *St[TREEMAX],*p;int top=-1;if(T!=NULL){p=T;while(top>-1||p!=NULL){while(p!=NULL){top++;St[top]=p;p=p->lchild;}if(top>-1){p=St[top];top--;printf("%c",p->data);p=p->rchild;}}printf("\n");}// 非递归后序遍历二叉树void noRecursivePostorder(Node *T){Node *St[TREEMAX],*p;int flag,top=-1;if(T!=NULL){do{while(T!=NULL){top++;St[top]=T;T=T->lchild;}p=NULL;flag=1;while(top!=-1&&flag){T=St[top];if(T->rchild==p){printf("%c",T->data);top--;p=T;}else{T=T->rchild;flag=0;}}}while(top!=-1);printf("\n");}}// 层次遍历二叉树,用queue数组充当顺序队列void LevelOrder(Node *T){Node *queue[TREEMAX], *p;int pre=-1, rear=-1;// 树根结点先进队queue[++pre]=T;// 当队列不为空时,出队一个结点的同时将其左右孩子进队while((pre-rear+TREEMAX)%TREEMAX!=0){p=queue[++rear]; // 出队一个结点并输出printf("%3c", p->data);if(p->lchild!=NULL) // 左孩子存在则进队queue[++pre]=p->lchild;if(p->rchild!=NULL) // 右孩子存在则进队queue[++pre]=p->rchild;}}void list(){printf("\n");printf("\n\t\t 二叉链表");printf("\n\t\t****************************************");printf("\n\t\t* 1.建立二叉树 *");printf("\n\t\t* 2.递归前序遍历 *");printf("\n\t\t* 3.递归中序遍历 *");printf("\n\t\t* 4.递归后序遍历 *");printf("\n\t\t* 5.非递归前序遍历 *");printf("\n\t\t* 6.非递归中序遍历 *");printf("\n\t\t* 7.非递归后序遍历 *");printf("\n\t\t* 8.层次遍历 *");printf("\n\t\t* 9.清屏 *");printf("\n\t\t* 0.退出程序 *");printf("\n\t\t****************************************");printf("\n\t\t请输入菜单项:");}void main(){Node *T=NULL;char a,b;b='m';while(b=='m'||b=='M'){list();scanf("%c", &a);fflush(stdin);switch(a){case'1':printf("\n\t\t请按先序序列输入二叉树的结点(输入#表示结点为空):\n");printf("\n\t\t请输入根结点:");T=CreateBT();printf("\n\t\t二叉树成功建立^-^\n");break;case'2':printf("\n\t\t该二叉树递归前序遍历为:");Preorder(T);break;case'3':printf("\n\t\t该二叉树递归中序遍历为:");Inorder(T);break;case'4':printf("\n\t\t该二叉树递归后序遍历为:");Postorder(T);break;case'5':printf("\n\t\t该二叉树非递归前序遍历为:");noRecursivePreorder(T);break;case'6':printf("\n\t\t该二叉树非递归中序遍历为:");noRecursiveInorder(T);break;case'7':printf("\n\t\t该二叉树非递归后序遍历为:");noRecursivePostorder(T);break;case'8':printf("\n\t\t该二叉树的层次遍历序列为:");LevelOrder(T);break;case'9':system("cls");break;case'0':b='n';break;default:printf("\n\t\t***对不起,输入有误!***");}}}/*多项式运算【链式结构】*/#include "stdio.h"#include "stdlib.h"typedef struct _node{float coe;int index;struct _node *next;}Node, *NodePtr;// 整理多项式链表,将链表中的结点根据各项指数进行升序排列void sortPoly(NodePtr list){NodePtr p=list->next, q=list, r, ptr;// 让p指向链表的第二个数据结点,// p为空则说明链表为空,不用整理了。

数据结构与算法分析习题及参考答案

数据结构与算法分析习题及参考答案

四川大学计算机学院《数据结构与算法分析》课程模拟试卷及参考答案模拟试卷一一、单选题(每题2 分,共20分)1.以下数据结构中哪一个是线性结构?( )A. 有向图B. 队列C. 线索二叉树D. B树2.在一个单链表HL中,若要在当前由指针p指向的结点后面插入一个由q指向的结点,则执行如下( )语句序列。

A. p=q; p->next=q;B. p->next=q; q->next=p;C. p->next=q->next; p=q;D. q->next=p->next; p->next=q;3.以下哪一个不是队列的基本运算?()A. 在队列第i个元素之后插入一个元素B. 从队头删除一个元素C. 判断一个队列是否为空D.读取队头元素的值4.字符A、B、C依次进入一个栈,按出栈的先后顺序组成不同的字符串,至多可以组成( )个不同的字符串?A.14B.5C.6D.85.由权值分别为3,8,6,2A. 11 B.35 C. 19 D. 53以下6-8题基于图1。

6.该二叉树结点的前序遍历的序列为( )。

A.E、G、F、A、C、D、BB.E、A、G、C、F、B、DC.E、A、C、B、D、G、FD.E、G、A、C、D、F、B7.该二叉树结点的中序遍历的序列为( )。

A. A、B、C、D、E、G、FB. E、A、G、C、F、B、DC. E、A、C、B、D、G、FE.B、D、C、A、F、G、E8.该二叉树的按层遍历的序列为( )。

A.E、G、F、A、C、D、B B. E、A、C、B、D、G、FC. E、A、G、C、F、B、DD. E、G、A、C、D、F、B9.下面关于图的存储的叙述中正确的是( )。

A.用邻接表法存储图,占用的存储空间大小只与图中边数有关,而与结点个数无关B.用邻接表法存储图,占用的存储空间大小与图中边数和结点个数都有关C. 用邻接矩阵法存储图,占用的存储空间大小与图中结点个数和边数都有关D.用邻接矩阵法存储图,占用的存储空间大小只与图中边数有关,而与结点个数无关10.设有关键码序列(q,g,m,z,a,n,p,x,h),下面哪一个序列是从上述序列出发建堆的结果?( )A. a,g,h,m,n,p,q,x,zB. a,g,m,h,q,n,p,x,zC. g,m,q,a,n,p,x,h,zD. h,g,m,p,a,n,q,x,z二、填空题(每空1分,共26分)1.数据的物理结构被分为_________、________、__________和___________四种。

四川大学《数据结构2264》20春在线作业1.doc

四川大学《数据结构2264》20春在线作业1.doc

1.树最适合用来表示()。

A.有序数据元素B.无序数据元素C.元素之间具有分支层次关系的数据 D.元素之间无联系的数据【参考答案】: C2.下列关于数据结构的叙述中,正确的是()。

A.数组是不同类型值的集合B.递归算法的程序结构比迭代算法的程序结构更为精炼C.树是一种线性结构D.用一维数组存储一棵完全二叉树是有效的存储方法【参考答案】: D3.从一个长度为n的顺序表中删除第i个元素()时,需向前移动的元素个数是()。

A.n-iB.n-i1C.n-i-1D.i【参考答案】: A4.若有序表为(),则在二分查找关键字b的过程中,先后进行比较的关键字依次为()。

A.f,c,bB.f,d,bC.g,c,bD.g,d,b【参考答案】: A5.以下数据结构中哪一个是非线性结构?()A.队列B.栈C.线性表D.二叉树【参考答案】: D6.队列的特点是()。

A.先进后出B.先进先出C.任意位置进出D.前面都不正确【参考答案】: B7.对n个记录进行堆排序,所需要的辅助存储空间为()。

A.O(1og2nB.O(n)C.O(1)D.O(n2)【参考答案】: C8.在数据结构中,数据元素可由()。

A.实体B.域C.数据项D.字段【参考答案】: C9.在对n个关键字进行直接选择排序的过程中,每一趟都要从无序区选出最小关键字元素,则在进行第i趟排序之前,无序区中元素的个数为()。

A.iB.i1C.n-iD.n-i1【参考答案】: C10.一散列表长度m为100,采用除留余数法构造散列函数,即H()=K%P (),,为使散列函数具有较好的性能,P的选择应是()。

A.99 B.100 C.97 D.93【参考答案】: C11.设有一个二维数组A[m][n] (),假设A[0][0]存放位置在600,A[3][3]存放位置在678,每个元素占一个空间,则A[2][3]的存放位置是()。

A.658B.648C.633D.653【参考答案】: C12.对一个算法的评价,不包括如下()方面的内容。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

四川大学《数据结构》课程设计实验项目及内容提要(实验任选一个完成)
试读3页
数据结构实验报告
实验名称: Huffman编码(二叉树应用)
提交文档学生姓名:
提交文档学生学号:
同组成员名单:无
指导教师姓名:
指导教师评阅成绩:
指导教师评阅意见:
.
.
提交报告时间: 2020 年 3 月 26 日
目录
一、概述 (1)
二、系统分析 (1)
三、概要设计 (2)
四、详细设计 (4)
4.1 赫夫曼树的建立 (4)
4.1.1 选择选择parent 为0 且权值最小的两个根结点的算
法 (5)
4.1.2 统计字符串中字符的种类以及各类字符的个数 (7)
4.1.3构造赫夫曼树 (8)
4.2赫夫曼编码 (10)
4.2.1赫夫曼编码算法 (10)
4.2.2建立正文的编码文件 (11)
4.3代码文件的译码 (12)
五、运行与测试 (14)
六、总结与心得 (14)
参考文献................................. 错误!未定义书签。

附录..................................... 错误!未定义书签。

相关文档
最新文档