1、3 Projects3.1 Project 1: Performance Measurement9Given a list of orderedN integers, numbered from 0 toN 1, checking to see that N is notin this list provides a worst case for many search algorithms.Consider two algorithms: one is called “sequential search” which scans through the list from left to r
2、ight; and the other is “binary search” which is given on page 24(Figure 2.9) of your textbook. Your tasks are:(1) Implement an iterative version and a recursive version of sequential search;(2) Implement an iterative version of binary search;(3) Analyze the worst case complexities of the above two v
3、ersions of sequential search and that of binary search;(4) Measure and compare the worst case performances of the above three functions forN = 100,500,1000,2000,4000,6000,8000,10000.To measure the performance of a function, we may use Cs standard library time.h as the following:Note: If a function r
4、uns so quickly that it takes less than a tick to finish, we may repeat the function calls for K times to obtain a total run time(“Total Time”), and then divide the total timeby Kto obtain a more accurate duration(“Duration”) for a single fun of the function. Therepetition factor must by large enough
5、 so that the number of elapsed ticks is at least 10 if we want an accuracy of at least 10%.The test results must be listed in the following table:The performances of the three functions must be plotted in the sameN -run_time coordinatesystemforillustration.3.2 Project 2: Implementation of Lists, and
6、 PolynomialProblems1. Merge two ordered lists into a new linked list in which the nodes are also in this order. If lengths of original two lists are m and n, the length of new linked list is m + n.For example:Input:5 (length of list 1)42646569511 (length of list 2)1517263046485658829095Output:415172
7、63046485658829095Demands:(1). You should use single linked list(with a header) to create the functions MakeEmpty, IsEmpty, IsLast, Find, Delete, FindPrevious, Insert, DeleteList, Header, First, Advance, Retrieve(See P40,Figure3.6).(2). Using above functions to solve this problem.(3). The linked impl
8、ementation of list should be written in separated files (.cpp and .h) in the VC+ workspace.Their names should be linkedlist.h, linkedlist.cpp, merge.cpp.2. The declarations that follow give us the polynomial ADT. Structure Polynomial isObject:P(x) = a xe1 +L+ a xen ;a set of ordered pairs of where a
9、 is1the coefficient and eiOperations:niis the exponent. ei are nonnegative integers.For all poly,poly1,poly2Polynomial,coefCoefficients, exponExponents Polynomial Zero():= return the polynomial, P(x)=0Boolean IsZero(poly):= if (poly) return FALSE;else return TRUE;Coefficient Coef(poly, expon):= if (
10、expon poly) return its coeffientelse return zero.Exponent Lead_Exp(poly):= return the largest exponent in poly.Polynomial Attach(poly, coef, expon):= if (expon poly) return errorelse return the polynomial poly with the term inserted.Polynomial Remove(poly, expon):= if (expon poly) return the polynom
11、ial poly withthe term whose exponent is expon deletedelse return error.Polynomial SingleMult(poly, coef, expon) := return the polynomial poly*coef*x exponPolynomial Add(poly1,poly2):= return the polynomial poly1 + poly2. Polynomial Mult(poly1,poly2):= return the polynomial poly1 * poly2. end Polynom
12、ialDemands:(1). You should choose a suitable representation for Polynomial.(2). You should create the functions Zero, IsZero, Coef, Lead_Exp, Attach, Remove, SingleMult, Add, Mult, and test them.(3). IfA(x) = 3x20 + 2x5 + 4 and B(x) = 3x4 + 2x3 + 3x2 +1 , write a function to use abovefunctions to co
13、mpute C(x) = A(x) + B(x) and D(x) = A(x)* B(x) .(4). Analyze advantages of your representation.(5). The implementation of polynomial ADT should be written in separated files (.cpp and .h) in the VC+ workspace.Their names should be Polynomial.h, Polynomial.cpp, main.cpp.Note:Your program must read fr
14、om a file “input.txt” and write to a file “output.txt” in the current directory.3.3 Project 3: Implementation and Applications of StacksProblems1. Write a Conversion function to converse any decimal data to binary version.Demands:(1). Implement Stack ADT using linked list representation, which must
15、at least has five basic operations: Create , IsFull, Push , IsEmpty and Pop.(2).Build a new project to implement the Conversion function. The input and output should be according to the following format:Please input the decimal number: 15The corresponding binary version is: 1111Please input the decimal number: -1Bye!2. Write a program to judge whether a bracket sequence (maybe has other letters) is “matching”. The “matching” means that if there ha
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1