Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

A3.dvi School of Computer Science University of Guelph CIS*3490 The Analysis and Design of Algorithms Winter 2023 Instructor: Fangju Wang Assignment 3 (100%) For this assignment, you are...

1 answer below »
A3.dvi
School of Computer Science
University of Guelph
CIS*3490 The Analysis and Design of Algorithms
Winter 2023
Instructor: Fangju Wang
Assignment 3 (100%)
For this assignment, you are required to write programs in C. No pseudocode.
Question 1 (40%)
You have a list of n open intervals (a1, b1), (a2, b2), ..., (an, bn) on the integer line. An open
interval (a, b) comprises all the points (integers) strictly between its endpoints a and b, i.e.,
(a, b) = {x|a < x < b)}. (The points do not include a and b.) Find the maximum number of
these intervals that have a common point. For example, for the intervals (0, 5), (-1, 3), (-2, 3),
(3, 6), this maximum number is 3. 3 intervals (0, 5), (-1, 3), (-2, 3) have common point 1 or 2.
No more than 3 intervals have a common point.
Write the following programs for finding the maximum number of the intervals that have a
common point:
1.1 A program to implement a
ute force algorithm. (15%)
1.2 A more efficient program based on the presorting technique. (25%)
When a program is executed, it prompts for a file name, reads in the file containing intervals,
and finds the maximum number of the intervals that have a common point. Finally the program
eports the number and a common point.
A program is required to report the running time for searching, i.e. finding the number, (in
1.1 for searching, and in 1.2 for sorting and searching). The running time should not include
the time for reading the file.
You can use file data A3 Q1 1.txt to develop/test your programs. A different data file will be
used to grade your programs. The numbers of intervals and data formats of the two data files
will be the same.
Question 2 (60%)
Write the following programs for string search:
2.1 A program to implement a
ute force algorithm. (10%)
2.2 A program to implement the Horspool’s algorithm. (20%)
2.3 A program to implement the Boyer-Moore algorithm. (20%)
The text is in file data A3 Q2.txt, which has 44049 lines of strings. A search pattern includes
the 52 upper and lower case letters only. Search is case-sensitive. When a program is executed,
1
it reads in the text, prompts for a pattern, finds all the occu
ences of the pattern in the text,
and reports the total number of occu
ences found. Don’t remove any symbols (characters)
from the text. A program is required to report the number of pattern shifts and running time
for each search. The running time of your Horspool’s and Boyer-Moore programs should include
the time for creating tables.
The file data A3 Q2.txt will be used to grade your programs. You may hard-code the file name
in your programs.
2.4 Analyze performance of your
ute force and Horspool programs. (10%)
The performance parameters are the number of pattern shifts and running time. To compare
two programs, choose ten search patterns of different lengths, and search them by using the
programs separately. For each pattern, calculate the ratios of the performance parameters of
the two programs. Then, for all the ten patterns, calculate average ratios, and compare and
analyze the performance of the two programs in terms of the ratios. Very
iefly write you
comparison and analysis in the readme file submitted with your programs.
Note: Write your own code for this assignment. NO code from any source is allowed.
Due time: 08:00am, Monday March 13, 2023. Submit your work as a tar file to Moodle.
2

A3_guide.dvi
School of Computer Science
University of Guelph
CIS*3490 The Analysis and Design of Algorithms
Winter 2023
Instructor: Fangju Wang
Assignment 3 Guide
You can develop your programs using any C system, as long as your programs can be
co
ectly compiled and executed on the SoCS Linux server.
You are allowed to use standard li
ary functions. Your programs should be submitted as
a tar file containing files like
eadme.txt, P11.c, P12.c, P21.c, P22.c, P23.c, makefile.
Any compilation warning will result in a mark deduction. There will be some marks allocated
for documentation.
Each file should have a comment at the beginning containing your name, ID, date, and the
assignment number.
The readme file should contain the following:
• Name, ID and assignment numbe
• A
ief and clear description of how to compile and run your programs.
• Comparison and analysis for Q2.4.
Each function should have a
ief comment describing its purpose. Also, any section of code
where it is not easily apparent what the code does should have a short comment.
Hints for individual questions:
1 You may visualize the example in the handout by drawing the integer line at the bottom,
and above it a short line representing an interval. Visualizing the example may help you
understand the problem and develop algorithms.
1.1 Find the minimum and maximum endpoints (integers) of all the intervals. Scan the intege
line between the minimum and maximum. For each of the points, check all the intervals
to see how many intervals include it.
1.2 You may sort the endpoints of all the intervals, and also find the minimum and maximum
of the endpoints. By scanning the sorted endpoints of intervals you can find the maximum
number.
1
1.1, 1.2 The output could be something like:
Brute force program for finding max number of intervals
The maximum number of intervals: 15057
The intervals include point: 21713
Time for finding the maximum number: 6236 ms
2.1, 2.2, 2.3 You can follow the algorithms in the text. The output could be something like:
A Brute force program for string search.
Enter a pattern: maintain
Count: 137
Shifts: XXXXXXXXXX
Execution time = 14 ms
In searching a pattern, the counts of different algorithms must be the same. The numbers
of shifts of different implementations of the same algorithm could differ slightly.
2

XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
Answered 17 days After Mar 12, 2023

Solution

Aditi answered on Mar 13 2023
33 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here