1. Homepage
  2. Programming
  3. COMP3023 Design and Analysis of Algorithms - Programming Assignment: Maximum contiguous array problem

COMP3023 Design and Analysis of Algorithms - Programming Assignment: Maximum contiguous array problem

Engage in a Conversation
McGillCOMP3023Design and Analysis of AlgorithmsCDivide-and-conquerDynamic programming

COMP3023 24S Programming Assignment CourseNana.COM

  CourseNana.COM

Lecture 2 introduces a divide-and-conquer algorithm for the maximum contiguous array problem. In this programming assignment, you need to design and implement a dynamic programming algorithm under the following requirements. CourseNana.COM

Environment CourseNana.COM

-       The implementation must be done in standard C (using gcc compiler). Please do not use visual studio. For the students who do not have the compiler, you can use online GDB at https://www.onlinegdb.com/. CourseNana.COM

-       For FE students who haven’t taken COMP1023 Foudations of C Programming, you can use C++. CourseNana.COM

-       Submissions which cannot pass gcc/g++ compilation, will directly receive 0. To check whether your code can pass compilation, use online GDB at least. CourseNana.COM

-       Plagiarism will receive 0. Plagiarism can be (but not limited to) CourseNana.COM

o   Copying from other students, CourseNana.COM

o   Copying from internet, CourseNana.COM

o   Providing copies, CourseNana.COM

o   Hiring agents. CourseNana.COM

This assignment is not difficult. Be confident! You can work it out by yourself.  CourseNana.COM

  CourseNana.COM

Implementation Structure CourseNana.COM

In your program, you need to implement three source files “mcs.c”, “lib.h”, and “lib.c” (“mcs.cpp”, “lib.h” and “lib.cpp” if you use C++). CourseNana.COM

For “mcs.c” (or “mcs.cpp”) CourseNana.COM

-       It only contains the “main” function. CourseNana.COM

-       It reads inputs from text files. The input text file is passed to the main function as an argument. CourseNana.COM

-       For testing convenience purpose, text files are without “.txt” extension. But you can open them with text editors anyway. CourseNana.COM

-       Each text file contains exactly one instance of MCS. CourseNana.COM

-       The index of the array starts from 0. CourseNana.COM

  CourseNana.COM

For “lib.h” and “lib.c” (or “lib.h” and “lib.cpp”) CourseNana.COM

-       .h is the header file for .c (or .cpp). CourseNana.COM

-       They contain all other functions except “main”. CourseNana.COM

  CourseNana.COM

Functionality CourseNana.COM

-       The input txt file contains the input array of integers as one line. Two integers are separated by a space “ ”. Negative integers start with the negative sign “-”. You can assume that the input file is robust. It does not contain any illegal integers or other symbols. CourseNana.COM

-       When the calculation is finished, print the optimal value (sum of the MCS) and one optimal solution (start index and end index of the subarray) on separate lines on the screen. (The optimal value is unique, but the optimal solution may not.) CourseNana.COM

-       Your program also writes the output (the optimal value and one optimal solution in the same format) to “xxx_out”, where “xxx” is the input txt file name. Again, please do not add any extension to output files. CourseNana.COM

  CourseNana.COM

Documentation CourseNana.COM

Other than implementation, each student also needs to submit a document, which contains CourseNana.COM

-       the formal definition of the problem, CourseNana.COM

-       the recurrence relation of your dynamic programming algorithm, CourseNana.COM

-       definitions of the notations in your recurrence relation, CourseNana.COM

-       pseudocode of your algorithm, and CourseNana.COM

-       time cost analysis of your algorithm. CourseNana.COM

  CourseNana.COM

Submission CourseNana.COM

You need to pack all files in a package. Rename the package as COMP3023_24S_PA_XX and the document as XX_Description, where XX is your studend ID. Students who do not rename properly (the document or source files) will receive 10% off. CourseNana.COM

  CourseNana.COM

Bonus CourseNana.COM

Besides the basic requirements, students are encouraged to hunt for bonus. Each bonus is worth 5% of the total marks for this programming assignment. CourseNana.COM

-       Documentation: Write the documentation in markdown files or LaTeX. All notations, equations, and pseudo code should be in correct environments. CourseNana.COM

-       Functionality: Output all optimal solutions (both on the screen and to the output file). CourseNana.COM

-       Functionality: The number of integers from the input is unknown. So, you cannot assume the maximum length of the input array. Thus, to read an arbitrary length array, you need to use dynamic memory allocation. The time cost of reading the input needs to be in . CourseNana.COM

If you implement any functionality bonus, you need to describe them in your documentation. CourseNana.COM

  CourseNana.COM

Sample CourseNana.COM

In the folder “Sample”, you will find all the source files described above. Take the C version in subfolder “c” for example (the C++ version is in subfolder “c++”). Currently, all source files are empty. The main function simple prints the argument on the screen. “lib.c” only tests the linkage. The package also contains “make.bat”. You can open it by a TXT editor. Then, you can see the compilation commands. CourseNana.COM

CourseNana.COM

After executing “make.bat”, you will have “mcs.exe”. (Note that .bat files are only executable in Windows. For Mac users, you can directly type in the commands or create your own makefile. The extension for executable files is different in Mac OS.) CourseNana.COM

Next, if try to execute the sample code on the input file “in”, it will give you the following. CourseNana.COM

CourseNana.COM

  CourseNana.COM

Example instance CourseNana.COM

Suppose the input file contains CourseNana.COM

CourseNana.COM

The output should be CourseNana.COM

CourseNana.COM

Because CourseNana.COM

            CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
McGill代写,COMP3023代写,Design and Analysis of Algorithms代写,C代写,Divide-and-conquer代写,Dynamic programming代写,McGill代编,COMP3023代编,Design and Analysis of Algorithms代编,C代编,Divide-and-conquer代编,Dynamic programming代编,McGill代考,COMP3023代考,Design and Analysis of Algorithms代考,C代考,Divide-and-conquer代考,Dynamic programming代考,McGillhelp,COMP3023help,Design and Analysis of Algorithmshelp,Chelp,Divide-and-conquerhelp,Dynamic programminghelp,McGill作业代写,COMP3023作业代写,Design and Analysis of Algorithms作业代写,C作业代写,Divide-and-conquer作业代写,Dynamic programming作业代写,McGill编程代写,COMP3023编程代写,Design and Analysis of Algorithms编程代写,C编程代写,Divide-and-conquer编程代写,Dynamic programming编程代写,McGillprogramming help,COMP3023programming help,Design and Analysis of Algorithmsprogramming help,Cprogramming help,Divide-and-conquerprogramming help,Dynamic programmingprogramming help,McGillassignment help,COMP3023assignment help,Design and Analysis of Algorithmsassignment help,Cassignment help,Divide-and-conquerassignment help,Dynamic programmingassignment help,McGillsolution,COMP3023solution,Design and Analysis of Algorithmssolution,Csolution,Divide-and-conquersolution,Dynamic programmingsolution,