数据结构试题(英文版)C
Final Examination Paper on Data Structures(A)I、Fill Vacant Position (1′×10=10′)1、____________is the name for the case when a function invokes itself or invokes asequence of other functions,one of which eventually invokes the __________again.2、In a __________ data structure, all insertions and deletions of entries are made atone end. It is particularly useful in applications involving __________.3、In c++ , we use ____________operator to implement the circular queues.4、In processing a contiguous list with n entries: insert and remove require timeapproximately to _________. And clear, empty, full, size operate in ________ time.5、One of method of searching is ____________________that requires ordered list.6、The time complexity of the quicksort is______________.7、Only __________ ____________graph has topological order.II、Multiple choice (2′×10=20′)1、In a tree, ______are vertices with the same parent. ( )A. childrenB. siblingC. adjacentD. leaf2、A queue is a version of ( )A. linked listB. LIFO listC. sequential listD. FIFO list3、How many shapes of binary trees with four nodes are there ( )A. 12B.15C. 14D. 134、Among sorting algorithms, which kind of algorithm is divide-and-conquer sorting( )A. shell sortB. heap sortC. merge sortD. inserting sort5、For the following graph, one of results of depth_first traversal is ( )A. abcdefghiB. abcdeighfC. acbdieghfD.abdeighfc6、In a binary tree, if the result of traversing under preorder is the same as that underinorder, then( )A. It is only a binary tree with one nodeB. It is either empty, or the left subtree of any node of the tree is emptyC. It is only an empty binary treeD. It is either empty, or the right subtree of an node of the tree is empty7、There are _______solutions to the problem of placing four queens on a 4×4 board.( )A. 2B. 3C. 6D. 48、Which function is smallest order of magnitude? ( )A. 2 nB. n + lgnC.n 0.1D.100009、The time requirement of retrieving a given target in hash table with n entries is( )A. O(n)B. O(log2n)C. O(1)D.O(nlog2n)10、For the following binary tree, the result of traversing under postorder is ( )A. abcdefghiB. dgbechfiaC. gdbaehifcD. gdbehifcaIII、Analyze and Calculate ( 10′)Let A be a upper triangular matrix andSuppose that(a) Elements of A are stored in row-major ordering(b) Each element occupies m memory locations(c) Indexing begins at 0Please give the calculating formula of loc(aij)(address of the element aij)IV、Comprehensive Problem(7′×6=42′)1、Draw a diagram to illustrate the configuration of linked nodes that is created bythe following statement.Node *p0=new Node (a);Node *p1=p0→next=new Node(b);Node *p2=p1→next=new Node(c,p1);2、Briefing the idea of Shellsort .3、By hand, trace the action of heap_sort on the following lists. Draw the initial tree towhich the list corresponds, show how it is converted into a heap, and show the resulting heap as each entry is removed from the top and the new entry inserted.25 31 36 28 19 12 224、Suppose that(a) A hash table contains hash_size=16 position indexed from 0 to 15(b) A hash function H(key)=(key*3)%13(c) The following keys are to be mapped into the table:10 120 33 45 58 26 3 27 200 400 2Draw the hash table with the collision resolution oflinear probing.5、Construct a minimal spanning tree ofthe following connected network..6、Given a sequence of keys:A , Z, B,Y, C, X, D, W, E, V, FInsert the keys in the order shown above, to build them into an A VL tree (draw the principal A VL tree).V、Develop Algorithm(18′)For linked implementation of binary trees, we have the following class specifications: template <class Entry>struct Binary_node {Entry data;Binary_node <Entry>*left;Binary_node <Entry>*right; };template <class Entry>class Binary_tree{protected:Binary_node<Entry>*root;int recursive_height (Binary_node<Entry> *sub_root);public:int height(); //other function; };template <class Entry>int Binary_tree<Entry>::height() {recursive_height(root);}Write the function recursive_height to computethe height ofa binary tree.Answer of Final Examination Paper On Data Structures (A)I. 1、Recursion first function 2、stack reversing3、modulus ( or % or mod)4、O(n) O(1) (or constant)5、binary search6、O(n log2n)7、directed with no cycleII. 1、B 2、D 3、A 4、C 5、D 6、B 7、A 8、D 9、C 10、DIII.(不写不扣分)IV. 1、2、Repeat(1) Choosethe increment di satsifies the followings(a) d1<n, di+1 < di(b) di is an integer(2) Partition all entries into di groups (distance between entries is di)(3) For each group,do straight insertion sortWhile (di >1)、3、4、H(10)=2 H(120)=7 H(33)=6 H(45)=3 H(58)=3H(26)=11 H(3)=7 H(27)=1 H(200)=0 H(400)=2 H(2)=40 1 2 3 4 5 6 7 8 9 10 11 12200 27 10 45 58 400 33 120 3 2 26 5、6、V.int Binary_tree<entry>::recursive_height(Binary_node<entry>*&sub_root) { int l,r,h; if(sub_root==NULL) return 0;l=recursive_height(sub_root->left);r=recursive_height(sub_root->right);h=1+(l>r?l:r);returnh;}。
数据结构 英文试题
以下是一份关于数据结构的英文试题,供您参考:1. What is the difference between an array and a linked list?Answer: An array and a linked list are two fundamental data structures used in computer science. An array is a linear data structure that stores elements in a consecutive memory location. It has a fixed size and the elements are accessed by their indices. On the other hand, a linked list is a dynamic data structure that consists of a set of nodes where each node contains the data and a reference (pointer) to the next node. The size of a linked list can vary dynamically and the elements are accessed in the order of their appearance.2. Explain the operation of binary search tree.Answer: A binary search tree is a tree-like data structure in which each node has at most two children, usually referred to as the left child and the right child. The value of each node in the binary search tree is greater than or equal to the value of all nodes in its left subtree and less than or equal to the value of all nodes in its right subtree. This property allows for efficient search, insertion, and deletion operations in the binary search tree. The search operation starts from the root node and compares the value with the target value, following the appropriate branch based on the comparison result until the target value is found or the appropriate action is taken. Insertion and deletion operations also involve maintaining the binary search tree property by adjusting the tree accordingly.3. What is the difference between a stack and a queue?Answer: A stack and a queue are two fundamental data structures used in computer science. A stack is a linear data structure that follows the Last In First Out (LIFO) principle. It allows the addition and removal of elements only at one end, usually referred to as the top of the stack. Elements are added to or removed from the stack using the push and pop operations, respectively. On the other hand, a queue is a linear data structure that follows the First In First Out (FIFO) principle. It allows the addition of elements at one end (rear) and removal of elements at the other end (front). Elements are added to or removed from the queue using the enqueue and dequeue operations, respectively.。
英文版数据结构算法题
1.Suppose we have a linked list.Eack node has three parts: one data field and twolinked fields.The list has been linked by the first linked field link1,but the list is disorder.Try your best to sort the list with the second linked field into an increasing list.算法:int creasort(struct node &head){if (head.link1 == NULL) //没有结点return ERROR;head.link2 = head.link1; //设排列链表的第一个结点head.link2->link2 = NULL;p = head.link1->link1; //p为链表的第二个结点q = head; //q代表p插入位置的前一个结点if (!p) //只有一个结点return OK;while (p){while ( q->link2 && (q->link2->data < p->data)) //找查找入位置q = q->link2;if (!q->link2) //插在最后{q->link2 = p;}else //插在队列中间{p->link2 = q->link2;q->link2 = p;}p = p->link1;q = head;}return OK;}2.Suppose we have a sequence with the terminal character @.The format of thesequence can be S1&S2,S1 and S2 do not contain ‘&’, S2 is the reverse sequence of S1.Try to write an algorithm to check the sequence if the format of the sequence obeys the above fules then the function return TRUE otherwise FALSE.算法://s为待检查的字符串int checkrules(char *s){len = strlen(s);//用string.h自带函数取字符串s的长度if (len % 2 == 0) //字符串是偶数return FALSE;i = 0; //i指向字符串第一个字符n = len - 1;//n指向字符串最后一个字符while (i < len / 2 && ( s[i] != '&' || s[n] != '&')) //对半劈{if (s[i] == s[n]){i++;n--;}elsebreak;}if (i == len / 2 && s[i] == '&') //i指向中间元素且必须是’&’return TRUE;elsereturn FALSE;}3.Suppose we have a double-linked ciroular list L.Eack node has four fields:twolinked fiels pre and next, one data field data and one frequency field freq.At the beginning the initial value of freq is 0 and after each opeation Locate(L,x),the value in frequency field of x plus 1,and then sort the list according to freq into a non-increasing list.The node which is most frequently accessed is the first node after the head node.算法:void Locate(struct doulin L, int x){struct doulin *; //访问时用到的遍历指针if (x > L.data) //无效的访问return;p = &L; //定位,p指向已经访问的指针while(x--){p = p->next;}p->freq++;//因为形参L不在循环链表里,因此要用L.pre->next表示循环链表的头结点while (p->pre ->freq < p->freq && p->pre != L.pre->next){p->data <-> p->pre->data;p->freq <-> p->pre->freq;}}4.Suppose we have a disordered list of integers.The list has been stored in a stack.You are supposed to sort the list with queue.算法://表示将from队的元素倒到to中void QueToQue(Queue *from, Queue *to, int ns){ tag = 0; //用于标注要排列的数是否进栈while (!QueueEmpty(from)){ DeQueue(from, &nq); //nq用于存取出队元素if ((tag == 0 && nq > ns) || tag == 1) //不能入队EnQueue(to, nq);else //可以入队了{ tag = 1; //设置标志tag为1,表示已经入队了EnQueue(to, ns);EnQueue(to, nq);}}if (tag == 0) //当ns比队中任何数都大时EnQueue(to, ns);}//将队列from中的元素倒到to栈中void QueToStack(Queue *from, Stack *to){ while (!QueueEmpty(from)){ DeQueue(from, &nq);Push(to, nq);}}//排序的本体void sort(Stack *S){ InitQueue(&Q1); InitQueue(&Q2); //初始化两个队列Q1,Q2Pop(S, &ns); EnQueue(&Q1, ns); //先将一个元素出队进栈while (!StackEmpty(S)){ Pop(S,&ns);if (!QueueEmpty(&Q1)) //若Q1队列不空(即Q2队列为空)QueToQue(&Q1, &Q2, ns);else //若Q2队列为空(即Q1队列不为空)QueToQue(&Q2, &Q1, ns);}if (!QueueEmpty(&Q1)) //Q1不为空,也就是要把Q1队载入栈QueToStack(&Q1, S);elseQueToStack(&Q2, S);}5.颜色排列的算法://colors是颜色数组,number是数组大小void colorsort(int *colors, int number){i = 0, j = number – 1;while (colors[i] == 1) //找到第一个非1的单元i++;while (colors[j] == 3) //找到最后一个非3的单元j--;k = i; //遍历指针设为iwhile(k <= j){switch (colors[k]){case 1: colors[k]<->colors[i];i++; k++;break;case 2: k++;break;case 3: colors[k]<->colors[j];j--;break;}}}。
C程序设计英文试题
C程序设计英文试题第1页Section 1: Single Choice(2 mark for each item, total 20 marks)1. The precedence of operator _____ is the lowest one.A.? : B.== C.+= D.&2. _____ is correct if it is used as a character constant.A.‟\‟ B.'\080' C.'%d' D.0xa3. According to the declaration: char c1=92,c2=92; the value of expression _____ is 0. A.c1^c2 B.c1&c2 C.~c2 D.c1|c24. According to the declaration: int x=11; the value of expression (x++*1/3) is_____.A.3 B.4 C.0 D.3.6675. The value of expression sizeof("\num=%d\t") is ______.A.7 B.8 C.9 D.106. In the following assignments or initialization, ______ is wrong.A.char s[ ]="hello"; B.char s[10]; s="hello";C.char *p="hello"; D.char *p; p="hello";7. The following code fragment prints out ______.#define MA(x, y) (x)*(y)int i = 2;i = 3/MA(i, i+2)+5;printf(“%d\n”, i);A.5 B.8 C.9 D.118. static struct {int x, y[3];} a[3] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}, *p;p = a+1;The value of expression *((int *)(p+1)+2) is ______.A.3 B.7 C.10 D.119. After running the following code fragment, the value of s is ______.int i=5, s=0;《C Programming》TEST PAPER, Jan 22, 2005 2 / 8do if (i%2) continue; else s+=i; while (--i);A.15 B.9 C.6 D.510. According to the declaration: int (*p)[10], p is a(n) ______.A.pointer B.array C.function D.element of arraySection 2: Fill in the blanks(2 mark for each item, total 30 marks)1. The value of expression 1+4/5+15<7+4%5+(8,10) is ______.2. The value of expression !!10 is _____.3. The value of expression 3>2>1 is _____.4. The value of expression ~(-1<<1) is ______.5. The statement for (i=1; i<=9; i++) printf(“%3d”, ______);prints out the following numbers: 1 4 7 10 13 16 19 22 25.6. According to the declaration: int a[10], *p=&a[1]+2; the last element of array a is p[__].7. Write the declaration_____ with typedef, which makes PA a synonym for a characterpointer 第2页array, which contains 100 elements.8. The following code fragment prints out _____.static int a[3][4]={{1,2,3},{4,5,6}};printf(“%d”,a[0][5]);9. The following code fragment prints out _____.char a[]={“678”,”45”},**p=a+1;printf(“%s,%c”,*p,**p-1);10. The following code fragment prints out _____.int *p, *q, k = 1, j=10 ;p=&j; q = &k ; p = q ; (*p)++;printf("%d",k);11. The following program prints out _____.#include <stdio.h>void f(int *x,int *y){ int *p;p=x; x=y; y=p;}void main(){ int x=1, y=2;f(&y, &x);printf("%d, %d", x, y);}12. The following program prints out _____.#include <stdio.h>#include <string.h>main(){ char st[20]=”hello\0world!”;《C Programming》TEST PAPER, Jan 22, 2005 3 / 8printf(“%d,%d\n”,strlen(st),sizeof(st));}13. To execute the command: prog 123 456 ABC, the value of *(++argv[2]) is_____.14. The following program fragment prints out _____.int i;int f(int x){ static int k = 0;x+=k++;return x;}i=f(2);i=f(3);printf(“%d”,i);15. The following program fragment prints out _____.int f(int x){ return ((x>0)? x*f(x-1):3); } 第3页printf(“%d”,f(f(1)));Section 3: Read each of the following programs and answer questions (5marks for each item, total marks: 30)1.The output of the following program is _______.#include <stdio.h>void main(){int i,j,k=19;while (i=k-1) {k-=3;if(k%5==0) { i++; continue; }else if(k<5) break;i++;}printf(“i=%d,k=%d\n”,i,k);}2.When input: AabD <ENTER>, The output of the following program is _______.#include <stdio.h>void main(){char s[81];int i=0;gets(s);《C Programming》TEST PAPER, Jan 22, 2005 4 / 8while (s[i]!=…\0‟){if(s[i]<= ‟z‟&&s[i]>= ‟a‟)s[i]= ‟z‟+‟a‟-s[i];i++;}puts(s);}3.The output of the following program is _______.#include <stdio.h>int x,y,z,w;void p(int x, int *y){ int z;++x;++*y;z=x+*y;w+=x;printf(“%2d%2d%2d%2d#”, x,*y,z,w);}void main()p(y, &x);printf(“%2d%2d%2d%2d\n”, x,y,z,w);}4.The output of the following program is _______.#include <stdio.h>#define F(k) k+3.14#define P(a) printf("a=%d\n", (int)(a))#define P1(a) P(a);putchar('\n');#define P2(a, b) P(a);P1(b);void main(){int x = 1;{int x = 2;P(x*F(2));}{for (; x < 10; x += 50)P2(x, 9.15*x+32);}《C Programming》TEST PAPER, Jan 22, 2005 5 / 8}5.When input: this is a test.<ENTER>, The output of the following program is _______. #include <stdio.h>#define TRUE 1#define FALSE 0int change(char *c,int status);void main(){int flag=TRUE;char ch;do{ch=getchar();flag=change(&ch,flag);putchar(ch);} while(ch!=‟.‟);printf(“\n”);}int change(char *c,int status){if(*c==‟ …) return TRUE;if(status&&*c<=‟z‟&&*c>=‟a‟) *c+=‟A‟-…a‟;return FALSE;6.There are three text files f1,f2 & f3, each of them contains some characters as following: file name contentsf1 aaa!f2 bbb!f3 ccc!Compiling the following C source codes, and linking the related object codes, an executablecommand file ex12.exe will be produced. To execute the command at DOS prompt: ex12 f1f2 f3<ENTER>,the output is: .#include <stdio.h>main(int argc, char *argv[]){FILE *fp;void sub(FILE *);int i=1;while (--argc>0)if ((fp=fopen(argv[i++],“r”))==NULL) {printf(“Cannot open file!\n”);《C Programming》TEST PAPER, Jan 22, 2005 6 / 8exit(1);} else {sub(fp);fclose(fp);}}void sub(FILE *fp){char c;while((c=getc(fp))!=…!‟) putchar(c+1);}Section 4: According to the specification, complete each program (2 mark for each blank, total: 20 marks)1 .The following program is to calculate the value of “e” according to the formula= + + + +Λ3!12!11!e 1 1 , while the value of the last item must be less than 10- 6.#include <stdio.h>main()int i;double e,item;(1) ;item=1.0;for (i=1; (2) ;i++) {item/=(double)i;e+= (3) ;}printf(“e=%f\n”,e);}2.The following program deletes the non-nested comments which be included between /* and */from the C source program file exam.c, and stores the results in the file exam.out.#include <stdio.h>void delcomm(FILE *fp1,FILE *fp2){int c,i=0;while(( (4) )!=EOF)if (c==…\n‟)fprintf(fp2,“\n”);else《C Programming》TEST PAPER, Jan 22, 2005 7 / 8switch(i){case 0:if(c==…/‟) i=1;else fprintf(fp2,“%c”,c);break;case 1:if(c==…*‟) i=2;else {fprintf(fp2,“/%c”,c);i=0;}break;case 2:if(c==…*‟) i=3;break;case 3:i=(c==…/‟)? (5) ;break;}}void main()FILE *fp1,*fp2;fp1=fopen(“exam.c”,“r”);fp2=fopen(“exam.out”,“w”);delcomm( (6) );(7) ;return;}3.Given: the pointer head points to the first node of the simple list. The following function del()deletes the first node which value is equal to num from the simple list.#include <stdio.h>struct student {int info;struct student *link;};struct student *del(struct student *head,int num){struct student *p1,*p2;if(head==NULL)《C Programming》TEST PAPER, Jan 22, 2005 8 / 8printf(“\nlist null!\n”);else {p1=head;while( (8) ) {p2=p1;p1=p1->link;}if(num==p1->info){if(p1==head) (9) ;else (10) ;printf(“delete:%d\n”,num);} elseprintf(“%d not been found!\n”,num);}return(head);。
数据结构样卷2(英文)
重庆大学 数据结构 课程样卷2开课学院: 计算机学院 课程号: 18001035 考试日期:考试方式:考试时间: 120 分钟一. Single choice1. The linear list (a1, a2, ... an), which is in Sequential Storage , whenwe delete any node, the average number of moving nodes ( ). A. n B. n/2 C. (n-1)/2 D. (n+1)/2 2. Which is wrong among the following statements ( ).A. Data element is the basic unit of the dataB. Data element is the smallest unit of the dataC. Data can be composed of a number of data elementsD. Data items can be composed of a number of data elements3. To insert a data element in a linear structure data conveniently, thebest data structure is ( ).A. Sequential storageB. Linked storageC.Index storageD. Hash storage4. If insert a new node into the doubly linked list which the number ofnodes is n, the measurement level of time complexity is ( ).A.O(1)B. O(n)C. O(nlog 2n)D. O(n 2)5. In virtue of a child’s Brother linked lists as a tree, if we want tofind the fifth child of the node x, as long as finding the first child of x, and then ( ).A. pointer scans 5 nodes continuously from the child domainB. pointer scans 4 nodes continously from the child domainC. pointer scans 5 nodes continously from the brother domainD. pointer scans 4 nodes continously from the brother domain 6. The character of Tree structure is: a node can have( )A. More than one direct pre-trendB. More than one direct successorsC. More than one pre-trendD. A successor7. Assume that there are 13 numbers, they form a Huffman tree, calculatethe number of nodes on this Huffman tree ( ). A. 13 B. 12 C. 26 D. 258. A spanning tree of the undirected connected graph is a ( ) whichcontains the whole vertices of this connected graph.A. Minimal connected subgraphB. Minimal subgraphC. Significantly connected sub-graphD. Significantly sub-graph 9. Which is wrong in the following statements ( ).A. Each vertex is only visited once during the graph traversal.B. There are two methods, Depth-First Search and Breadth-First Search,to traverse a graph.C. Depth-First Search of a graph isn ’t fit to a directed graphD. Depth-first search of a graph is a recursive process10. In sequential search algorithm of static table, if we set up a sentryat the head of a list, the right way to find the element is ( ) A. Looking for the data element from the first element to the back B. Looking for the data element from the second element to the back C. Looking for the data element from the (n+1)th element to the front D. I t is nothing to do with the search for order11. In order to find the number 85 in an ordered list(18,20,25,34,48,62,74,85), how many times do we need to compare( ) A.Once B. Twice C. 3 times D. 4 times12. Assume that the length of Hash table is m=14, Hash function H(key) =key % 11. There have been 4 nodes in the table, and their addresses are: 4,5,6,7. Other addresses are NULL. In virtue of quadratic probing re-hash to deal with conflict, calculate the address of node whose keyword is 9 ( ).A. 8B. 3C. 5D. 913. Using Quicksort to sort the following four sequences, and choose the命题人:组题人:审题人:命题时间:教务处制学院 专业、班 年级 学号 姓名公平竞争、诚实守信、严肃考纪、拒绝作弊封线密first element as the benchmark to divide. During the first division,in the following sequences which need to move the most times ( )A.70,75,82,90,23,16,10,68B.70,75,68,23,10,16,90,82C.82,75,70,16,10,90,68,23D.23,10,16,70,82,75,68,9014.There are 10000 elements in a sequence, the best way to get the very smallest 10 elements in the sequence is ( ).A. QuicksortB. HeapsortC. Insertion sortD. Merge sort15.If the sequence is almost in order, take compare times of key code and move times of key code into account, the best way to sort is( )A. Merge sortB. Insertion sortC. Straight selection sortD.Quicksort二.Fill the blanks1.In order to insert a new node s after the node which pointer q points to in a circular doubly linked list, we need to execute the followingstatements:s->prior=q; s->next=q->next; _____________________;q->next=s;2.In the doubly linked list, if d is a pointer points to a node in the list, then:d->next->__________=d->prior->__________=__________;3.Stack can be considered as an operation restricted linked list ,one end that can insert and remove is called _____________。
数据结构样卷1(英文)答案by郑
重庆大学 数据结构 课程 样卷1开课学院: 计算机学院 课程号: 18001035 考试日期:考试方式:考试时间: 120 分钟一. Single choice1. In data structure, we logically divide the data into__C_____。
A. Dynamic structure and the static structureB. Sequence structure and chain structureC. Linear structure and non-linear structureD. The internal structure and external structure2. For a singly linked list with a head node pointer, The condition todetermine whether it is empty is__B_____。
A. head == NULLB. head->next == NULLC. head->next == headD. head != NULL3. In order to prevent Pseudo-overflow, we should___D____。
书上好像没有Pseudo-overflow 的内容,这道题我是猜的A. Define enough storage spaceB. Dequeue as soon as possibleC. Enqueue as soon as possibleD. Use circular queue4. Assuming data K1! =K2, After processed by a hash function H, it isH(K1)=H(K2), then the K1, K2 are known as the H’s __A_____。
华东师范大学大一计算机专业数据结构期中英文考卷及答案 (1)
华东师范大学期中试卷20XX—20xx学年第二学期课程名称:______数据结构_____姓名:___________________ 学号:__________________专业:___________________ 年级/班级:__________________课程性质:专业必修一、单项选择题(共21分,每题3分)1. Stack has the property called last in and first out, then which of the following describes the property of Queue?a) Last in and first outb) First in and last outc) First in and first out2. A list of items from which only the item most recently added can be removed is known as a ( )a) stackb) queuec) circular linked listd) list3. If the following function is called with a value of 2 for n, what is the resultingoutput?void Quiz( int n ){if (n > 0){cout << 0;Quiz(n - 1);cout << 1;Quiz(n - 1);}}a) 00011011b) 11100100c) 10011100d) 01100011e) 0011014. What is the value of the postfix expression ?6?5 * ?4 ?3 ?2 + ?1 - / +a) 19b) 31c) 36d) 635. Given the recursive functionint Func( /* in */ int i,/* in */ int j ){if (i < 11)if (j < 11)return i + j;elsereturn j + Func(i, j - 2);elsereturn i + Func(i - 1, j);}what is the value of the expression Func(12, 15) ?a) 81b) 62c) 19d) 72e) none of the above6. Which one of the following list can use binary search?a) A C E B Db) A B C D Ec) B D A C Fd) E C A B D7. Retrieval from a linked list of length n has running time ( )a) O(1)b) O(lgn)c) O(n)d) O(nlgn)二、填空题(共16分,每空2分)1. If the following function is called with a value of 75 for n, the resulting output is_______【1】_________.void Func( /* in */ int n ){if (n > 0){Func(n / 8);cout << n % 8;}}2. Give the output of the following program. ________【2】__________.template <class List_entry>void print(List_entry &x){cout<<x<<" ";}void main( ){List<int> mylist;for(int i=0;i<5;i++)mylist.insert(i,i);cout<<"Your list have "<<mylist.size()<<" elements:"<<endl;mylist.remove(0,i);mylist.remove(2,i);mylist.insert(i,i);mylist.traverse(print);mylist.clear( );for(i=1;i<3;i++)mylist.insert(i, i);mylist.traverse(print);}3. Read the following program and fill the blank to complete the method.template <class Node_entry>struct Node {// data membersNode_entry entry;Node<Node_entry> *next;Node<Node_entry> *back;// constructorsNode( );Node(Node_entry item, Node<Node_entry> *link_back = NULL, Node<Node_entry>*link_next = NULL);};template <class List_entry>void List<List_entry> :: set_position(int position) const/* Pre: position is a valid position in the List : 0 <=position < count .Post: The current Node pointer references the Node at position . */{if (current_position <= position)for ( ; current_position != position; current_position++)【3】;elsefor ( ; current_position != position; 【4】)current = current->back;}4. Read the following program and fill the blank to complete the method.Error_code recursive_binary_2(const Ordered_list &the_list, const Key &target, int bottom, inttop, int &position)/* Pre: The indices bottom to top define the range in the list to search for the target .Post: If a Record in the range from bottom to top in the list has key equal totarget , then position locates one such entry, and a code of success is returned. Otherwise,not_present is returned, and position is undefined.Uses: recursive_binary_2, together with methods from the classes Ordered_list and Record .*/{Record data;if (bottom <= top) {int mid = 【5】;the_list.retrieve (mid, data);if (data == target) {【6】;return success;}else if (data < target)return recursive_binary_2(the_list, target, 【7】, top, position);elsereturn recursive_binary_2(the_list, target, bottom, 【8】, position);}else return not_present;}三、编程题(共63分)1.(14分)The size of array A is n.If the original array A is (e0, e1, …, e n-2, e n-1).After calling the function inverse, the array A is (e n-1, e n-2, …, e1, e0).Implement the function template:Template <class Type> void inverse( Type A[ ], int n);2.(10分)Write function remove for the implementation of doubly linked list that uses the set_position function.Error_code List<List_entry> :: remove(int position, List_entry &x)3.(16分)Write the following overload operator for stacks:1)bool Stack::operator == (const Stack & s);(8分)2)bool Stack::operator += (const Stack & s);(8分)// pushes the contents of the given stack onto this stack;4.(10分)Write the following function temple:Template <class T> void reverse(Queue <T> & q);// reverses the contents of the given queue;5.(13分)Ackermann’s function is defined as follows,A(0, n) = n+1 for n≥0A(m, 0) = A(m-1, 1) for m>0A(m, n) = A(m-1, A(m, n-1)) for m>0 and n>01)Write a recursive function to calculate Ackermann’s function. (6分)2)Draw the recursion tree of A(2, 1). (7分)数据结构期中考卷参考答案一、单项选择题(3×7=21)1. c2. a3. e4. b5. a6. b7. c二、填空题(2×8=16)【1】113【2】Your list have 5 elements:1 2 4 3【3】current = current->next【4】current_position--【5】(bottom + top)/2【6】position = mid【7】mid + 1【8】mid – 1三、编程题(14+16+10+23=63)1.template<class Type> void inverse ( Type A[ ], int n ) {Type tmp;for ( int i = 0; i <= ( n-1 ) / 2; i++ ){tmp = A[i]; A[i] = A[n-i-1]; A[n-i-1] = tmp;}}2.Error_code List<List_entry> :: remove(int position, List_entry &x) {if (position < 0 || position >= count)return range_error;Node<List_entry> *previous, *following;if (position > 0) {set_position(position - 1);previous = current;following = previous->next;previous->next=following->next;if(following->next)following->next->back=previous;}else{following = head;head = head->next;if(head)head->back=NULL;//should be addedcurrent_position = 0;current = head;}delete following;count--;return success;}3.1)bool Stack::operator==(const Stack &s){Stack s1=s, s2=*this;while (!s1.empty( ))if (s1.top( )!= s2.top( )) return false;else { s1.pop( ); s2.pop( );}}2)bool Stack:: operator+=(const Stack &s){Stack ss=s, s2;while (!ss.empty( )){s2.push(ss.top( ));ss.top( );}while (!s2.empty( )){push(s2.top( ));s2.pop( );}}4.Template <class T> void reverse (Queue<T> & q){Stack<T> s ; T data;while ( !q.empty( )){ q.retrieve(data );s.push( data);q.serve( );}while (!s.empty( )){q.append(s.top( ));s.pop( );}}5.1) int akm ( int m, int n ) {if ( m == 0 ) return n+1; // m == 0else if ( n == 0 ) return akm ( m-1, 1 ); // m > 0, n == 0else return akm ( m-1, akm ( m, n-1 ) ); // m > 0, n > 0 }2)v = 2。
2003数据结构英文试卷
2003 Data Structure Test (120 minutes) Class: Student Number: Name:1.Single-Choice(20 points)(1) The Linked List is designed for conveniently b data item.a. gettingb. insertingc. findingd.locating(2) Assume a sequence list as 1,2,3,4,5,6 passes a stack, an impossible output sequence listIs c .a. 2,4,3,5,1,6b.3,2,5,6,4,1c.1,5,4,6,2,3d.4,5,3,6,2,1(3) A queue is a structure not implementing b .a. first-in/first-outb. first-in/last-outc. last-in/last-outd. first-come/first-serve(4) Removing the data item at index i from a sequential list with n items, d items needto be shifted left one position.a. n-ib. n-i+1c. id. n-i-1(5) There is an algorithm with inserting an item to a ordered SeqList and still keeping theSeqList ordered. The computational efficiency of this inserting algorithm is c .a. O(log2n)b. O(1)c. O(n)d.(n2)(6) The addresses which store Linked List d .a. must be sequentialb. must be partly sequentialc. must be no sequentiald. can be sequential or discontiguous(7) According the definition of Binary Tree, there will be b different Binary Treeswith 5 nodes.a. 6b. 5c. 4d. 3(8) In the following 4 Binary Trees, c is not the complete Binary Tree.a b c d(9) A Binary Tree will have a nodes on its level i at most.a.2ib. 2ic.2i+1d.2i-1(10) If the Binary Tree T2 is transformed from the Tree T1, then the postorder of T1 is theb of T2.a. preorderb. inorderc. postorderd. level order(11) In the following sorting algorithm, c is an unstable algorithm.a. the insertion sortb. the bubble sortc. quicksortd. mergesort(12) Assume there is a ordered list consisting of 100 data items, using binary search to find aspecial item, the maximum comparisons is d .a. 25b.1c. 10d.7(13) The result from scanning a Binary Search Tree in inorder traversal is in c order.a. descending or ascendingb. descendingc. ascendingd. out of order(14) The d case is worst for quicksort.a. the data which will be sorted is too larger.b. there are many same item in the data which will be sorted .c. the data will be sorted is out of orderd. the data will be sorted is already in a sequential order.(15) In a Binary Tree with n nodes, there is a non-empty pointers.a. n-1b. n+1c. 2n-1d.2n+1(16) In a undirected graph with n vertexs, the maximum edges is b .a. n(n+1)/2b. n(n-1)/2c. n(n-1)d.n2(17) The priority queue is a structure implementing c .a. inserting item only at the rear of the priority queue.b. inserting item only at the front of the priority queue.c. deleting item according to the priority of the item.d. first in/first out(18) The output from scanning a minimum heap with level traversal algorithm c .a. must be an ascending sequence.b. must be descending sequencec. must have a minimum item at the head position.d. must have a minimum item at the rear position.(19) Assume the preorder of T is ABEGFCDH, the inorder of T is EGBFADHC, then thepostorder of T will be a .a. GEFBHDCAb. EGFBDHCAc. GEFBDHCAd. GEBFDHCA(20) When a recursive algorithm is transformed into a no recursive algorithm, a structureb is generally used.a. SeqListb. Stackc. Queued. Binary Tree2. Please convert the following infix expression (a*(b+c))+(b/d-e)*a into postfix expression,in the converting process, please draw the change of operator stack and the change of the output. (10 points)3. Assume a list is {xal, wan, wil, zol, yo, xul, yum, wen, wim, zi, xem, zom}, please insert these items to an empty Binary Search Tree and then construct the AVL tree. Please draw the whole processes including inserting an item, or rotate nodes to restore height balance.(10 points)4. Assume a list is {48,35,64,92,77,13, 29,44}, firstly insert these items to an empty complete Binary Tree according to the sequence one by one, then please heapify the complete Binary Tree and implement the heap sort. Please draw the whole heapigying process and sorting process. (10 points)5. For the following directed graph, give the adjacency matrix and adjacency list. Then according your adjacency list, please scan the graph using the depth-first search and the breadth-first search and give the corresponding result. (10 points)6. Assume a list is 35,25,47,13,66,41,22,57, please sorting the list with quicksort algorithm. Please write every sorting pass result (no programming).(10 points)7. Assume keys={32,13,49,55,22,39,20}, Hash function is h(key)=key%7. The linear probe open addressing is used to resolve collisions. Please try to calculate the value of Hash for each key and give the final hash table. (10 points)8. Programming (All methods have been declared in textbook can be used directly, or you can rewrite them if they are not same in your answer) (20 points)(1) Assume there are two ascending ordered lists L1 and L2, please merge L1 and L2 into a new list L3. There will be no duplicate items in L3. Then please reverse the L3 into a descending ordered list.(10 points)(2) Please give the complete declaration of Queue in circle model, then write the insert algorithm and delete algorithm. (10 points)。
c语言英文试卷
c语言英文试卷C语言英文试卷的主要内容包括:基础知识、数据结构与算法、操作系统、网络编程等方面。
以下是一些建议的英文试题:1. Choose the correct answer:Which of the following is NOT a basic data type in C language?A. intB. floatC. stringD. character2. Fill in the blank:The prototype of the function `void swap(int *a, int *b)` is______.3. Write the correct syntax for declaring a 2D array of size 3x4 and initializing it with default values.4. Choose the correct answer:Which of the following is the correct syntax for calling a function na med `sum` that takes two integers as arguments and returns an integer?A. int sum(int a, int b);B. int sum(int, int);C. int sum(a, b);D. int sum(int b, int a);5. Fill in the blank:The return statement in C language is______.6. Write a C program to find the factorial of a given number.7. Write a C program to sort an array of 10 elements using bubble s ort.8. Choose the correct answer:Which of the following is the correct way to declare a function with a pointer parameter?A. void fun(int *p);B. void fun(int &p);C. void fun(int p);D. void fun(int *&p);9. Fill in the blank:In the following code, the purpose of the `malloc` function is to allo cate______.10. Write a C program to demonstrate the use of file I/O operations.11. Write a C program to implement a simple dynamic memory alloc ation using `malloc` and `free`.12. Choose the correct answer:Which of the following is NOT a valid operator in C language?A. %B. &C. |D. <<13. Fill in the blank:The precedence of the following arithmetic operators is______.14. Write a C program to find the sum of all even numbers from 1 to 100.15. Write a C program to implement a function that takes a string as input and reverses it.Remember to provide solutions for each problem, and use appropriate English vocabulary and grammar. This will help you practice your C lan guage programming skills and prepare for an English-based exam or interv iew.。
数据结构C语言版期末考试试题(有答案)精选全文
可编辑修改精选全文完整版“数据结构”期末考试试题一、单选题(每小题2分,共12分)1.在一个单链表HL中,若要向表头插入一个由指针p指向的结点,则执行( B)。
A. HL=ps p一>next=HLB. p一>next=HL;HL=pC. p一>next=Hl;p=HL;D. p一>next=HL一>next;HL一>next=p;2.n个顶点的强连通图中至少含有(B)。
A.n—l条有向边B.n条有向边C.n(n—1)/2条有向边D.n(n一1)条有向边3.从一棵二叉搜索树中查找一个元素时,其时间复杂度大致为( C )。
A.O(1)B.O(n)C.O(1Ogzn)D.O(n2)4.由权值分别为3,8,6,2,5的叶子结点生成一棵哈夫曼树,它的带权路径长度为( D )。
A.24 B.48C. 72 D. 535.当一个作为实际传递的对象占用的存储空间较大并可能需要修改时,应最好把它说明为(B)参数,以节省参数值的传输时间和存储参数的空间。
A.整形B.引用型C.指针型D.常值引用型·6.向一个长度为n的顺序表中插人一个新元素的平均时间复杂度为( A )。
A.O(n) B.O(1)C.O(n2) D.O(10g2n)二、填空题(每空1分,共28分)1.数据的存储结构被分为顺序结构链接结构索引结构散列结构四种。
2.在广义表的存储结构中,单元素结点与表元素结点有一个域对应不同,各自分别为值域和子表指针域。
3.——中缀表达式 3十x*(2.4/5—6)所对应的后缀表达式为————。
4.在一棵高度为h的3叉树中,最多含有—(3h一1)/2—结点。
5.假定一棵二叉树的结点数为18,则它的最小深度为—5—,最大深度为—18—·6.在一棵二叉搜索树中,每个分支结点的左子树上所有结点的值一定—小于—该结点的值,右子树上所有结点的值一定—大于—该结点的值。
7.当向一个小根堆插入一个具有最小值的元素时,该元素需要逐层—向上—调整,直到被调整到—堆顶—位置为止。
数据结构样卷3(英文)
重庆大学 《数据结构》 课程样卷 3开课学院: 计算机学院 课程号: 18001035 考试日期:考试方式:考试时间: 120 分钟一、 Single choice1. Merge two ordered list, both of them contain n elements, the least timesof comparison is ( ).A. nB. 2n-1C. 2nD. n-12. Sequential stored linear list with the length of 1000, if we insertan element into any position, the possibility is equal, when we insert a new element, the average number of removing elements is ( ). A. 1000 B. 1001 C. 500 D. 4993. Assume that the initial status of stack S and queue Q are both NULL,push elements e1,e2,e3,e4,e5,e6 into the stack S one by one, an element pops from stack, then enter into queue Q. If the sequence which the six elements in the dequeue is e2,e4,e6,e5,e3,e1, the capacity of stack S is at least ( ).A. 6B. 4C. 3D. 24. Two-dimensional array A [10 .. 20,5 .. 10] stores in line sequence,each element occupies 4 storage location, and the memory address of A[10,5] is 1000, then the address of A[20,9] is ( ). A. 1212 B. 1256 C. 1368 D. 13645. A tree with degree 3, it has 2 nodes with the degree 3, one node withthe degree 2, and 2 nodes with the degree 1, so the number of nodes with degree 0 is ( ).A. 4.B. 5.C. 6.D. 76. The inorder sequence of a binary tree is ABCDEFG, and its postordersequence is BDCAFGE, so its pre-order sequence is ( ) A. EGFACDB B. EACBDGF C. EAGCFBD D. EGAFCDB7. A Huffman tree with n leaf nodes, its total number of nodes is ( )A. n-1B. n+1C. 2n-1D. 2n+18. In an adjacency list of undirected graph with n vertexes and e edges,the number of edge node is ( ).A. nB. neC. eD. 2e9. The degree (sum of in-degree and out-degree) of a directed graph isk1, and the number of out-degree is k2. Therefore, in its adjacency list, the number of edge nodes in this singly linked list is ( ). A. k1 B. k2 C. k1-k2 D. k1+k210. If the graph has n vertexes is a circle, so it has ( ) spanning tree.A. nB. 2nC. n-1D.n+111. When look up a sequential list with the length 3, the possibility thatwe find the first element is 1/2, and the possibility that we find the second element is 1/3, the possibility that we find the third element is 1/6, so the average searching length to search any element (find it successfully and the sentry is at the end of the list) is ( ) A. 5/3 B.2 C. 7/3 D.4/312. There is an ordered list {3,5,7,8,11,15,17,22,23,27,29,33}, by binarysearch to search 27, so the number of comparison is ( ) A. 2 B. 3 C. 4 D. 513. Sort the following keyword sequences by using Quicksort, and theslowest one is ( )A. 19,23,3,15,7,21,28B. 23,21,28,15,19,3,7C. 19,7,15,28,23,21,3D. 3,7,15,19,21,23,28 14. Heapsort needs additional storage complexity is ( )A. O(n)B. O(nlog 2n)C. O(n 2) D. O(1)15. If we sort an array within the time complexity of O(nlog2n), needingsort it stably, the way that we can choose is ( )A. Merge sortB. Direct insertion sortC. Heap sortD. Quicksort二、 Fill the blanks1.Assume that the structure of the nodes in doubly circular linked list is (data,llink,rlink), without a head node in the list, if we want命题人:组题人:审题人:命题时间: 教务处制学院 专业、班 年级 学号 姓名公平竞争、诚实守信、严肃考纪、拒绝作弊封线密to insert the node which pointer s points after the node pointer ppoints, then execute as the following statements:; ; ___ _; ;2.Both stack and queue are _______linear structure.3.The four leaf nodes with the weight 9,2,5,7 form a Huffman tree, itsweighted path length is ________.4.In order to ensure that an undirected graph with six vertexes isconnected, need at least ______ edges.5.An n-vertex directed graph, if the sum of all vertices’ out-degreeis s, then the sum of all vertices’ degree is__ ___.6.The Depth-First traversal of a graph is similar to the binarytree_______ traversal; the Breadth-first graph traversal algorithmis similar to the binary tree ______traversal.7. A connected graph with n vertexes and e edges has ____ edges of itsspanning tree.8.The time complexity of binary searching is _____; if there are 100elements, the maximum number of comparisons by binary searching is____.9.Sort n elements by merge sort, the requiring auxiliary space is _____.10.Sort a linear list with 8 elements by Quicksort, at the best, thecomparison time is ______.三、 Application1. Begin from the vertex A, seek the minimum spanning tree by using Primalgorithms2. The following is AOE network:(1) How much time does it take to complete the whole project?(2) Find out all of the critical path.(9 points)3. Assume that a set of keywords is {1,12,5,8,3,10,7,13,97},tryto complete the following questions:(9 points)(1) Choose the keywords in sequence to build a binary sort tree Bt;(2) Draw the structure of the tree after deleting node “12”from thebinary tree Bt.4. The keyword sequence is {503,87,512,61,908,170,897,275,653,462}, usingradix sorting method to sort them in ascending order, try to write every trip results of sort. (9 points)四、 Algorithm1.The following algorithm execute on a singly linked list without headnode, try to analyze and write its function.(5 points)void function(LinkNode *head){LinkNode *p,*q,*r;p=head;q=p->next;while(q!=NULL){r=q->next;q->next=p;p=q;q=r;}head->next=NULL;head=p;}2.Design an algorithm to divide a singly linked list ‘A’ with a headpointer ‘a’ into two singly linked list ‘A’ and ‘B’, whose head pointers are ‘a’and ‘b’, respectively. On the condition that linked list A has all elements of odd serial number in the previous linked listA and linked listB has all elements of even serial number in the previouslinked list A, in addition, the relative order of the original linked list are maintained.(7 points)3. The type of binary tree is defined as follows:typedef struct BiTNode {char data;struct BiTNode *lchild,*rchild;}BiTNode, *BiTree;Please design an algorithm to count how many leaf nodes the binary tree have. (8 points)。
