PODDAR_RANADEEP_CS430_HW2.pdf

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
NAME:RANADEEP PODDAR CWID:A20355112 SUBJECT: CS430
Image of page 1

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

View Full Document Right Arrow Icon
Problem 1 Assume the priority queue also must support the update DELETE(A,i), where i gives you the location in the data strucure where element i is located. In a binary heap, that would be A [ i ]. Write pseudocode to achieve DELETE(A,i) in O (log n ) time for binary heaps, where n is the size of the heap. Solution: 1, Delete a node from the array (this creates a vacant node and the tree is not complete) 2. Replace the deletion node with the fartest right node on the lowest level of the Binary Tree (To complete the tree) 3. Heapify (fix the heap): Algorithm for Max Heapify Procedure: MaxHeapify(A, n) 1. l left(n) 2. r right(n) 3. if l heap-size[A] and A[l] > A[n] 4. then largest l 5. else largest i 6. if r heap-size[A] and A[r] > A[largest] 7. then largest r 8. if largest n 9. then exchange A[n] A[largest] 10. MaxHeapify(A, largest) Running time( delete(n) ) = Running time heap delete in heap with n node = height of a heap with n nodes height of the heap containing n nodes =log(n + 1) Running time of delete into a heap of n nodes = O(log(n)) Complexity of deletion: O(logN) in the worst case.
Image of page 2
Problem 2 Using only the definition of a binary search tree, show that if a node in a binary search tree has two children, then its successor has no left child and then its predecessor has no right child.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern