An education researcher has the hypothesis that higher education only reinforces…
- User
An education researcher has the hypothesis that higher education only reinforces existing education inequalities, rather than making students catch up and excel. More specifically, he makes the strong hypothesis that the student with the highest SAT score coming in will have the highest GPA upon graduation, the student with the second-highest SAT score will have the second-highest GPA, and so on. To be consistent, he hypothesizes that students coming in with the same SAT score will also have the exact same GPA. He would like you to write a program to test his theory on data sets. Each data set will contain students sorted alphabetically, with their GPA and SAT score given. Your program should determine whether his hypothesis is true. Add your code to the skeleton on the next page. Because he expects to run on several large data sets, your algorithm must run in time O(nlogn) for data sets of n students. struct StudentRecord { string name; // name of the student int SAT; // SAT score double GPA; // GPA at graduation // feel free to add functionality here if you need it. }; int main (int nargs, char** args) { int n; // number of students in data set StudentRecord students; read_data (args[1], &n, students); / this function reads all the data correctly from the file and puts them in the array ‘students’. When the function returns, the students in the array will be sorted by name. n will be the size of the array. No two students will have the same name. */ // Your code goes here. You should output "Yes" if the hypothesis is true, and "No" otherwise.
- Assistant
- User
explains more on the sort algorithm and why is it log n
- Assistant
- User
dont create vector just use the array
- Assistant
- User
// Sort the students array based on SAT scores, and then by GPA for ties sort(students, students + n, [](const StudentRecord &a, const StudentRecord &b) { if (a.SAT == b.SAT) { return a.GPA < b.GPA; // Compare by GPA if SAT scores are tied } return a.SAT < b.SAT; // Otherwise, compare by SAT scores }); why dpes parameter have studetns + n?
- Assistant
- User
do not use the sort function
- Assistant
- User
modify it so now you can just Write sort(a,left,right) to sort an array a between left and right (inclusive) in ascending order. no need for implementatiob
- Assistant
- User
You put k keys into a hash table with m hash buckets. We assume that the hash function is good enough that you can treat the destination of each key as independently uniformly random. What is the probability that there are no collisions at all, i.e., that all keys end up in different positions of the array? Show your work as you derive your answer.
- Assistant
- User
if i do: # of ways for no collision is "m choose k" and there are m^k ways in total so p = "m choose k" / m^k is that correct
- Assistant
- User
Implement and analyze lookup of keys in general (b, 2b − 1) trees. Remember that these are trees in which each node has at least b and at most 2b − 1 children. Other than that, they are exactly like 2–3 trees, which are the special case b = 2. You are already given the class BTreeNode below, which only has integers keys, and no values (to keep it simple). The child pointers will be NULL when a certain child does not exist. You get to assume that your function will be passed the root of a correct (b, 2b − 1)-tree and a key to search for. Your analysis in big-O/Ω/Θ notation should tell us how long the lookup function takes, as a function of n (the number of keys in the tree) and b. (a) Give us your implementation of lookup. #define b 10000 // Your code should work also if someone gives b another value struct BTreeNode { int c; // number of children this node actually has. // Will always be between b and 2b-1. int k [2b-2]; // the sorted array of keys in the node. BTreeNode *child[2b-1]; // the ordered array of children. }; bool lookup (BTreeNode root, int key) / This is the function you implement. It should return true if the key exists in the tree, and false otherwise. You may define helper functions if you want. */
- Assistant
- User
struct Node { does this also work as well int n; int key[MAX_KEYS]; Node* child[MAX_CHILDREN]; bool leaf; };
Node* BtreeSearch(Node* x, int k) { int i = 0; while (i < x->n && k > x->key[i]) { i++; } if (i < x->n && k == x->key[i]) { return x; } if (x->leaf) { return nullptr; } return BtreeSearch(x->child[i], k); }
- Assistant
- User
i want you to modify the variable in there so it fits with the program
- Assistant
- User
modify it to not use the isleaf() if (currentNode->isLeaf) { return nullptr; }
- Assistant
- User
You have a correctly implemented Max-Heap class (indices starting at 1), which provides the two following helper functions (in addition to insert, remove, peek): (a) trickleUp (int i) (David’s lecture) a.k.a. insert (int i) (Mark’s lecture) takes the element at position i and keeps swapping it with its parent (and grandparent etc.) until it is no larger than the parent at the time. (b) trickleDown (int i) (David’s lecture) a.k.a. heapify (int i) (Mark’s lecture) takes the element at position i and keeps swapping it with the larger of its children (and grandchildren etc.) until it is no smaller than both children. Suppose that you get an instance whose array elements are not in correct heap order, i.e., the heap property does not hold yet. You want to establish the correct arrangement, by using the two helper functions given above. Which of the following two alternatives do this correctly? Explain why they are correct or incorrect. For incorrect ones, give an example of an initial heap which is not correctly processed, and explain what happens when the incorrect variant is executed on it. Heap h; // Variant 1 for (int i = 1; i <= n; i ++) h.trickleUp (i); // Variant 2; for (int i = 1; i <= n; i ++) h.trickleDown (i);
- Assistant
- User
if either one must be correct, which one is closer to being correct
- Assistant
- User
shows the tree beforea nd after the swap
- Assistant