《数据结构Java版》习题解答

合集下载

数据结构(JAVA)复习题及答案

数据结构(JAVA)复习题及答案

一、选择题1、数据结构在计算机内存中的表示是指____A__A.数据的存储结构 B.数据结构C.数据的逻辑结构D.数据元素之间的关系2、若一个算法的时间复杂度用T(n)表示,其中n的含义是(A)A.问题规模B.语句条数C.循环层数D.函数数量3、下列选项中与数据存储结构无关的术语是(D)A.顺序表B.链表C.链队列D.栈4、已知循环队列的存储空间大小为m,队头指针front指向队头元素,队尾指针rear指向队尾元素的下一个位置,则向队列中插入新元素时,修改指针的操作是(D)A.rear=(rear-1)%m;B.front=(front+1)%m;C.front=(front-1)%m;D.rear=(rear+1)%m;5、栈和队列的共同点是__C______A.都是先进后出B.都是先进先出C.只允许在端点处插入和删除元素D.没有共同点6、已知一堆栈的进栈序列为1234,则下列哪个序列为不可能的出栈序列______D__A.1234B.4321C.2143D.41237、具有线性结构的数据结构是(C)A.树B.图C.栈和队列D.广义表8、假设以数组A[60]存放循环队列的元素,其头指针是front=47,当前队列有50个元素,则队列的尾指针值为(B)A.3B.37C.50D.979、若栈采用链式存储结构,则下列说法中正确的是(B)A.需要判断栈满且需要判断栈空B.不需要判断栈满但需要判断栈空C.需要判断栈满但不需要判断栈空D.不需要判断栈满也不需要判断栈空10、若一棵具有n(n>0)个结点的二叉树的先序序列与后序序列正好相反,则该二叉树一定是(C)A.结点均无左孩子的二叉树B.结点均无右孩子的二叉树C.高度为n的二叉树D.存在度为2的结点的二叉树11、若一棵二叉树中度为l的结点个数是3,度为2的结点个数是4,则该二叉树叶子结点的个数是(B)A.4B.5C.7D.812、在n个结点的线索二叉树中,线索的数目为_C_______A.n-1 B.nC.n+1D.2n13、一棵完全二叉树有1001个结点,其中有____B_____叶子结点A.500B.501C.503D.50515、一个有n个顶点的无向图最多有___C____条边。

数据结构(Java版)_郑州大学中国大学mooc课后章节答案期末考试题库2023年

数据结构(Java版)_郑州大学中国大学mooc课后章节答案期末考试题库2023年

数据结构(Java版)_郑州大学中国大学mooc课后章节答案期末考试题库2023年1.对不含相同元素的同一输入序列进行两组不同的、合法的入栈和出栈组合操作,所得的输出序列一定相同。

参考答案:错误2.在链队列中,即使不设置尾指针,也能进行入队操作。

参考答案:正确3.循环顺序队列和循环链队列都存在空间一处问题。

参考答案:错误4.直接选择排序的时间复杂度与关键字的初始排列无关。

参考答案:正确5.一个循环链表可以由给定的头指针或尾指针来唯一标识。

参考答案:正确6.所谓随机存取,就是通过首地址和元素的序号可以在O(1)的时间内找到指定的元素。

参考答案:正确7.快速排序在最坏情况下的时间复杂度是O(【图片】)。

参考答案:正确8.哈夫曼树是带权路径长度最短的树,路径上权值较大的结点离根较近()参考答案:正确9.在队列中存取数据元素的原则是()。

参考答案:先进先出10.将整数1、2、3、4依次进栈,则不可能得到的出栈序列是()。

参考答案:142311.完全二叉树的存储结构通常采用顺序存储结构()。

参考答案:正确12.在中序线索二叉树中,每一非空的线索均指向其祖先结点()参考答案:正确13.二叉树中序线索化后,不存在空指针域()参考答案:错误14.二叉树的层次遍历需要栈结构的支持。

参考答案:错误15.下列关于AOE网的叙述中,不正确的是()参考答案:任何一个关键活动提前完成,那么整个工程将会提前完成16.一棵非空的二叉树的先序遍历序列与后序遍历序列正好相反,则该二叉树一定满足()参考答案:只有一个叶子结点17.引入二叉线索树的目的是()参考答案:加快查找结点的前驱或后继的速度18.单源最短路径算法的时间复杂度为()参考答案:O()19.对6个不同的数据元素进行直接插入排序,最多需要进行()次关键字的比较。

参考答案:1520.完全二叉树中,若一个结点没有左孩子,则它必是树叶()。

参考答案:正确21.已知循环队列存储在一维数组A[0【图片】n]中,且队列非空时front和rear分别指向队首元素和队尾元素。

数据结构(Java版)习题解答

数据结构(Java版)习题解答

AI N D E X练习题答案第一章练习题答案(a) n+(n–1)+(n–2)+…+2+1=2)1(+ n n (b) n+(n–1)+(n–2)+…+2+1=2)1(+nnf(n)≦c.g(n) →f(n)=O(g(n))(a) f(n)=100n+9c=101, g(n)=n, n0=10得知f(n)=O(n)(b) f(n)=1000n2+100n–8c=2000, g(n)= n2, n0=1得知f(n)=O(n2)(c) f(n)=5*2n+9 n2+2c=10, n0=5得知f(n)=O(2n)f(n)≧c g(n) →f(n)=Ω(g(n)) (a) f(n)=3n+1c=2, n0=1, g(n)=n得知f(n)=Ω(n)(b) f(n)=100n2+4n+5c=10, n0=1, g(n)= n2得知f(n)=Ω(n2)(c) f(n)=8*2n+8n+16c=8, n0=1, g(n)= 2n得知f(n)=Ω(n2)c1.g(n)≦f(n)≦c2.g(n) →f(n)= Θ(g(n))(a) f(n)=3n+2c1=3, c2=6, n0=1得知f(n) = Θ (n)(b) f(n)=9n2+4n+2c1=9, c2=16, n0=1得知f(n) = Θ (n2)(c) f(n)=8n4+5n3+5c1=8, c2=20, n0=1得知f(n) = Θ (n4)A-2练习题解答第二章练习题答案1. 分别以行为主和以列为主说明之。

(a) 以行为主A(i, j)=l0+(i–1)*u2*d+(j–1)*d(b) 以列为主A(i, j)=l0+(j–1)*u1*d+(i–1)*d2. 以列为主A(i, j)=l0+(j–12)*md+(i–l1)dm=u1–l1+1=5–(–3)+1=9m=u2–l2+1=2–(–4)+1=7A(1, 1) =100+(1–(–4))*9+(1–(–3))=100+45+4=1493. 分别以行为主和以列为主的说明。

《数据结构(Java版)叶核亚(第4版)》样卷及答案

《数据结构(Java版)叶核亚(第4版)》样卷及答案

《数据结构(Java版)》课程样卷教材:《数据结构(Java版)(第4版)》叶核亚编著,电子工业出版社,2015年7月出版。

试题范围:第1〜9章,掌握基础原理,熟悉经典算法,问答题形式考核。

编程题重点是:1•单/双链表;2•二叉树/树,递归算法。

这是必须掌握的,即使部分学生掌握不了递归算法,也必须考。

不考内容:6.3线索二叉树求父母、插入、删除算法(没写),7.5.2 Floyd , 8.5.3平衡二叉树,第10章。

可作为课程设计题。

试卷范围和难度不超过样卷。

4-0 模拟样卷填空题(16分=2分X 8题)1. 声明抽象数据类型的目的是2. 以下数据存储结构声明为table Node<T>3. 已知ng.String类声明以下成员方法:public String replaceAII(String pattern, String str)//将所有与pattern匹配的子串替换为str 下列语句的执行结果是 ______________________String target="aababbabac", pattern="ab", str="aba";System.out.println("\""+target+"\".replaceAII(\""+pattern+"\", \""+str+"\")=\""+ target.replaceAII(pattern,str)+"\"");4. A+B*(C-D*(E+F)/G+H)-(I+J)*K ________________________________ 的后缀表达式为。

5. 已知二维数组a[10][8]采用行主序存储,数组首地址是1000,每个元素占用4字节,则数组元素a[4][5] 的存储地址是6. 由n个顶点组成的无向连通图,最多有 _________________________ 条边。

数据结构Java版习题解答

数据结构Java版习题解答
return binarySearch(table, value, low, mid-1);//查找范围缩小到前半段
else
return binarySearch(table, value, mid+1, high);//查找范围缩小到后半段
}
return -1;
}
【习2.5】二叉排序树查找的递归算法。
数据结构Java版习题解答
第1章
【习1.1】实验哥德巴赫猜想。
【习1.2】实验杨辉三角形。
【习1.3】实验金额的中文大写形式。
【习1.4】实验下标和相等的数字方阵。
输出下列方阵(当n=4时)。
1267或13410
3581325911
491214681215
101115167131416
采用二维数组实现。二维数组中,每一条斜线上各元素下标和相等,如图所示。
图1.2下标和相等的数字方阵算法描述
程序如下。
public class Upmat
{
public static void main(String args[])
{
表1.1int n=4;ength; j++)8.2.18.2.1
ength, ;
for (int j=0; j<[i].length; j++)
[j][i]=[i][j];
return trans;
}
第2章
【习2.1】画出3个结点的各种形态的树和二叉树。
3个结点的树有2种形态,3个结点的二叉树有5种形态,如图所示。
图2.23个结点树和二叉树的形态
【习2.1】找出分别满足下面条件的所有二叉树。
1先根遍历序列和中根遍历序列相同:右单支二叉树,如图(a)所示。

数据结构java语言描述课后答案

数据结构java语言描述课后答案

数据结构 java 语言描述课后答案【篇一:数据机构第一章—— java 语言描述第 1 章绪论习题参考答案】概念题1.试述下列各组概念:⑴数据、数据元素、数据项⑵ 数据结构、数据的逻辑结构、数据的存储结构⑶ 数据类型、数据操作⑷ 算法、算法的时间复杂度、算法的空间复杂度参考答案 : 略2 .试述数据结构研究的3 个方面的内容。

参考答案:数据结构研究的 3 个方面分别是数据的逻辑结构、数据的存储结构和数据的运算(操作)。

3.试述集合、线性结构、树型结构和图型结构四种常用数据结构的特性。

参考答案 :集合结构:集合中数据元素之间除了“同属于一个集合”的特性外,数据元素之间无其它关系,它们之间的关系是松散性的。

线性结构:线性结构中数据元素之间存在“一对一”的关系。

即若结构非空,则它有且仅有一个开始结点和终端结点,开始结点没有前趋但有一个后继,终端结点没有后继但有一个前趋,其余结点有且仅有一个前驱和一个后继。

树形结构:树形结构中数据元素之间存在“一对多”的关系。

即若结构非空,则它有一个称为根的结点,此结点无前驱结点,其余结点有且仅有一个前驱,所有结点都可以有多个后继。

图形结构:图形结构中数据元素之间存在“多对多”的关系。

即若结构非空,则在这种数据结构中任何结点都可能有多个前驱和后继。

4 .设有数据的逻辑结构的二元组定义形式为b=(d,r) ,其中d={a1,a2,?,an},r={ai,ai+1| i=1,2,?,n-1},请画出此逻辑结构对应的顺序存储结构和链式存储结构的示意图。

参考答案 :顺序存储结构示意图如下:0 1 2 ?n-2 n-1链式存储结构示意图如下:?5 .设一个数据结构的逻辑结构如图 1.9 所示,请写出它的二元组定义形式。

图 1.9 第 5 题的逻辑结构图参考答案 :它的二元组定义形式为 b= (d ,r ),其中d={k1,k2,k3,k4,k5,k6,k7,k8,k9},r=k1,k3,k1,k8,k2,k3k2,k4,k2,k5,k3,k9,k4,k6,k4,k7,k5,k6,k8,k9,k9,k7 } 。

java数据结构期末考试题及答案

java数据结构期末考试题及答案

java数据结构期末考试题及答案一、选择题(每题2分,共20分)1. 在Java中,以下哪个类是实现了List接口的?A. ArrayListB. LinkedListC. HashSetD. TreeMap答案:A、B2. Java中HashMap是基于什么数据结构实现的?A. 链表B. 红黑树C. 二叉搜索树D. 哈希表答案:D3. 下列哪种排序算法的时间复杂度是O(n^2)?A. 快速排序B. 归并排序C. 堆排序D. 冒泡排序答案:D4. Java中哪个类提供了栈的实现?A. StackB. LinkedListC. PriorityQueueD. Deque答案:A5. 在Java中,以下哪个集合类是线程安全的?A. ArrayListB. VectorC. HashSetD. ConcurrentHashMap答案:B、D6. Java中,哪个方法可以用来清空集合中的所有元素?A. clear()B. remove()C. removeAll()D. retainAll()答案:A7. 在Java中,以下哪个类实现了Set接口?A. ArrayListB. HashSetC. LinkedListD. TreeMap答案:B8. Java中,以下哪个类是实现了Queue接口的?A. PriorityQueueB. LinkedListC. StackD. Deque答案:A、B、C、D9. 在Java中,以下哪个排序算法是稳定的?A. 快速排序B. 归并排序C. 堆排序D. 冒泡排序答案:B、D10. Java中,以下哪个方法可以用来检查集合是否包含某个元素?A. contains()B. containsKey()C. containsValue()D. allOf()答案:A、B、C二、填空题(每题2分,共20分)1. 在Java中,______类实现了Map接口,它允许空键和空值。

数据结构JAVA语言描述习题答案(刘小晶等主编).第7章 排序(Java版)

数据结构JAVA语言描述习题答案(刘小晶等主编).第7章 排序(Java版)

结束放映
12
7.1排序的基本概念
(2) 交换类
章节目录 作业布置
数据结构(Java语言描述)
通过“交换”无序序列中的记录从
而得到其中关键字最小或最大的记录,
结束放映
并将它加入到有序子序列中,以此方法
增加记录的有序子序列的长度。
13
7.1排序的基本概念
(3) 选择类
章节目录 作业布置
数据结构(Java语言描述)
无序序列 r[i..n-1]
结束放映
有序序列r[0..i]
21
无序序列 r[i+1..n-1]
7.2插入排序
数据结构(Java语言描述)
实现“一趟插入排序”可分三步进行:
章节目录
1.在r[0..i-1]中查找r[i]的插入位臵,
作业布置
r[0..j].key r[i].key < r[j+1..i-1].key; 2.将r[j+1..i-1]中的所有记录均后移 一个位臵;
7
7.1排序的基本概念
关键字
章节目录
数据结构(Java语言描述)
作业布置
结束放映
是数据元素(或记录)中某个数据项 的值,用以标识(识别)一个数据元素 (或记录)。
若此关键字可以识别唯一的一个记录, 则称之谓“主关键字”。 若此关键字能识别若干记录,则称 之谓“次关键字”。
8
7.1排序的基本概念
数据结构(Java语言描述)
7.2.1 直接插入排序-不带监视哨的算法
章节目录
基本条件:
待排序记录依次存放在数组r[0..n-1]中。
作业布置
结束放映
思想:
先将第0个记录组成一个有序的子表, 然后依次将后面的记录插入到这子表中, 且一直保持它的有序性。

《数据结构Java版》习题解答.

