CS241 - Fall 2017 - Assignment #6
Assigned: November 21st, 2017
Due: November 30th, 2017
Collaboration policy: The goal of homework is to give you practice in
mastering the course material. Consequently, you are encouraged to collab-
orate with others (groups of at most three). In fact, students who form
study groups generally do better on exams than do students who work alone.
If you do work in a study group, however, you owe it to yourself and your
group to be prepared for your study group meeting. Specifically, you should
spend at least 30–45 minutes trying to solve each problem beforehand. If
your group is unable to solve a problem, it is your responsibility to get help
from the instructor before the assignment is due. You must write up
each problem solution and/or code any programming assignment
by yourself without assistance, even if you collaborate with others to solve
the problem. You are asked to identify your collaborators. If you did
not work with anyone, you must write “Collaborators: none.” If you obtain
a solution through research (e.g., on the web), acknowledge your source, but
write up the solution in your own words. It is a violation of this pol-
icy to submit a problem solution that you cannot orally explain
to the instructor. No other student may use your solutions; this includes
your writing, code, tests, documentation, etc. It is a violation of this policy
to permit anyone other than the instructor and yourself read-access to the
location where you keep your solutions.
1
Submission Guidelines: Your group has to submit your work on Black-
board by the due date. Only one submission per group is necessary.
Just make sure that you identify your group in the header by
putting all names in the “author” field. For each of the program-
ming assignments you must use the header template provided in Blackboard.
The header must contain, your name, course number, semester, homework
number, problem number, and list of collaborators (if any, otherwise put
“none”). Your answers to questions that do not require coding must be in-
cluded in this header as well. Your code must follow the Java formatting
standards posted in Blackboard. Format will also be part of your grade.
To complete your submission, you have to upload two files to Blackboard:
your source file and your class file. The submission will be returned without
grading if any of these guidelines is not followed.
Style and Correctness: Keep in mind that your goal is to communi-
cate. Full credit will be given only to the correct solution which is described
clearly. Convoluted and obtuse descriptions might receive low marks, even
when they are correct. Also, aim for concise solutions, as it will save you
time spent on write-ups, and also help you conceptualize the key idea of the
problem.
2
Assignment 6
Programming Assignment Grading Rubric:
The following rubric applies only to the programming assignment.
Program
characteristic
Program feature
Credit
possible
Part 3
.
The Ultimate Guide to Social Media Marketing in 2024.pdf
CS241 - Fall 2017 - Assignment #6Assigned November 21st, .docx
1. CS241 - Fall 2017 - Assignment #6
Assigned: November 21st, 2017
Due: November 30th, 2017
Collaboration policy: The goal of homework is to give you
practice in
mastering the course material. Consequently, you are
encouraged to collab-
orate with others (groups of at most three). In fact, students
who form
study groups generally do better on exams than do students who
work alone.
If you do work in a study group, however, you owe it to
yourself and your
group to be prepared for your study group meeting. Specifically,
you should
spend at least 30–45 minutes trying to solve each problem
beforehand. If
your group is unable to solve a problem, it is your responsibility
to get help
from the instructor before the assignment is due. You must
write up
each problem solution and/or code any programming assignment
by yourself without assistance, even if you collaborate with
others to solve
the problem. You are asked to identify your collaborators. If
you did
not work with anyone, you must write “Collaborators: none.” If
you obtain
a solution through research (e.g., on the web), acknowledge
your source, but
2. write up the solution in your own words. It is a violation of this
pol-
icy to submit a problem solution that you cannot orally explain
to the instructor. No other student may use your solutions; this
includes
your writing, code, tests, documentation, etc. It is a violation of
this policy
to permit anyone other than the instructor and yourself read-
access to the
location where you keep your solutions.
1
Submission Guidelines: Your group has to submit your work on
Black-
board by the due date. Only one submission per group is
necessary.
Just make sure that you identify your group in the header by
putting all names in the “author” field. For each of the program-
ming assignments you must use the header template provided in
Blackboard.
The header must contain, your name, course number, semester,
homework
number, problem number, and list of collaborators (if any,
otherwise put
“none”). Your answers to questions that do not require coding
must be in-
cluded in this header as well. Your code must follow the Java
formatting
standards posted in Blackboard. Format will also be part of your
grade.
To complete your submission, you have to upload two files to
Blackboard:
your source file and your class file. The submission will be
3. returned without
grading if any of these guidelines is not followed.
Style and Correctness: Keep in mind that your goal is to
communi-
cate. Full credit will be given only to the correct solution which
is described
clearly. Convoluted and obtuse descriptions might receive low
marks, even
when they are correct. Also, aim for concise solutions, as it will
save you
time spent on write-ups, and also help you conceptualize the
key idea of the
problem.
2
Assignment 6
Programming Assignment Grading Rubric:
The following rubric applies only to the programming
assignment.
Program
characteristic
Program feature
Credit
possible
Part 3
Design
30%
4. Algorithm 30%
Functionality
30%
Program runs
without errors
20%
Correct result given 10%
Input
15%
User friendly,
typos, spacing
10%
Values read in
correctly
5%
Output
15%
Output provided 10%
Proper spelling,
spacing, user friendly
5%
5. Format
10%
Documentation: name,
collaborators, header, etc.
5%
Clarity: comments,
indentation, etc.
5%
TOTAL 100%
1(20) 2(20) 3(40) 4(20) TOTAL(100)
3
Assignment:
The intended usage of a data structure is crucial to choose the
most
efficient one. Common operations include insertions/deletions,
queries1, and
range queries2. Suppose that the application requirements are
such that
the crucial operations are insertions and queries. We know that
hash tables
have O(1) query time, provided that the hash function
distributes the entries
uniformly. But also a good choice of the initial table size is
crucial to avoid
costly re-hashings when new entries are added. AVL trees are
6. Binary Search
Trees that balance themselves through rotations. Because they
are balanced,
the query time is O(log n). But the order in which the entries
are added is
also important to avoid the worst-case O(log n) rotations per
insertion. The
purpose of this homework is to test experimentally the insertion
and query
performance of a separate-chaining hash table and an AVL tree,
drawing
conclusions from the results observed.
Assuming that each entry is a pair <key,value>, where the key
is used
to index the entries, do the following.
1. (20 points) Make a conjecture for the asymptotic running
time of (a)
adding n entries with consecutive keys in a separate-chaining
hash
table and (b) searching for a key that is not in the table. Justify
your conjecture using the running times detailed above and any
other
assumptions you make.
2. (20 points) Make a conjecture for the asymptotic running
time of
(a) adding n entries with consecutive keys in an AVL tree and
(b)
searching for a key that is not in the tree. Justify your
conjecture
using the running times detailed above and any other
assumptions you
make.
7. 3. (40 points) Write a program that does the following.
• Create an instance of the Hashtable class from the Java API.
Make the initial table size of the hash table 1000 and the load
factor3 0.75 (which has been shown experimentally to be
optimal).
1Access operations, such as read or contains.
2Returning multiple items.
3The load factor is the occupancy threshold for rehashing. That
is, if the number of
items in the table is more than the table size times the load
factor, the object rehashes
the table increasing the capacity.
4
• Create an instance of the AVLtree class attached with this
home-
work.
• Measure the running time of adding various numbers of entries
(as
required by the table below) to the hash table and the AVL tree.
• For each of those cases, measure the running time of searching
for
a key that is not in the hash table, and do the same for the AVL
tree.
Fill in the following charts, adjusting the values of n as needed
accord-
ing to your platform to obtain at least 4 measurements.
8. construction time n = 102 n = 103 n = 104 n = 105 n = 106
Hash table
Tree
search time n = 102 n = 103 n = 104 n = 105 n = 106
Hash table
Tree
4. (20 points) How does these measurements compare with your
con-
jecture in parts 1 and 2? If the results differ from your
conjecture,
investigate the reason by looking carefully at the code of
Hashtable
(grepcode.com) and AVLtree provided and explain what might
have
happened.
5
grepcode.com
CS241 - Fall 2017 - Assignment #4
Assigned: October 30th, 2017
Due: November 7th, 2017
Collaboration policy: The goal of homework is to give you
practice in
mastering the course material. Consequently, you are
encouraged to collab-
9. orate with others (groups of at most three). In fact, students
who form
study groups generally do better on exams than do students who
work alone.
If you do work in a study group, however, you owe it to
yourself and your
group to be prepared for your study group meeting. Specifically,
you should
spend at least 30–45 minutes trying to solve each problem
beforehand. If
your group is unable to solve a problem, it is your responsibility
to get help
from the instructor before the assignment is due. You must
write up
each problem solution and/or code any programming assignment
by yourself without assistance, even if you collaborate with
others to solve
the problem. You are asked to identify your collaborators. If
you did
not work with anyone, you must write “Collaborators: none.” If
you obtain
a solution through research (e.g., on the web), acknowledge
your source, but
write up the solution in your own words. It is a violation of this
pol-
icy to submit a problem solution that you cannot orally explain
to the instructor. No other student may use your solutions; this
includes
your writing, code, tests, documentation, etc. It is a violation of
this policy
to permit anyone other than the instructor and yourself read-
access to the
location where you keep your solutions.
1
10. Submission Guidelines: Your group has to submit your work on
Black-
board by the due date. Only one submission per group is
necessary.
Just make sure that you identify your group in the header by
putting all names in the “author” field. For each of the program-
ming assignments you must use the header template provided in
Blackboard.
The header must contain, your name, course number, semester,
homework
number, problem number, and list of collaborators (if any,
otherwise put
“none”). Your answers to questions that do not require coding
must be in-
cluded in this header as well. Your code must follow the Java
formatting
standards posted in Blackboard. Format will also be part of your
grade.
To complete your submission, you have to upload two files to
Blackboard:
your source file and your class file. The submission will be
returned without
grading if any of these guidelines is not followed.
Style and Correctness: Keep in mind that your goal is to
communi-
cate. Full credit will be given only to the correct solution which
is described
clearly. Convoluted and obtuse descriptions might receive low
marks, even
when they are correct. Also, aim for concise solutions, as it will
save you
time spent on write-ups, and also help you conceptualize the
key idea of the
11. problem.
2
Assignment 4
Programming Assignment Grading Rubric:
The following rubric applies only to the programming
assignment.
Program
characteristic
Program feature
Credit
possible
Part 2
Design
30%
Algorithm 30%
Functionality
30%
Program runs
without errors
20%
Correct result given 10%
12. Input
15%
User friendly,
typos, spacing
10%
Values read in
correctly
5%
Output
15%
Output provided 10%
Proper spelling,
spacing, user friendly
5%
Format
10%
Documentation: name,
collaborators, header, etc.
5%
Clarity: comments,
indentation, etc.
5%
13. TOTAL 100%
1(20) 2(60) 3(20) TOTAL(100)
3
Assignment:
The way that data is stored in a Binary Search Tree (BST)
depends
on the order in which the values are inserted. For example, if
we insert the
numbers 1, 2, 3 in that order, the resulting tree has 1 in the root,
2 as a
right child of the root, and 3 as a right child of 2. However, if
we insert
first 2, then 2 will be stored in the root, and 1 and 3 will be the
left and
right child of the root respectively. Moreover, not only the
values are stored
in different places but also the shape of the tree obtained is
different. The
first one is skewed whereas the second one is balanced. As a
consequence,
although both trees contain the same data, the worst-case cost of
searching
differs. The purpose of this homework is to highlight this
striking difference
in running time, creating a skewed BST and a (roughly)
balanced BST, both
with a large number of nodes, and measuring the execution time
of searching
on each.
14. 1. (20 points) Estimate the asymptotic running time of searching
in a
skewed BST and a balanced BST. Justify your conjecture
explaining
which operations of the BinarySearchTree class (attached) you
would
use, and explain how do you obtain the overall running time
from the
running times of those operations. You can use asymptotic
notation
(big-O).
2. (60 points) Write a program to do the following.
• Input an integer x. (Should work with “big” numbers.)
• Create a completely-skewed BST S containing 1, 2, . . . , x.
• Create a BST R containing x integers without repetitions gen-
erated at random. (To minimize the risk of repetitions, you can
multiply the value returned by random() by a big number.)
Given
that the numbers are generated uniformly at random, the tree
will
likely be balanced.
• Measure the time to search in S for a number that is not in the
tree.
• Measure the time to search in R for a new random number.
• Display the time taken for each search.
4
Fill in a chart like the following with the times in nanoseconds
15. mea-
sured. You may need to adjust the values of n according to your
plat-
form. That is, if your program takes too long to complete, or if
you run
out of memory, etc., reduce the range of n as needed. Your chart
must
have enough cells filled to be able to answer the following
question.
n = 103 n = 104 n = 105 n = 106
Skewed BST
Balanced BST
3. (20 points) How the results obtained compare with your
conjecture? If
the results differ from your conjecture, investigate the reason by
looking
carefully at the code of the BinarySearchTree class, and explain
what
happened.
4. Extra credit: Carry out the same experiments on the Java API
class
TreeMap. Compare the measurements with the skewed tree and
random
tree. Argue why the running time functions observed are
(roughly)
equal/different .
5
16. CS241 - Fall 2017 - Assignment #5
Assigned: November 9th, 2017
Due: November 16th, 2017
Collaboration policy: The goal of homework is to give you
practice in
mastering the course material. Consequently, you are
encouraged to collab-
orate with others (groups of at most three). In fact, students
who form
study groups generally do better on exams than do students who
work alone.
If you do work in a study group, however, you owe it to
yourself and your
group to be prepared for your study group meeting. Specifically,
you should
spend at least 30–45 minutes trying to solve each problem
beforehand. If
your group is unable to solve a problem, it is your responsibility
to get help
from the instructor before the assignment is due. You must
write up
each problem solution and/or code any programming assignment
by yourself without assistance, even if you collaborate with
others to solve
the problem. You are asked to identify your collaborators. If
you did
not work with anyone, you must write “Collaborators: none.” If
you obtain
a solution through research (e.g., on the web), acknowledge
your source, but
write up the solution in your own words. It is a violation of this
pol-
icy to submit a problem solution that you cannot orally explain
to the instructor. No other student may use your solutions; this
17. includes
your writing, code, tests, documentation, etc. It is a violation of
this policy
to permit anyone other than the instructor and yourself read-
access to the
location where you keep your solutions.
1
Submission Guidelines: Your group has to submit your work on
Black-
board by the due date. Only one submission per group is
necessary.
Just make sure that you identify your group in the header by
putting all names in the “author” field. For each of the program-
ming assignments you must use the header template provided in
Blackboard.
The header must contain, your name, course number, semester,
homework
number, problem number, and list of collaborators (if any,
otherwise put
“none”). Your answers to questions that do not require coding
must be in-
cluded in this header as well. Your code must follow the Java
formatting
standards posted in Blackboard. Format will also be part of your
grade.
To complete your submission, you have to upload two files to
Blackboard:
your source file and your class file. The submission will be
returned without
grading if any of these guidelines is not followed.
Style and Correctness: Keep in mind that your goal is to
18. communi-
cate. Full credit will be given only to the correct solution which
is described
clearly. Convoluted and obtuse descriptions might receive low
marks, even
when they are correct. Also, aim for concise solutions, as it will
save you
time spent on write-ups, and also help you conceptualize the
key idea of the
problem.
2
Assignment 5
Programming Assignment Grading Rubric:
The following rubric applies only to the programming
assignment.
Program
characteristic
Program feature
Credit
possible
Design
30%
Algorithm 30%
Functionality
30%
19. Program runs
without errors
20%
Correct result given 10%
Input
15%
User friendly,
typos, spacing
10%
Values read in
correctly
5%
Output
15%
Output provided 10%
Proper spelling,
spacing, user friendly
5%
Format
10%
Documentation: name,
collaborators, header, etc.
20. 5%
Clarity: comments,
indentation, etc.
5%
TOTAL 100%
1(20) 2(30) 3(30) 4(20) TOTAL(100)
3
Assignment:
Quick Sort is a popular sorting algorithm because it usually
achieves op-
timal O(n log n) running time in practice. However, in the worst
case, the
running time can be quadratic. The method to choose the pivot
is crucial to
avoid the worst cases. The purpose of this homework is to
evaluate exper-
imentally the performance of Quick Sort for different methods
of choosing
the pivot, and compare with Selection Sort, which is simpler but
quadratic.
1. (20 points) Write a method that implements Selection Sort.
2. (30 points) Write methods for two versions of Quick Sort,
depending
on how the pivot is chosen from each subarray to be sorted, as
follows.
21. (a) Choose the pivot from the first position of the subarray.
(b) Choose three positions of the subarray at random and make
the
median of the values in these positions the pivot.
3. (30 points) Write a test program that measures the running
time
of the above three methods while sorting 1000000 numbers
(adjust
the quantity if needed). Use three types of inputs: already sorted
in increasing order, already sorted in decreasing order, and an
input
with the numbers generated at random. Fill in the following
chart with
the running times observed.
version increasing order decreasing order random
1
2a
2b
4. (20 points) Draw conclusions from the values observed. Are
the mea-
surements significantly different for some cases? Why? How the
pivot
choice helps for those cases where the running time is smaller?
Extra Credit (up to 20%): Obtain real data of similar volume
(for
instance from the Internet) and test your methods. Provide
references
to the data source. How the running times observed compare
with the
running times observed on the synthesized data used in part 3?