hw3s - Cs445 - Homework #3 Augmented Data Structures,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Cs445 — Homework #3 Augmented Data Structures, Graphs, Prim algorithms and Random variables Due: 3/22/2005 during class meeting. All questions are worth 13 points, excluding the bonus question that is worth 20 points. 1. Suggest a data structure that supports the following operations on the grades that a (single) student at the university receives. Assume that the total number n of exams that the student might take is large. The data structure should support the following operations: (a) insert ( exam date,exam grade ). This operation informs the data structure that the student received at date exam date the grade exam grade . (b) average ( date 1 , date 2 ). As a response to this operation the data structure should answer what is the average of all grades that are received between the dates date 1 and date 2 . The time per operation should be O (log n ), where n is the total number of exam taken. Hint — use search trees or SkipList, and maintain extra information in each cell of the structure. Answer: We can use an augmented AVL tree, augmented Red-Black tree, or an augmented SkipList . Each node contains a field “total” which holds the sum of the grades in the sub-tree for which it is the root and another field “number” that holds the number of nodes in the sub-tree. Modification to insert : Add the ”grade” to be inserted, to the total field of each node that we traverse during insertion. Modification to delete : Subtract the ”grade” to be deleted from the total field of each node traversed during deletion. Average : Search date 1 in the tree. Maintain a variable total 1 initialized to 0. During traversal, to find date 1 , if next node is left child, then total 1 remains unchanged. If next node is right child, add “total” value of the left node to total 1 , and the grade of the exam store at current node. If date 1 happens to be stored at a node v of the tree, also add total 1 the value of “total” stored at the left child of v . Repeat the same for date 2 and store total grade in total 2 . Similarly define (and compute) number 1 and number 2 . The average ( date 1 , date 2 ) = ( total 1 - total 2 ) / ( number 1 - number 2 ) 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2. Assume that the graph G ( V,E ) is given, where the weights of each edge is an integer between 1 and 10. Show that in this case,prim’s algorithm can be implemented for this graph in time O ( | E | + | V | ). Hint — suggest a data structure that replaces the priority queue, and analyze the running time. Answer:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

hw3s - Cs445 - Homework #3 Augmented Data Structures,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online