《数据结构Java版》习题解答.
up=!up;//方向求反
}
for (int sum=n; sum<2*n-1; sum++)//右下三角
{
if (up)
for (int j=sum-n+1;j<n;j++)
mat[sum-j][j] = k++;
else
for (int j=n-1;j>sum-n;j--)
mat[sum-j][j] = k++;
{//复制单链表
this.head = null;
if (list!=null && list.head!=null)
{
this.head = new Node(list.head.data);
Node<E> p = list.head.next;
Node<E> rear = this.head;
while (p!=null)
Comparable cmp = (Comparable)element;
if (this.head==null || pareTo(this.head.data)<=0)
this.head = new Node<E>(element,this.head);//头插入
else
{
Node<E> front=null, p=this.head;
}
比较两条单链表是否相等的操作也可设计为以下的递归方法:
public boolean equals(Object obj)//比较两条单链表是否相等
{
if (obj == this)
return true;

数据结构习题解答与实验指导

数据结构习题解答与实验指导

数据结构( Java 版) 习题解答与实验指导目录第1 章绪论11.1 数据结构的基本概念11.2 算法2第2 章线性表32.1 线性表抽象数据类型32.2 线性表的顺序存储和实现42.2.1 线性表的顺序存储结构42.2.2 顺序表52.2.3 排序顺序表72.3 线性表的链式存储和实现92.3.1 单链表9【习题2-8】单链表结点类问题讨论。

9【习2.1 ]使用单链表求解Josephu环问题。

12【习2.2】集合并运算,单链表深拷贝的应用。

142.3.2 双链表16【习2.3] 循环双链表的迭代方法。

19【习2.4] 循环双链表合并连接。

19第3 章串213.1 串抽象数据类型213.2 串的存储和实现223.2.1 串的存储结构223.2.2 常量字符串类22【习3.1 ] C/C++语言,str in g.h 中的strcpy()和strcat()函数存在下标越界错误。

22【思考题3-1】逆转String串,分析算法效率。

24【实验题3-1】MyString 类,比较串大小,忽略字母大小写。

25【例3.2思考题3-2] Mylnteger整数类,返回value的radix进制原码字符串。

26【实验题3-9] 浮点数类。

273.2.3 变量字符串类30【实验题3-11]删除变量串中的所有空格。

4-样卷303.3 串的模式匹配313.3.1 Brute-Force模式匹配算法313.3.2 模式匹配应用32【思考题3-4,实验题3-13 ] MyString 类,replaceAII(pattern,s)改错。

323.3.3 KMP模式匹配算法33第4 章栈和队列364.1 栈364.2 队列384.3 递归41【习4.1 】打印数字塔。

41第5 章数组和广义表435.1 数组435.2 特殊矩阵的压缩存储445.2.1 三角矩阵、对称矩阵和对角矩阵的压缩存储445.2.2 稀疏矩阵的压缩存储465.3 广义表48第6 章树和二叉树496.2 二叉树496.3 线索二叉树566.4 Huffman 树616.5 树的表示和实现62第7 章图637.1 图及其抽象数据类型637.2 图的表示和实现647.3 图的遍历657.4最小生成树677.5最短路径69 第8章查找728.1查找的基本概念728.2二分法查找738.4散列748.5二叉排序树7676【实验8-1】判断一棵二叉树是否为二叉排序树,改错。

JAVA数据结构习题及解答(英) GOOD

JAVA数据结构习题及解答(英) GOOD

Chapter1OverviewThese questions are intended as a self-test for readers.Answers to the questions may be found in Appendix C.1.In many data structures you can________a single record,_________it,and_______it.2.Rearranging the contents of a data structure into a certain order is called_________.3.In a database,a field isa.a specific data item.b.a specific object.c.part of a record.d.part of an algorithm.4.The field used when searching for a particular record is the______________.5.In object-oriented programming,an objecta.is a class.b.may contain data and methods.c.is a program.d.may contain classes.6.A classa.is a blueprint for many objects.b.represents a specific real-world object.c.will hold specific values in its fields.d.specifies the type of a method.7.In Java,a class specificationa.creates objects.b.requires the keyword new.c.creates references.d.none of the above.8.When an object wants to do something,it uses a________.9.In Java,accessing an object’s methods requires the_____operator.10.In Java,boolean and byte are_____________.(There are no experiments or programming projects for Chapter1.)Questions31Chapter1,OverviewAnswers to Questions1.insert,search for,delete2.sorting3.c4.search key5.b6.a7.d8.method9.dot10.data typesChapter2ArraysThese questions are intended as a self-test for readers.Answers may be found in Appendix C.1.Inserting an item into an unordered arraya.takes time proportional to the size of the array.b.requires multiple comparisons.c.requires shifting other items to make room.d.takes the same time no matter how many items there are.2.True or False:When you delete an item from an unordered array,in most cases you shift other items to fill in the gap.3.In an unordered array,allowing duplicatesa.increases times for all operations.b.increases search times in some situations.c.always increases insertion times.d.sometimes decreases insertion times.4.True or False:In an unordered array,it’s generally faster to find out an item is not in the array than to find out it is.5.Creating an array in Java requires using the keyword________.6.If class A is going to use class B for something,thena.class A’s methods should be easy to understand.b.it’s preferable if class B communicates with the program’s user.c.the more complex operations should be placed in class A.d.the more work that class B can do,the better.7.When class A is using class B for something,the methods and fields class A can access in class B are called class B’s__________.8.Ordered arrays,compared with unordered arrays,area.much quicker at deletion.b.quicker at insertion.c.quicker to create.d.quicker at searching.9.A logarithm is the inverse of_____________.10.The base10logarithm of1,000is_____.11.The maximum number of elements that must be examined to complete a binary search in an array of200elements isa.200.b.8.c.1.d.13.12.The base2logarithm of64is______.13.True or False:The base2logarithm of100is2.14.Big O notation tellsa.how the speed of an algorithm relates to the number of items.b.the running time of an algorithm for a given size data structure.c.the running time of an algorithm for a given number of items.d.how the size of a data structure relates to the number of items.15.O(1)means a process operates in_________time.16.Either variables of primitive types or_________can be placed in an array.Chapter2,ArraysAnswers to Questions1.d2.True3.b4.False5.new6.d740APPENDIX C Answers to Questions7.interface8.d9.raising to a power10.311.812.613.False14.a15.constant16.objectsChapter3Simple SortingThese questions are intended as a self-test for readers.Answers may be found in Appendix C.puter sorting algorithms are more limited than humans in thata.humans are better at inventing new algorithms.puters can handle only a fixed amount of data.c.humans know what to sort,whereas computers need to be told.puters can compare only two things at a time.2.The two basic operations in simple sorting are_________items and_________ them(or sometimes_________them).3.True or False:The bubble sort always ends up comparing every item with every other item.4.The bubble sort algorithm alternates betweenparing and swapping.b.moving and copying.c.moving and comparing.d.copying and comparing.5.True or False:If there are N items,the bubble sort makes exactly N*N comparisons.6.In the selection sort,a.the largest keys accumulate on the left(low indices).b.a minimum key is repeatedly discovered.c.a number of items must be shifted to insert each item in its correctlysorted position.d.the sorted items accumulate on the right.7.True or False:If,in a particular sorting situation,swaps take much longer than comparisons,the selection sort is about twice as fast as the bubble sort.8.A copy is________times as fast as a swap.9.What is the invariant in the selection sort?10.In the insertion sort,the“marked player”described in the text corresponds to which variable in the insertSort.java program?a.inb.outc.tempd.a[out]11.In the insertion sort,“partially sorted”means thata.some items are already sorted,but they may need to be moved.b.most items are in their final sorted positions,but a few still need to be sorted.c.only some of the items are sorted.d.group items are sorted among themselves,but items outside the groupmay need to be inserted in it.12.Shifting a group of items left or right requires repeated__________.13.In the insertion sort,after an item is inserted in the partially sorted group,it willa.never be moved again.b.never be shifted to the left.c.often be moved out of this group.d.find that its group is steadily shrinking.14.The invariant in the insertion sort is that________.15.Stability might refer toa.items with secondary keys being excluded from a sort.b.keeping cities sorted by increasing population within each state,in a sortby state.c.keeping the same first names matched with the same last names.d.items keeping the same order of primary keys without regard tosecondary keys.Chapter3,Simple SortingAnswers to Questions1.dparing and swapping(or copying)3.False4.a5.False6.b7.False8.three9.Items with indices less than or equal to outer are sorted.10.c11.d12.copies13.b14.Items with indices less than outer are partially sorted.15.bChapter4Stacks and QueuesThese questions are intended as a self-test for readers.Answers may be found in Appendix C.1.Suppose you push10,20,30,and40onto the stack.Then you pop three items. Which one is left on the stack?2.Which of the following is true?a.The pop operation on a stack is considerably simpler than the remove operation on a queue.b.The contents of a queue can wrap around,while those of a stack cannot.c.The top of a stack corresponds to the front of a queue.d.In both the stack and the queue,items removed in sequence are takenfrom increasingly high index cells in the array.3.What do LIFO and FIFO mean?4.True or False:A stack or a queue often serves as the underlying mechanism on which an ADT array is based.5.Assume an array is numbered with index0on the left.A queue representing a line of movie-goers,with the first to arrive numbered1,has the ticket window on the right.Thena.there is no numerical correspondence between the index numbers andthe movie-goer numbers.b.the array index numbers and the movie-goer numbers increase inopposite left-right directions.c.the array index numbers correspond numerically to the locations in theline of movie-goers.d.the movie-goers and the items in the array move in the same direction.6.As other items are inserted and removed,does a particular item in a queue move along the array from lower to higher indices,or higher to lower?7.Suppose you insert15,25,35,and45into a queue.Then you remove three items.Which one is left?8.True or False:Pushing and popping items on a stack and inserting and removing items in a queue all take O(N)time.9.A queue might be used to holda.the items to be sorted in an insertion sort.b.reports of a variety of imminent attacks on the star ship Enterprise.c.keystrokes made by a computer user writing a letter.d.symbols in an algebraic expression being evaluated.10.Inserting an item into a typical priority queue takes what big O time?11.The term priority in a priority queue means thata.the highest priority items are inserted first.b.the programmer must prioritize access to the underlying array.c.the underlying array is sorted by the priority of the items.d.the lowest priority items are deleted first.12.True or False:At least one of the methods in the priorityQ.java program (Listing4.6)uses a linear search.13.One difference between a priority queue and an ordered array is thata.the lowest-priority item cannot be extracted easily from the array as it can from the priority queue.b.the array must be ordered while the priority queue need not be.c.the highest priority item can be extracted easily from the priority queue but not from the array.d.All of the above.14.Suppose you based a priority queue class on the OrdArray class in the orderedArray.java program(Listing2.4)in Chapter2,“Arrays.”This will buy you binary search capability.If you wanted the best performance for your priority queue,would you need to modify the OrdArray class?15.A priority queue might be used to holda.passengers to be picked up by a taxi from different parts of the city.b.keystrokes made at a computer keyboard.c.squares on a chessboard in a game program.d.planets in a solar system simulation.Chapter4,Stacks and QueuesAnswers to Questions1.102.bst-In-First-Out;and First-In-First-Out4.False.It’s the other way around.5.b6.It doesn’t move at all.7.458.False.They take O(1)time.9.c10.O(N)11.c12.True13.b14.Yes,you would need a method to find the minimum value.15.aChapter5Linked Lists1.Which of the following is not true?A reference to a class objecta.can be used to access public methods in the object.b.has a size dependant on its class.c.has the data type of the class.d.does not hold the object itself.2.Access to the links in a linked list is usually through the_________link.3.When you create a reference to a link in a linked list,ita.must refer to the first link.b.must refer to the link pointed to by current.c.must refer to the link pointed to by next.d.can refer to any link you want.4.How many references must you change to insert a link in the middle of a singly linked list?5.How many references must you change to insert a link at the end of a singly linked list?6.In the insertFirst()method in the linkList.java program(Listing5.1),the statement newLink.next=first;means thata.the next new link to be inserted will refer to first.b.first will refer to the new link.c.the next field of the new link will refer to the old first link.d.newLink.next will refer to the new first link in the list.7.Assuming current points to the next-to-last link in a singly linked list,what statement will delete the last link from the list?8.When all references to a link are changed to refer to something else,what happens to the link?9.A double-ended lista.can be accessed from either end.b.is a different name for a doubly linked list.c.has pointers running both forward and backward between links.d.has its first link connected to its last link.10.A special case often occurs for insertion and deletion routines when a list is ________.11.Assuming a copy takes longer than a comparison,is it faster to delete an item with a certain key from a linked list or from an unsorted array?12.How many times would you need to traverse a singly linked list to delete the item with the largest key?13.Of the lists discussed in this chapter,which one would be best for implementing a queue?14.Which of the following is not true?Iterators would be useful if you wanted toa.do an insertion sort on a linked list.b.insert a new link at the beginning of a list.c.swap two links at arbitrary locations.d.delete all links with a certain key value.15.Which do you think would be a better choice to implement a stack:a singly linked list or an array?Chapter5,Linked ListsAnswers to Questions1.b2.first3.d4.25.16.c7.current.next=null;8.Java’s garbage collection process destroys it.Chapter5,Linked Lists7419.a10.empty11.a linked list12.once,if the links include a previous reference13.a double-ended list14.bually,the list.They both do push()and pop()in O(1)time,but the list uses memory more efficiently.Chapter6RecursionThese questions are intended as a self-test for readers.Answers may be found in Appendix C.1.If the user enters10in the triangle.java program(Listing6.1),what is the maximum number of“copies”of the triangle()method(actually just copies of its argument)that exist at any one time?2.Where are the copies of the argument,mentioned in question1,stored?a.in a variable in the triangle()methodb.in a field of the TriangleApp classc.in a variable of the getString()methodd.on a stack3.Assume the user enters10as in question1.What is the value of n when the triangle()method first returns a value other than1?4.Assume the same situation as in question1.What is the value of n when the triangle()method is about to return to main()?5.True or false:In the triangle()method,the return values are stored on the stack.6.In the anagram.java program(Listing6.2),at a certain depth of recursion,a version of the doAnagram()method is working with the string“led”.When this method calls a new version of itself,what letters will the new version be working with?7.We’ve seen that recursion can take the place of a loop,as in the loop-oriented orderedArray.java program(Listing2.4)and the recursive binarySearch.java program(Listing6.3).Which of the following is not true?a.Both programs divide the range repeatedly in half.b.If the key is not found,the loop version returns because the rangebounds cross,but the recursive version occurs because it reaches thebottom recursion level.c.If the key is found,the loop version returns from the entire method, whereas the recursive version returns from only one level of recursion.d.In the recursive version the range to be searched must be specified in the arguments,while in the loop version it need not be.8.In the recFind()method in the binarySearch.java program(Listing6.3),what takes the place of the loop in the non-recursive version?a.the recFind()methodb.arguments to recFind()c.recursive calls to recFind()d.the call from main()to recFind()9.The binarySearch.java program is an example of the_________approach to solving a problem.10.What gets smaller as you make repeated recursive calls in the redFind() method?11.What becomes smaller with repeated recursive calls in the towers.java program (Listing6.4)?12.The algorithm in the towers.java program involvesa.“trees”that are data storage devices.b.secretly putting small disks under large disks.c.changing which columns are the source and destination.d.moving one small disk and then a stack of larger disks.13.Which is not true about the merge()method in the merge.java program(Listing6.5)?a.Its algorithm can handle arrays of different sizes.b.It must search the target array to find where to put the next item.c.It is not recursive.d.It continuously takes the smallest item irrespective of what array it’s in.14.The disadvantage of mergesort is thata.it is not recursive.b.it uses more memory.c.although faster than the insertion sort,it is much slower than quicksort.d.it is complicated to implement.15.Besides a loop,a___________can often be used instead of recursion.Chapter6,RecursionAnswers to Questions1.102.d3.24.105.false6.“ed”7.b8.c9.divide-and-conquer10.the range of cells to search11.the number of disks to transfer12.c13.b14.b15.stackChapter7Advanced SortingThese questions are intended as a self-test for readers.Answers may be found in Appendix C.1.The Shellsort works bya.partitioning the array.b.swapping adjacent elements.c.dealing with widely separated elements.d.starting with the normal insertion sort.2.If an array has100elements,then Knuth’s algorithm would start with an interval of________.3.To transform the insertion sort into the Shellsort,which of the following do you not do?a.Substitute h for1.b.Insert an algorithm for creating gaps of decreasing width.c.Enclose the normal insertion sort in a loop.d.Change the direction of the indices in the inner loop.4.True or false:A good interval sequence for the Shellsort is created by repeatedly dividing the array size in half.5.Fill in the big O values:The speed of the Shellsort is more than_______but less than________.6.Partitioning isa.putting all elements larger than a certain value on one end of the array.b.dividing an array in half.c.partially sorting parts of an array.d.sorting each half of an array separately.7.When partitioning,each array element is compared to the_______.8.In partitioning,if an array element is equal to the answer to question7,a.it is passed over.b.it is passed over or not,depending on the other array element.c.it is placed in the pivot position.d.it is swapped.9.True or false:In quicksort,the pivot can be an arbitrary element of the array.10.Assuming larger keys on the right,the partition isa.the element between the left and right subarrays.b.the key value of the element between the left and right subarrays.c.the left element in the right subarray.d.the key value of the left element in the right subarray.11.Quicksort involves partitioning the original array and then_________.12.After a partition in a simple version of quicksort,the pivot may beed to find the median of the array.b.exchanged with an element of the right subarray.ed as the starting point of the next partition.d.discarded.13.Median-of-three partitioning is a way of choosing the_______.14.In quicksort,for an array of N elements,the partitionIt()method will examine each element approximately______times.15.True or false:You can speed up quicksort if you stop partitioning when the partition size is5and finish by using a different sort.Chapter7,Advanced SortingAnswers to Questions1.c2.403.d4.false5.O(N*logN),O(N2)6.a7.pivot8.d9.true10.c11.partitioning the resulting subarrays12.b13.pivot14.log2N15.trueChapter8Binary TreesThese questions are intended as a self-test for readers.Answers may be found in Appendix C.1.Insertion and deletion in a tree require what big O time?2.A binary tree is a search tree ifa.every non-leaf node has children whose key values are less than(or equal to)the parent.b.every left child has a key less than the parent and every right child has akey greater than(or equal to)the parent.c.in the path from the root to every leaf node,the key of each node is greater than(or equal to)the key of its parent.d.a node can have a maximum of two children.3.True or False:Not all trees are binary trees.4.In a complete binary tree with20nodes,and the root considered to be at level 0,how many nodes are there at level4?5.A subtree of a binary tree always hasa.a root that is a child of the main tree’s root.b.a root unconnected to the main tree’s root.c.fewer nodes than the main tree.d.a sibling with the same number of nodes.6.In the Java code for a tree,the______and the_______are generally separate classes.7.Finding a node in a binary search tree involves going from node to node, askinga.how big the node’s key is in relation to the search key.b.how big the node’s key is compared to its right or left children.c.what leaf node we want to reach.d.what level we are on.8.An unbalanced tree is onea.in which most of the keys have values greater than the average.b.whose behavior is unpredictable.c.in which the root or some other node has many more left children thanright children,or vice versa.d.that is shaped like an umbrella.9.Inserting a node starts with the same steps as_______a node.10.Suppose a node A has a successor node S.Then S must have a key that is larger than_____but smaller than or equal to_______.11.In a binary tree used to represent a mathematical expression,which of the following is not true?a.Both children of an operator node must be operands.b.Following a postorder traversal,no parentheses need to be added.c.Following an inorder traversal,parentheses must be added.d.In pre-order traversal a node is visited before either of its children.12.If a tree is represented by an array,the right child of a node at index n has an index of_______.13.True or False:Deleting a node with one child from a binary search tree involves finding that node’s successor.14.A Huffman tree is typically used to_______text.15.Which of the following is not true about a Huffman tree?a.The most frequently used characters always appear near the top of the tree.b.Normally,decoding a message involves repeatedly following a path fromthe root to a leaf.c.In coding a character you typically start at a leaf and work upward.d.The tree can be generated by removal and insertion operations on apriority queue.Chapter8,Binary TreesAnswers to Questions1.O(logN)2.b3.True4.55.c6.node,tree7.a8.cChapter8,Binary Trees7439.finding10.A,A’s left-child descendents11.d12.2*n+113.Falsepress15.cChapter102-3-4Trees and External StorageThese questions are intended as a self-test for readers.Answers may be found in Appendix C.1.A2-3-4tree is so named because a node can havea.three children and four data items.b.two,three,or four children.c.two parents,three children,and four items.d.two parents,three items,and four children.2.A2-3-4tree is superior to a binary search tree in that it is________.3.Imagine a parent node with data items25,50,and75.If one of its child nodes had items with values60and70,it would be the child numbered__________.4.True or False:Data items are located exclusively in leaf nodes.5.Which of the following is not true each time a node is split?a.Exactly one new node is created.b.Exactly one new data item is added to the tree.c.One data item moves from the split node to its parent.d.One data item moves from the split node to its new sibling.6.A2-3-4tree increases its number of levels when________.7.Searching a2-3-4tree does not involvea.splitting nodes on the way down if necessary.b.picking the appropriate child to go to,based on data items in a node.c.ending up at a leaf node if the search key is not found.d.examining at least one data item in any node visited.8.After a non-root node of a2-3-4tree is split,does its new right child contain the item previously numbered0,1,or2?9.A4-node split in a2-3-4tree is equivalent to a_______in a red-black tree.10.Which of the following statements about a node-splitting operation in a2-3 tree(not a2-3-4tree)is not true?a.The parent of a split node must also be split if it is full.b.The smallest item in the node being split always stays in that node.c.When the parent is split,child2must always be disconnected from itsold parent and connected to the new parent.d.The splitting process starts at a leaf and works upward.11.What is the big O efficiency of a2-3tree?12.In accessing data on a disk drive,a.inserting data is slow but finding the place to write data is fast.b.moving data to make room for more data is fast because so many itemscan be accessed at once.c.deleting data is unusually fast.d.finding the place to write data is comparatively slow but a lot of data canbe written quickly.13.In a B-tree each node contains_______data items.14.True or False:Node splits in a B-tree have similarities to node splits in a2-3 tree.15.In external storage,indexing means keeping a file ofa.keys and their corresponding blocks.b.records and their corresponding blocks.c.keys and their corresponding records.st names and their corresponding keys.Chapter9,Red-Black TreesAnswers to Questions1.in order(or inverse order)2.b3.False4.d5.b6.rotations,changing the colors of nodes7.red8.a9.left child,right child10.d11.a node,its two children12.b13.True14.a15.TrueQuestionsThese questions are intended as a self-test for readers.Answers may be found in Appendix C.Chapter11Hash Tablesing big O notation,say how long it takes(ideally)to find an item in a hash table.2.A__________transforms a range of key values into a range of index values.3.Open addressing refers toa.keeping many of the cells in the array unoccupied.b.keeping an open mind about which address to use.c.probing at cell x+1,x+2,and so on until an empty cell is found.d.looking for another location in the array when the one you want is occupied.ing the next available position after an unsuccessful probe is called_____________.5.What are the first five step sizes in quadratic probing?6.Secondary clustering occurs becausea.many keys hash to the same location.b.the sequence of step lengths is always the same.c.too many items with the same key are inserted.d.the hash function is not perfect.7.Separate chaining involves the use of a_____________at each location.8.A reasonable load factor in separate chaining is________.9.True or False:A possible hash function for strings involves multiplying each character by an ever-increasing power.10.The best technique when the amount of data is not well known isa.linear probing.b.quadratic probing.c.double hashing.d.separate chaining.11.If digit folding is used in a hash function,the number of digits in each group should reflect_____________.12.True or False:In linear probing an unsuccessful search takes longer than a successful search.Questions57513.In separate chaining the time to insert a new itema.increases linearly with the load factor.b.is proportional to the number of items in the table.c.is proportional to the number of lists.d.is proportional to the percentage of full cells in the array.14.True or False:In external hashing,it’s important that the records don’t become full.15.In external hashing,all records with keys that hash to the same value are located in___________.Chapter11,Hash TablesAnswers to Questions1.O(1)2.hash function3.d4.linear probing5.1,4,9,16,256.b7.linked listChapter11,Hash Tables7458.1.09.True10.d11.the array size。

数据结构java语言描述课后答案

数据结构java语言描述课后答案

数据结构java语言描述课后答案【篇一:数据机构第一章——java语言描述第1章绪论习题参考答案】概念题1. 试述下列各组概念:⑴数据、数据元素、数据项⑵数据结构、数据的逻辑结构、数据的存储结构⑶数据类型、数据操作⑷算法、算法的时间复杂度、算法的空间复杂度参考答案: 略2.试述数据结构研究的3个方面的内容。

参考答案:数据结构研究的3个方面分别是数据的逻辑结构、数据的存储结构和数据的运算(操作)。

3.试述集合、线性结构、树型结构和图型结构四种常用数据结构的特性。

参考答案:集合结构:集合中数据元素之间除了“同属于一个集合”的特性外,数据元素之间无其它关系,它们之间的关系是松散性的。

线性结构:线性结构中数据元素之间存在“一对一”的关系。

即若结构非空,则它有且仅有一个开始结点和终端结点,开始结点没有前趋但有一个后继,终端结点没有后继但有一个前趋,其余结点有且仅有一个前驱和一个后继。

树形结构:树形结构中数据元素之间存在“一对多”的关系。

即若结构非空,则它有一个称为根的结点,此结点无前驱结点,其余结点有且仅有一个前驱,所有结点都可以有多个后继。

图形结构:图形结构中数据元素之间存在“多对多”的关系。

即若结构非空,则在这种数据结构中任何结点都可能有多个前驱和后继。

4.设有数据的逻辑结构的二元组定义形式为b=(d,r),其中d={a1,a2,?,an}, r={ai,ai+1| i=1,2,?,n-1},请画出此逻辑结构对应的顺序存储结构和链式存储结构的示意图。

参考答案:顺序存储结构示意图如下:0 1 2 ?n-2 n-1链式存储结构示意图如下:?5.设一个数据结构的逻辑结构如图1.9所示,请写出它的二元组定义形式。

图1.9 第5题的逻辑结构图参考答案:它的二元组定义形式为b=(d,r),其中d={k1,k2,k3,k4,k5,k6,k7,k8,k9},r=k1,k3,k1,k8,k2,k3k2,k4,k2,k5,k3,k9,k4,k6,k4,k7,k5,k6,k8,k9,k9, k7 }。

java数据结构测试题及答案解析

java数据结构测试题及答案解析

java数据结构测试题及答案解析```markdownJava数据结构测试题及答案解析第一章:数组概述数组是一种线性数据结构,用于存储多个相同数据类型的元素。

本章将介绍数组的基本概念和操作。

1.定义数组在Java中,可以使用以下语法定义一个数组:```java<数据类型>[] <数组名> = new <数据类型>[<数组长度>];```2.访问数组元素可以使用索引值来访问数组中的元素,索引值从0开始。

例如,要访问数组中的第一个元素,可以使用以下语法:```java<数组名>[0];```3.数组的常见操作本节将详细介绍数组的常见操作,包括添加元素、删除元素、查找元素等。

3.1 添加元素可以使用以下语法向数组中添加元素:```java<数组名>[<索引值>] = <新元素>;```3.2 删除元素使用以下语法删除数组中的元素:```java<数组名>[<索引值>] = null;```3.3 查找元素可以使用循环语句遍历数组,并通过判断元素的值来查找指定元素。

第二章:链表概述链表是一种常见的数据结构,用于存储多个元素。

本章将介绍链表的基本概念和操作。

1.定义链表在Java中,可以使用以下代码定义一个链表节点:```javaclass ListNode {int val;ListNode next;ListNode(int x) { val = x; }}```2.链表的插入和删除本节将介绍链表的插入和删除操作,包括在链表头插入、在链表尾插入、在指定位置插入等。

2.1 在链表头插入使用以下代码在链表头部插入一个节点:```javaListNode newNode = new ListNode(val); newNode.next = head;head = newNode;```2.2 在链表尾插入使用以下代码在链表尾部插入一个节点:```javaListNode newNode = new ListNode(val); if (head == null) {head = newNode;} else {ListNode curr = head;while (curr.next != null) {curr = curr.next;}curr.next = newNode;}```2.3 删除节点使用以下代码删除链表中的一个节点:```javaListNode prev = null;ListNode curr = head;while (curr != null) {if (curr.val == val) {if (prev == null) {head = curr.next;} else {prev.next = curr.next; }break;}prev = curr;curr = curr.next;}```3.链表的常见操作本节将介绍链表的常见操作,包括查找节点、链表反转等。

数据结构(Java)复习题及答案 1绪论

数据结构(Java)复习题及答案 1绪论

一、单项选择题( B )1. 计算机算法必须具备输入、输出和 等5个特性。

A) 可行性、可移植性和可扩充性 B) 可行性、确定性和有穷性C) 确定性、有穷性和稳定性 D) 易读性、稳定性和安全性( C )2. 数据结构中,与所使用的计算机无关的是数据的 结构;A) 存储 B) 物理 C) 逻辑 D) 物理和存储( C )3. 算法分析的目的是:A) 找出数据结构的合理性 B) 研究算法中的输入和输出的关系C) 分析算法的效率以求改进 D) 分析算法的易懂性和文档性( A )4. 算法分析的两个主要方面是:A) 空间复杂性和时间复杂性 B) 正确性和简明性C) 可读性和文档性 D) 数据复杂性和程序复杂性( C )5. 计算机算法指的是:A) 计算方法 B) 排序方法 C) 解决问题的有限运算序列 D) 调度方法6.数据结构是研究数据的(A)和(B)以及它们之间的相互关系,并对这种结构定义相应的 (C),设计出相应的(D),从而确保经过这些运算后所得到的新结构是(E)结构类型。

供选择的答案A.B: 1.理想结构 2.抽象结构 3.物理结构 4逻辑结构C.D.E: 1.运算 2.算法 3.结构 4.规则 5.现在的 6.原来的解答:341267.(A)是描述客观事物的数、字符以及所有能输入到计算机中被计算机程序加工处理的符号的结合。

(B)是数据的基本单位,即数据结合中的个体。

有时一个(B)由若干个 (C)组成,在这种情况下,称(B)为记录。

(C)是数据的最小单位。

(D)是具有相同特性的数据元素的集合。

(E)是带有结构特性的数据元素的结合。

被计算机加工的数据元素不是孤立无关的,它们彼此之间一般存在着某种联系,通常将数据元素的这种联系关系称为 (G)。

算法的计算量和问题规模的联系用(H)表示。

供选择的答案:A-F: 1.数据元素 2.符号 3.记录 4.文件 5.数据 6.数据项 7.数据对象 8.关键字 9.数据结构G: 1.规则 2.集合 3.结构 4.运算H: 1.现实性 2.难度 3.复杂性 4.效率解答:5167933二、判断题1, 数据元素是数据的最小单位。

数据结构(java语言版)-王学军主编-课后习题参考答案

数据结构(java语言版)-王学军主编-课后习题参考答案

第一章习题参考答案一、简答题1.【参考答案】:数据结构是计算机类专业的一门专业基础的课程,是学习操作系统、数据库原理等专业课的基础,所涉及的有数学范围的诸多知识;计算机硬件范围的编码理论、存取装置和存取方法等知识;软件范围的文件系统、数据的动态存储管理和信息管理等知识。

所以说数据结构是介于数学、计算机硬件及软件三者之间的一门核心课程。

2.【参考答案】:(1)学生管理系统中的学生信息顺序表、图书查询系统中的图书信息表、电话查询系统中的电话号码表中都表现了前后元素之间的线性关系,课本中【例1.2】也是线性结构。

(2)计算机文件管理系统中目录的层次管理结构、家谱管理等都体现上一层次与下一层次元素之间的层次关系,即树形结构,课本中【例1.3】也是树形结构。

(3)地图中城市之间的关系、同一地区不同城市之间的交通关系等都反映了不同元素之间复杂的网状结构,课本中【例1.4】也是网状结构。

3.【参考答案】:数据元素(Data Element)是构成数据的基本单位。

这些数据可由单个元素构成的,例如{1,4,7,100,……}中每个数字就是一个数据。

另外有些数据是由一组元素构成的。

数据项(Data Item)是数据结构中的最小单位。

当数据元素由多个项构成时,其每个分项称为数据项,例如,{{1,100,’a’},{1,101,’b’,{3,102,’c’ },……}中的每个元素都是有三个数据元素构成的。

4.【参考答案】:不矛盾。

算法的时间复杂度是指在计算机上运行该算法(或程序)所需要的时间。

它与机器的性能、算法语言的选取、编译程序的效率、算法的选择等方面有关系。

算法的空间复杂度是指程序从开始运行到结束运行所需的最大存储空间,其影响因素包括:输入数据所占空间;程序本身所占空间;辅助变量所占空间等。

算法的时间复杂度和空间复杂度是反映算法优劣的两个方面,但是有时候会因为提高时间复杂度而降低空间复杂度,反之同理,但是这些并不说明它们之间是有矛盾的。

java数据结构测试题及答案解析

java数据结构测试题及答案解析

1 下列数据结构中,能用二分法进行查找的是__A____。

A、顺序存储的有序线性表B、线性链表C、二叉链表D、有序线性链表解析:二分法查找只合用于顺序存储的有序表。

在此所说的有序表是指线性表中的元素按值非递减罗列(即从小到大,但允许相邻元素值相等)。

2 在软件设计中,不属于过程设计工具的是__D____。

A、PDL(过程设计语言)B、PAD 图C、N-S 图D、DFD 图解析:软件设计工具包括:程序流程图、 N-S、PAD、HIPO,判定表, PDL(伪码)。

而 DFD(数据流图)属于结构化分析工具。

3 在 switch(expression)语句中, expression 的数据类型不能是__A____。

A、doubleB、charC、byteD、short解析:表达式expression 只能返回这个几种类型的值: int、byte、short 和 char。

多分支语句把表达式返回的值挨次与每一个 case 子句中的值相比较,如果遇到匹配的值,则执行该 case 子句后的语句序列。

4 下列叙述中,错误的是__D____。

A、父类不能替代子类B、子类能够替代父类C、子类继承父类D、父类包含子类5 通过继承实现代码复用:Java 中所有的类都是通过直接或者间接地继承 ng.Object 类得到的。

继承而得到的类称为子类,被继承的类称为父类。

子类不能继承父类中访问权限为 private 的成员变量和方法,子类可以重写父类的方法,及命名与父类同名的成员变量。

子类通过隐藏父类的成员变量和重写父类的方法,把父类的状态和行为改变为自身的状态和行为。

注意:子类中重写的方法和父类中被重写的方法要具有相同的名字,相同的参数表和相同的返回类型,只是函数体不同。

由于子类继承了父类所有的属性(私有的除外),所以子类对象可以作为父类对象使用。

程序中凡是使用父类对象的地方,都可以用子类对象来代替。

一个对象可以通过引用子类的实例来调用子类的方法。

数据结构(Java)复习题及答案2线性表

数据结构(Java)复习题及答案2线性表

第2章线性表一、填空1.在顺序表中插入或删除一个元素,需要平均移动一半的元素,具体移动的元素个数与插入位置有关。

2.向一个长度为n的向量的第i个元素(K i< n+1)之前插入一个元素时,需向后移动n-i+1 个元素。

3.向一个长度为n的向量中删除第i个元素(K i< n)时,需向前移动n-i 个元素。

4.在顺序表中访问任意一结点的时间复杂度均为0(1),因此,顺序表也称为随机读取的数据结构。

5.顺序表中逻辑上相邻的元素的物理位置也相邻。

单链表中逻辑上相邻的元素的物理位置不一定相邻。

6.在单链表中,除了首元结点外,任一结点的存储位置由前驱节点的引用域指示。

7.在n个结点的单链表中要删除已知结点*p,需找到它的存储位置,其时间复杂度为0 (n) ______ 。

8 .链表中逻辑上相邻的元素的物理位置环一定—相连。

⑵ 在单链表中除首结点外,任意结点的存储位置都由前驱结点中的引用指示。

(3)在单链表中,设置头结点的作用是在插入或删除首结点时不必对头指针―进行处理二、判断正误V X(V) 1.链表的每个结点中都包含一个引用域。

(X ) 2.链表的物理存储结构具有同链表一样的顺序。

(X ) 3.链表的删除算法很简单,因为当删除链中某个结点后,计算机会自动将后续各个单元向前移动。

(X ) 4.顺序表的每个结点只能是一个简单类型,而链表的每个结点可以是一个复杂类型。

X ) 5.顺序表结构适宜于进行顺序存取,而链表适宜于进行随机存取。

(X ) 6.顺序存储方式的优点是存储密度大,且插入、删除运算效率高。

X ) 7.线性表在物理存储空间中也一定是连续的。

(V ) 8.线性表在顺序存储时,逻辑上相邻的元素在存储的物理位置次序上相邻。

(X ) 9.顺序存储方式只能用于存储线性结构。

X ) 10.线性表的逻辑顺序与存储顺序总是一致的。

(V ) 11.顺序存储的线性表的插入和删除操作需要付出很大的代价,因为平均每次操作有近一半的元素需要移动。

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

第0章Java程序设计基础 (1)【习0.1】实验0.1 哥德巴赫猜想。

(1)【习0.2】实验0.2 杨辉三角形。

(1)【习0.3】实验0.3 金额的中文大写形式。

(1)【习0.4】实验0.4 下标和相等的数字方阵。

(1)【习0.5】实验0.5 找出一个二维数组的鞍点 (2)【习0.6】实验0.6 复数类。

(2)【习0.7】实验0.8 图形接口与实现图形接口的类 (2)第1章绪论 (3)【习1.1】实验1.1 判断数组元素是否已按升序排序。

(3)【习1.2】实验1.3 用递归算法求两个整数的最大公因数。

(3)第2章线性表 (5)【习2.1】习2-5 图2.19的数据结构声明。

(5)【习2.2】习2-6 如果在遍历单链表时,将p=p.next语句写成p.next=p,结果会怎样? (5)【习2.3】实验2.2 由指定数组中的多个对象构造单链表。

(5)【习2.4】实验2.2 单链表的查找、包含、删除操作详见8.2.1。

(5)【习2.5】实验2.2 单链表的替换操作。

(6)【习2.6】实验2.2 首尾相接地连接两条单链表。

(6)【习2.7】实验2.2 复制单链表。

(6)【习2.8】实验2.2 单链表构造、复制、比较等操作的递归方法。

(7)【习2.9】建立按升序排序的单链表(不带头结点)。

(8)【习2.10】实验2.6 带头结点的循环双链表类,实现线性表接口。

(10)【习2.11】实验2.5 建立按升序排序的循环双链表。

(14)第3章栈和队列 (17)【习3.1】习3-5 栈和队列有何异同? (17)【习3.2】能否将栈声明为继承线性表,入栈方法是add(0,e),出栈方法是remove(0)?为什么? (17)【习3.3】能否用一个线性表作为栈的成员变量,入栈方法是add(0,e),出栈方法是remove(0)?为什么? (17)【习3.4】能否将队列声明为继承线性表,入队方法是add(e),出队方法是remove(0)?为什么? (17)第4章串 (18)【习4.1】实验4.6 找出两个字符串中所有共同的字符。

(18)【习4.2】习4-9(1) 已知目标串为"abbaba"、模式串为"aba",画出其KMP算法的匹配过程,并给出比较次数。

(18)【习4.3】习4-9(2) 已知target="ababaab"、pattern="aab",求模式串的next数组,画出其KMP 算法的匹配过程,并给出比较次数。

(18)第5章数组和广义表 (20)【习5.1】求一个矩阵的转置矩阵。

(20)第6章树和二叉树 (21)【习6.1】画出3个结点的各种形态的树和二叉树。

(21)【习6.2】找出分别满足下面条件的所有二叉树。

(21)【习6.3】输出叶子结点。

(21)【习6.4】求一棵二叉树的叶子结点个数。

(22)【习6.5】判断两棵二叉树是否相等。

(22)【习6.6】复制一棵二叉树。

(23)【习6.7】二叉树的替换操作。

(23)【习6.8】后根次序遍历中序线索二叉树。

(24)第7章图 (25)第8章查找 (26)【习8.1】实验8.1 顺序表的查找、删除、替换、比较操作。

(26)【习8.2】实验8.2 单链表的全部替换操作。

(28)【习8.3】实验8.2 单链表的全部删除操作。

(28)【习8.4】折半查找的递归算法。

(29)【习8.5】二叉排序树查找的递归算法。

(29)【习8.6】二叉排序树插入结点的非递归算法。

(30)【习8.7】判断一棵二叉树是否为二叉排序树。

(31)第9章排序 (32)【习9.1】判断一个数据序列是否为最小堆序列。

(32)【习9.2】归并两条排序的单链表。

(32)【习9.3】说明二叉排序树与堆的差别。

(34)图0.1 下标和相等的数字方阵算法描述 (1)图2.1 p.next=p将改变结点间的链接关系 (5)图4.1 目标串"abbaba"和模式串"aba"的KMP算法模式匹配过程 (18)图4.2 目标串"ababaab"和模式串"aab"的KMP算法模式匹配过程 (19)图6.1 3个结点树和二叉树的形态 (21)图6.2 单支二叉树 (21)图9.2 归并两条排序的单链表 (33)表4.1 模式串"aab"的next数组 (19)第0章 Java程序设计基础【习0.1】实验0.1 哥德巴赫猜想。

【习0.2】实验0.2 杨辉三角形。

【习0.3】实验0.3 金额的中文大写形式。

【习0.4】实验0.4 下标和相等的数字方阵。

输出下列方阵(当n=4时)。

1 2 6 7 或 1 3 4 103 5 8 13 2 5 9 114 9 12 14 6 8 12 1510 11 15 16 7 13 14 16采用二维数组实现。

二维数组中,每一条斜线上各元素下标和相等,如图0.1所示。

图0.1 下标和相等的数字方阵算法描述程序如下。

public class Upmat{public static void main(String args[]){int n=4; //阶数int[][] mat = new int[n][n];int k=1; //k是自然数,递增变化boolean up = true; //方向向上for (int sum=0; sum<n; sum++) //左上三角,sum表示行列的下标和{if (up)for (int i=sum; i>=0; i--)mat[i][sum-i] = k++; //k先赋值后自加elsefor (int i=0; i<=sum; i++)mat[i][sum-i] = k++;up=!up; //方向求反}for (int sum=n; sum<2*n-1; sum++) //右下三角{if (up)for (int j=sum-n+1; j<n; j++)mat[sum-j][j] = k++;elsefor (int j=n-1; j>sum-n; j--)mat[sum-j][j] = k++;up=!up;}for (int i=0; i<mat.length; i++) //输出二维数组元素{for (int j=0; j<mat[i].length; j++) //i、j是行、列下标System.out.print(" "+mat[i][j]);System.out.println();}}}【习0.5】实验0.5 找出一个二维数组的鞍点【习0.6】实验0.6 复数类。

【习0.7】实验0.8 图形接口与实现图形接口的类第1章绪论【习1.1】实验1.1 判断数组元素是否已按升序排序。

程序见例1.4的SortedArray.java。

public static boolean isSorted(int[] table) //判断整数数组是否已按升序排序{ //若已排序返回true,否则返回false if (table==null)return false;for (int i=0; i<table.length-1; i++)if (table[i]>table[i+1])return false;return true;}public static boolean isSorted(Comparable[] table) //判断对象数组是否已按升序排序{ //若已排序返回true,否则返回false if (table==null)return false;for (int i=0; i<table.length-1; i++)if (table[i].compareTo(table[i+1])>0)return false;return true;}【习1.2】实验1.3 用递归算法求两个整数的最大公因数。

public class Gcd{public static int gcd(int a, int b) //返回a,b的最大公因数,递归方法{if(b==0)return a;if(a<0)return gcd(-a, b);if(b<0)return gcd(a, -b);return gcd(b, a%b);}public static void main(String args[]){int a=12, b=18, c=24;System.out.println("gcd("+a+","+b+","+c+")="+gcd(gcd(a,b),c)); //获得3个整数最大公因数}}第2章线性表【习2.1】习2-5 图2.19的数据结构声明。

table数组元素为单链表,声明如下:SinglyLinkedList<E> table[]【习2.2】习2-6 如果在遍历单链表时,将p=p.next语句写成p.next=p,结果会怎样?使p.next指向p结点自己,改变了结点间的链接关系,丢失后继结点,如图2.1所示。

p图2.1 p.next=p将改变结点间的链接关系【习2.3】实验2.2 由指定数组中的多个对象构造单链表。

在SinglyLinkedList单链表类中,增加构造方法如下。

public SinglyLinkedList(E[] element) //由指定数组中的多个对象构造单链表{this.head = null;if (element!=null && element.length>0){this.head = new Node(element[0]);Node<E> rear=this.head;int i=1;while (i<element.length){rear.next = new Node(element[i++]);rear = rear.next;}}}【习2.4】实验2.2 单链表的查找、包含、删除操作详见8.2.1。

单链表的以下查找、包含、删除等操作方法详见8.2.1顺序查找。

public Node<E> search(E element, Node<E> start) //从单链表结点start开始顺序查找指定对象public Node<E> search(E element) //若查找到指定对象,则返回结点,否则返回null public boolean contain(E element) //以查找结果判断单链表是否包含指定对象public boolean remove(E element) //移去首次出现的指定对象【习2.5】实验2.2 单链表的替换操作。

相关文档
最新文档