442_External Sorting

442_External Sorting - ExternalSorting WhySort?

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

View Full Document Right Arrow Icon
External Sorting
Background image of page 1

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

View Full DocumentRight Arrow Icon
Why Sort? A classic problem in computer science! Data requested in sorted order  e.g., find students in increasing  gpa  order Sorting is first step in  bulk loading  B+ tree index. Sorting useful for eliminating  duplicate copies  in a  collection of records (Why?) Sort-merge  join algorithm involves sorting. Problem: sort 1Gb of data with 1Mb of RAM.
Background image of page 2
2-Way Sort: Requires 3 Buffers Pass 1: Read a page, sort it, write it. only one buffer page is used Pass 2, 3, …, etc.:  three buffer pages used. Main memory buffers INPUT 1 INPUT 2 OUTPUT Disk Disk
Background image of page 3

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

View Full DocumentRight Arrow Icon
Two-Way External Merge Sort Each pass we read + write  each page in file. N pages in the file => the  number of passes So toal cost is:   Idea:    Divide and conquer:  sort subfiles and merge   = + log 2 1 N   ( 29 2 1 2 N N log + Input file 1-page runs 2-page runs 4-page runs 8-page runs PASS 0 PASS 1 PASS 2 PASS 3 9 3,4 6,2 9,4 8,7 5,6 3,1 2 3,4 5,6 2,6 4,9 7,8 1,3 2 2,3 4,6 4,7 8,9 1,3 5,6 2 2,3 4,4 6,7 8,9 1,2 3,5 6 1,2 2,3 3,4 4,5 6,6 7,8
Background image of page 4
General External Merge Sort
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/24/2011 for the course CS 442 taught by Professor Mlittman during the Fall '08 term at Rutgers.

Page1 / 14

442_External Sorting - ExternalSorting WhySort?

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

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