0% found this document useful (0 votes)
101 views

CS3330 Problem Set 1 - Recursion and Complexity Analysis - Complete Solution

CS3330 Problem Set 1: Recursion and Complexity Analysis | Complete Solution CS3330 Problem Set 1: Recursion and Complexity Analysis | Complete Solution Problem Set 1: Recursion and Complexity Analysis CS3330 Data Structures and Algorithms Overview: For problem 1(a) of this assignment, you will need a C++ compiler. In order to receive credit, your program must compile and run; and you must provide the actual source code file so that I can compile and run your program (e.g. the file you modified ending in .cpp). Examples on how to import existing files into your compiler are provided in the file called Importing Source Code.pdf. The remaining problems for the assignment must be written up within a single Microsoft Word document. You must include your name and course number within all files that you submit, including source code files as a comment at the top of each file that you create or modify. 1. [7 points] Recursion. Read the assigned chapter and notes for Week 1 located in the Learning Activities area in Blackboard. Then provide solutions for the following: (a) [3 points] Download the f.cpp file, then using the definition below, implement the details of a recursive function called f(n). This function can be directly translated into C/C++ from the following mathematical definition: ( 1) 2 1 0 ( 1) 2 1 0 0 0 ( ) f n n n f n n n n f n The function must be implemented based on the mathematical definition provided above. Note: For this program, the function must use recursion. You only need to modify the provided file by adding the necessary code to implement the TODO areas as noted in the comments. Everything else in the program should remain the same. Output: The output for this program once the function is implemented will be as follows: f(-44) is 1936 f(-20) is 400 f(-1) is 1 f(0) is 0 f(1) is 1 f(13) is 169 f(20) is 400 f(50) is 2500 f(44) is 1936 ** Press any key to continue ** (b) [2 points] Briefly explain how the following recursive function could result in an infinite loop and what you could do to correct this: (c) [2 points] Perform an Internet search and provide a brief description (at least a paragraph with four to five sentences) of an example of a practical use for recursion. For example, the practical use you mention should be something other than simple function implementations such as factorial, the power of a number, Fibonacci, etc. The description should be in your own words. Include the reference to your source or sources in APA format at the end of your description. 2. [3 points] Complexity Analysis. Begin by reading the assigned chapter and notes for Week 2 located in the Learning Activities area in Blackboard. Then answer the following questions: (a) [2 points] Briefly explain the difference between big-Ω (Omega) and big-O notation. Also provide the mathematical definitions of each. (b) [1 points] What is the asymptotic complexity (or big-O) of the following code block? Briefly explain why. Note: No programming is necessary for this problem. Just tell me what the big-O of the function, and provide a couple of sentences explaining how you arrived at the solution. for (int i=0; i < n; i++) { for (int j=0; j < n; j++) { a[i][j]=0; for (int k=0; k < n; k++) { a[i][j] += b[i][k] * c[k][j]; } } } Other Notes: Submit your solutions as a single Zip file using the Problem Set 1 link provided in the Assignments area. If you are using the Visual C++ or Dev-C++ compiler, you should only submit the source code files for your program (the files ending in .cpp and .h). For space reasons, please do not submit the entire Visual C++ or Dev-C++ project folders. Do not hesitate to ask if you have any questions or need clarification on what to do for this assignment. CS3330 Problem Set 1: Recursion and Complexity Analysis | Complete Solution
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

CS3330 Problem Set 1 - Recursion and Complexity Analysis - Complete Solution

CS3330 Problem Set 1: Recursion and Complexity Analysis | Complete Solution CS3330 Problem Set 1: Recursion and Complexity Analysis | Complete Solution Problem Set 1: Recursion and Complexity Analysis CS3330 Data Structures and Algorithms Overview: For problem 1(a) of this assignment, you will need a C++ compiler. In order to receive credit, your program must compile and run; and you must provide the actual source code file so that I can compile and run your program (e.g. the file you modified ending in .cpp). Examples on how to import existing files into your compiler are provided in the file called Importing Source Code.pdf. The remaining problems for the assignment must be written up within a single Microsoft Word document. You must include your name and course number within all files that you submit, including source code files as a comment at the top of each file that you create or modify. 1. [7 points] Recursion. Read the assigned chapter and notes for Week 1 located in the Learning Activities area in Blackboard. Then provide solutions for the following: (a) [3 points] Download the f.cpp file, then using the definition below, implement the details of a recursive function called f(n). This function can be directly translated into C/C++ from the following mathematical definition: ( 1) 2 1 0 ( 1) 2 1 0 0 0 ( ) f n n n f n n n n f n The function must be implemented based on the mathematical definition provided above. Note: For this program, the function must use recursion. You only need to modify the provided file by adding the necessary code to implement the TODO areas as noted in the comments. Everything else in the program should remain the same. Output: The output for this program once the function is implemented will be as follows: f(-44) is 1936 f(-20) is 400 f(-1) is 1 f(0) is 0 f(1) is 1 f(13) is 169 f(20) is 400 f(50) is 2500 f(44) is 1936 ** Press any key to continue ** (b) [2 points] Briefly explain how the following recursive function could result in an infinite loop and what you could do to correct this: (c) [2 points] Perform an Internet search and provide a brief description (at least a paragraph with four to five sentences) of an example of a practical use for recursion. For example, the practical use you mention should be something other than simple function implementations such as factorial, the power of a number, Fibonacci, etc. The description should be in your own words. Include the reference to your source or sources in APA format at the end of your description. 2. [3 points] Complexity Analysis. Begin by reading the assigned chapter and notes for Week 2 located in the Learning Activities area in Blackboard. Then answer the following questions: (a) [2 points] Briefly explain the difference between big-Ω (Omega) and big-O notation. Also provide the mathematical definitions of each. (b) [1 points] What is the asymptotic complexity (or big-O) of the following code block? Briefly explain why. Note: No programming is necessary for this problem. Just tell me what the big-O of the function, and provide a couple of sentences explaining how you arrived at the solution. for (int i=0; i < n; i++) { for (int j=0; j < n; j++) { a[i][j]=0; for (int k=0; k < n; k++) { a[i][j] += b[i][k] * c[k][j]; } } } Other Notes: Submit your solutions as a single Zip file using the Problem Set 1 link provided in the Assignments area. If you are using the Visual C++ or Dev-C++ compiler, you should only submit the source code files for your program (the files ending in .cpp and .h). For space reasons, please do not submit the entire Visual C++ or Dev-C++ project folders. Do not hesitate to ask if you have any questions or need clarification on what to do for this assignment. CS3330 Problem Set 1: Recursion and Complexity Analysis | Complete Solution
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

