




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Translating SQL queries into relational algebra, Basic algorithms - Sorting: internal sorting and external sorting - Implementing the SELECT operation - Implementing the JOIN operation - Implementing the Project operation - Other operations • Heuristics for query optimization, What is a heap? • MaxHeap and Maintenance of MaxHeaps - MaxHeapify - BuildMaxHeap • Heapsort - Algorithm - Heapsort analysis
Typology: Study notes
1 / 122
This page cannot be seen from the preview
Don't miss anything!





























































































(Ch. 18, 3
rd
- Ch. 15, 4
th ed. 5
th ed., Ch. 19, 6
th
ed., Ch. 18, 19, 7
th ed.)
Scanning, Parsing, Validating
Query in a high-level language
Intermediate form of query
Query optimization
Execution plan
Query code generation
Code to execute the query
Runtime database processor
Result of query
SELECT MAX(SALARY)
FROM EMPLOYEE
WHERE DNO = 5
SELECT LNAME, FNAME
FROM EMPLOYEE
WHERE SALARY > c
MAX SALARY
DNO=
LNAME FNAME
SALARY>C
sorting numbers
Input n numbers. Sort them such that the numbers are
ordered increasingly.
3 9 1 6 5 4 8 2 10 7
1 2 3 4 5 9 7 8 9 10
main idea:
1st step: 3 9 1 6 5 4 8 2 10 7
2nd step: 1 9 3 6 5 4 8 2 10 7
1 2 3 6 5 4 8 9 10 7
… ...
swap
swap
Heapsort
insertion sort.
is O ( n lg n ).
place.
during the execution of an algorithm.
Data Structure Binary Heap
1
(^2 )
4 5 6 7
(^8 9 )
1 2 3 4 5 6 7 8 9 10
Searching the tree in breadth-first
fashion, we will get the array.
Last row filled from left to right.
Heap Property (Max and Min)
that node is at most that of its parent: A [ parent [ i ]] A [ i ]
stored at the subtree’s root.
that node is at least that of its parent: A [ parent [ i ]] A[ i ]
stored at the subtree’s root
1 2 3 4 5 6 7 8 9 10
1
(^2 )
4 5 6 7
(^8 9 )
exchange
Heaps in Sorting
(i) Convert the given array of size n to a max-heap ( BuildMaxHeap )
(ii) Swap the first and last elements of the array.
belongs.
locations.
heap.
the array remains a max-heap ( MaxHeapify )
MaxHeapify
but the root violates the max-heap
property.
with the larger of the values at its children.
heap.
heap property.
MaxHeapify – Example
MaxHeapify( A , 2)
14
1
2 3
4 5 6 7
8
9 10