Clarifications/Hints
First, we need to find a set of students in the top k% of GPA. Assume all the students have the same GPA, then all of them will be in the top k% range. Then my algorithm should return all of the students instead of just k% of the all the students, is this correct? Yes, if all the students have the same GPA, then the top k% would have to be all of them.
Second, after selecting out the set of students with top k% GPA, should my algorithm return the students in the order of GPA (from lower to higher) or just in the any order? As the assignment asked for a set, which is inherently unordered, you do not have to sort the set of students returned.
Clarifications/Hints
Today (2/16/12) in class we decided the following issues:
% ./prog2 -p 10 -i overexposedGrey.pgm -s overexposedSorted.pgm -r overexposedRed.ppm
2, 5, 6, and 7 (prove both part a and part b)
Clarifications/Hints
I am having trouble finding out why the proof fails on problem #5.
T(n) = 5T(n/5) + 2n
Claim: T(n) = O(n)
Hypothesis: T(n) <= c*n for all m < n
Base case: T(1) = c -> c*1 = c
Proof by induction:
T(m) = 5T(m/5) + 2m |
<= 5(c*(m/5)) + 2*m |
= c*m + 2*m |
= (c+2) * m |
<= c * m | if c >= 2
I don't understand. I can find no algebraic errors, all signs seem to
hold true. And I was able to get the equation back to the hypothesis
form, which proves it correct, unless I am terribly mistaken.Hint: if x+2 >= 42 is x >= 42? If not in all cases, then your proof is incorrect.
Also, have you tried using the master theorem to see what it gives for the solution to this recurrence?
For problem 5, be sure to justify in detail the run time of your algorithm.
Hi, I am having a problem understanding the first question of homework 3. I don't get what you mean by "achieve the smallest average number of comparisons to sort a list into the the order 1,4,2,3." Could you explain what you mean by "order"? Does 1,4,3,2 represent a leaf of the decision tree? Or is it derived from one of the leafs?
This problem asks you to sort a list into a particular order. The order isn't smallest to largest, it is as stated in the problem. Whatever item in the list is smallest should be the first item in the output list. Whatever item is largest should be the second item in the output list. etc. Thus the output order is 1432 (which represents where each item would go from an input list that was in order smallest to largest). Your job is to produce a decision tree that solves the problem of taking an input list that is in an arbitrary order, and outputting a list sorted as stated. Of all the possible decision trees, your tree must use the fewest average number of comparisons between elements to sort an input list.
E.g. if the input list was "atom", "big", "plant", "little" the output should be "atom", "plant", "big", "little" or if you consider the indexes, the output item in the first position was at the old 1, then 3, then 2 then 4.
Clarifications
In class Thr. we decided that no vector of students will consist of fewer than 4 items.
We also decided that not two student records will have the same First name, last name and SSN. At least one of these must be different for each element of the vector of students.
There is a return value num_compares in FindMaxMin() function. Does it mean that we need to count that how many comparisons happen inside FindMaxMin() function?
Yes, your function must count how many comparisons it does. The comparisons you are to count are those involving the entire entry (see also the next question below).
Someone asked if the number of comparisons counted only the comparisons of entire elements in the input.
The intent of the assignment was to get you to think about how to efficiently solve this problem using comparison of entire elements (i.e. Names/SSNs). As for the 4 pt. bonus, solutions that do not use comparison of entire elements would have to be judged on a different basis. A thorough justification for any other method would have to be provided, including data validating why you believe your method is better.
Two other criteria for the assignment were to use an efficient solution (one that asymptotically runs the fastest). And one that on "cpu seconds" consumes the least amount of time. Both of these criteria are also important to scoring well.
Are we allowed to edit the student.h file that we download from prime?
No, you MUST use the student.h file as is. All the member variables are public so you can access them directly. Remember the focus of this assignment is on efficiency. Adding a lot of functions between you and the data will likely increase the access time.
I'm not sure yet how to use FindMaxMin.h and FindMaxMin.cc to come up with functions that both create and read Student objects that are defined in a separate file entirely.
As for these sorts of functions, it might be best not to read the data from a file, but use a function to generate random data. However, it is also reasonable to have a fixed file to use each time so that you can tell if you are making changes that make your code faster.
If you use srand to set the seed of the random number generator, you can ensure that each time you run your program you'll get the same randomly generated data
You should be able to write a very simple function to read a student object in from a file. Since all the member variables are public, simply do a new to create a student object, then read in each of the fields it requires.
Have a quick question about the programming part of the second homework. when calling the function from main.cc, my function just prints this output
Max:5 Min:0 Max2:6 Min2:1is this sufficient enough?
In addition to showing your function is correct, your submitted main program must thoroughly test your function, and provide timings to show you have tried to optimize your code. In addition, an analysis of the number of comparisons utilized should be reported. One test case is NOT sufficient. Also, your tests should show the time behavior of your function as input sizes increase.
Clarifications
I'm having trouble with the nlgn part of problem 1. Do you have any hints to get
me going in the right direction? Thank you.
A couple of hints:
1.) You cannot solve equations like this exactly (there is no
closed-form solution).
2.) You do have access to a computer that is great at calculating lots and lots of trials.
3.) Look up the bisection method in google for solving the roots of numerical equations. I.e. if you can put the problem in the form of:
f(x) = 0
There are several relatively easy ways to solve it.
In general, since you will be learning how to implement good algorithms, use of the STL algorithm sort, or the list member function sort is not allowed (but see below for exceptions).
Be sure to credit all sources for any code that you did not write yourself! Any code you turn in must be written according to the style guidelines for this class, which includes (among other things) headers that include an asymptotic analysis of space and time complexity.
NOTE: Homework assignments are also available on
prime/p1/p2 clients. These files are in the same format as the
lecture notes. You can find them in ~cs404/homework. You can
print them in the same way as the lecture notes.
Class
Homepage