10/30/2015

TheAceStudent:CS3330ProblemSet1:RecursionandComplexityAnalysis|CompleteSolution

CS3330ProblemSet1:RecursionandComplexityAnalysis|
CompleteSolution
CS3330ProblemSet1:RecursionandComplexityAnalysis|CompleteSolution
ProblemSet1:RecursionandComplexityAnalysisCS3330DataStructuresandAlgorithms
Overview:Forproblem1(a)ofthisassignment,youwillneedaC++compiler.Inordertoreceive
credit,yourprogrammustcompileandrunandyoumustprovidetheactualsourcecodefilesothat
Icancompileandrunyourprogram(e.g.thefileyoumodifiedendingin.cpp).Examplesonhowto
importexistingfilesintoyourcompilerareprovidedinthefilecalledImportingSourceCode.pdf.The
remainingproblemsfortheassignmentmustbewrittenupwithinasingleMicrosoftWorddocument.
Youmustincludeyournameandcoursenumberwithinallfilesthatyousubmit,includingsource
codefilesasacommentatthetopofeachfilethatyoucreateormodify.1.[7points]Recursion.
ReadtheassignedchapterandnotesforWeek1locatedintheLearningActivitiesareain
Blackboard.Thenprovidesolutionsforthefollowing:(a)[3points]Downloadthef.cppfile,then
usingthedefinitionbelow,implementthedetailsofarecursivefunctioncalledf(n).Thisfunctioncan
bedirectlytranslatedintoC/C++fromthefollowingmathematicaldefinition:(1)210(1)21000(
)fnnnfnnnnfnThefunctionmustbeimplementedbasedonthemathematicaldefinition
providedabove.Note:Forthisprogram,thefunctionmustuserecursion.Youonlyneedtomodify
theprovidedfilebyaddingthenecessarycodetoimplementtheTODOareasasnotedinthe
comments.Everythingelseintheprogramshouldremainthesame.Output:Theoutputforthis
programoncethefunctionisimplementedwillbeasfollows:f(44)is1936f(20)is400f(1)is1f(0)
is0f(1)is1f(13)is169f(20)is400f(50)is2500f(44)is1936**Pressanykeytocontinue**(b)[2
points]Brieflyexplainhowthefollowingrecursivefunctioncouldresultinaninfiniteloopandwhat
youcoulddotocorrectthis:(c)[2points]PerformanInternetsearchandprovideabriefdescription
(atleastaparagraphwithfourtofivesentences)ofanexampleofapracticaluseforrecursion.For
example,thepracticaluseyoumentionshouldbesomethingotherthansimplefunction
implementationssuchasfactorial,thepowerofanumber,Fibonacci,etc.Thedescriptionshouldbe
inyourownwords.IncludethereferencetoyoursourceorsourcesinAPAformatattheendofyour
description.2.[3points]ComplexityAnalysis.Beginbyreadingtheassignedchapterandnotesfor
Week2locatedintheLearningActivitiesareainBlackboard.Thenanswerthefollowingquestions:
(a)[2points]Brieflyexplainthedifferencebetweenbig(Omega)andbigOnotation.Alsoprovide
themathematicaldefinitionsofeach.(b)[1points]Whatistheasymptoticcomplexity(orbigO)of
thefollowingcodeblock?Brieflyexplainwhy.Note:Noprogrammingisnecessaryforthisproblem.
JusttellmewhatthebigOofthefunction,andprovideacoupleofsentencesexplaininghowyou
arrivedatthesolution.for(inti=0i<ni++){for(intj=0j<nj++){a[i][j]=0for(intk=0k<n
k++){a[i][j]+=b[i][k]*c[k][j]}}}OtherNotes:SubmityoursolutionsasasingleZipfileusingthe
ProblemSet1linkprovidedintheAssignmentsarea.IfyouareusingtheVisualC++orDevC++
compiler,youshouldonlysubmitthesourcecodefilesforyourprogram(thefilesendingin.cppand
.h).Forspacereasons,pleasedonotsubmittheentireVisualC++orDevC++projectfolders.Do
nothesitatetoaskifyouhaveanyquestionsorneedclarificationonwhattodoforthisassignment.
CS3330ProblemSet1:RecursionandComplexityAnalysis|CompleteSolution

data:text/htmlcharset=utf8,%3Ch3%20class%3D%22posttitle%20entrytitle%22%20itemprop%3D%22name%22%20style%3D%22margin%3A%200px

1/1

You might also like