![數(shù)據(jù)結構教學課件:chapter8_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/28/3583a995-2d9a-41ff-8194-43adeab288dc/3583a995-2d9a-41ff-8194-43adeab288dc1.gif)
![數(shù)據(jù)結構教學課件:chapter8_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/28/3583a995-2d9a-41ff-8194-43adeab288dc/3583a995-2d9a-41ff-8194-43adeab288dc2.gif)
![數(shù)據(jù)結構教學課件:chapter8_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/28/3583a995-2d9a-41ff-8194-43adeab288dc/3583a995-2d9a-41ff-8194-43adeab288dc3.gif)
![數(shù)據(jù)結構教學課件:chapter8_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/28/3583a995-2d9a-41ff-8194-43adeab288dc/3583a995-2d9a-41ff-8194-43adeab288dc4.gif)
![數(shù)據(jù)結構教學課件:chapter8_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-4/28/3583a995-2d9a-41ff-8194-43adeab288dc/3583a995-2d9a-41ff-8194-43adeab288dc5.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、120:452Primary storage: Main memory (RAM)Secondary Storage: Peripheral devicesDisk drivesTape drives20:453RAM is usually volatile.RAM is about 1/4 million times faster than disk.MediumEarly 1996 Mid 1997 Early 2000RAM$45.007.001.50Disk1Floppy0.500.360.25Tape0.030.010.00120:454Minimize the
2、 number of disk accesses!1. Arrange information so that you get what you want with few disk accesses.2. Arrange information to minimize future disk accesses.An organization for data on disk is often called a file structure.Disk-based space/time tradeoff: Compress information to save processing time
3、by reducing disk accesses.20:45520:456A sector is the basic unit of I/O.Interleaving factor: Physical distance between logically adjacent sectors on a track.20:457Locality of Reference: When record is read from disk, next request is likely to come from near the same place in the file.Cluster: Smalle
4、st unit of file allocation, usually several sectors.Extent: A group of physically contiguous clusters.Internal fragmentation: Wasted space within sector if record size does not match sector size; wasted space within cluster if file size is not a multiple of cluster size.Sector headers: Contains the
5、sector address and an error detection code for the contents of that sector. See P267 Figure 8.5.20:458Seek time: Time for I/O head to reach desired track. Largely determined by distance between I/O head and desired track.Track-to-track time: Minimum time to move from one track to an adjacent track.A
6、verage Seek time: Average time to reach a track for random access.20:459Rotational Delay or Latency: Time for data to rotate under I/O head.One half of a rotation on average.At 7200 rpm, this is 8.3/2 = 4.2ms.Transfer time: Time for data to move under the I/O head.At 7200 rpm: Number of sectors read
7、/Number of sectors per track * 8.3ms.20:451016.8 GB disk on 10 platters = 1.68GB/platter13,085 tracks/platter256 sectors/track512 bytes/sectorTrack-to-track seek time: 2.2 msAverage seek time: 9.5ms8 sector/clusters =4KB, 32 clusters/track.Interleaving factor of 3.5400RPM20:4511Read a 1MB file divid
8、ed into 2048 records of 512 bytes (1 sector) each.Assume all records are on 8 contiguous tracks.First track: 9.5 + 11.1/2 + 3 x 11.1 = 48.4 msRemaining 7 tracks: 2.2 + 11.1/2 + 3 x 11.1 = 41.1 ms.Total: 48.4 + 7 * 41.1 = 335.7ms20:4512Read a 1MB file divided into 2048 records of 512 bytes (1 sector)
9、 each.Assume all file clusters are randomly spread across the disk.256 clusters. Cluster read time is (3 x 8)/256 of a rotation for about 1 ms.256(9.5 + 11.1/2 + (3 x 8)/256) is about 4119.2 ms. 20:4513Read time for one track:9.5 + 11.1/2 + 3 x 11.1 = 48.4ms.Read time for one sector:9.5 + 11.1/2 + (
10、1/256)11.1 = 15.1ms.Read time for one byte:9.5 + 11.1/2 = 15.05 ms.Nearly all disk drives read/write one sector at every I/O access.Also referred to as a page.20:4514The information in a sector is stored in a buffer or cache.If the next I/O access is to the same buffer, then no need to go to disk.Th
11、ere are usually one or more input buffers and one or more output buffers.20:4515A series of buffers used by an application to cache disk data is called a buffer pool.Virtual memory uses a buffer pool to imitate greater RAM memory by actually storing information on disk and “swapping” between disk an
12、d RAM.20:451620:4517Which buffer should be replaced when new data must be read?First-in, First-out: Use the first one on the queue.Least Frequently Used (LFU): Count buffer accesses, reuse the least used.Least Recently used (LRU): Keep buffers on a linked list. When buffer is accessed, bring it to f
13、ront. Reuse the one at end.20:4518class BufferPool / (1) Message Passingpublic: virtual void insert(void* space, int sz, int pos) = 0; virtual void getbytes(void* space, int sz, int pos) = 0;class BufferPool / (2) Buffer Passingpublic: virtual void* getblock(int block) = 0; virtual void dirtyblock(i
14、nt block) = 0; virtual int blocksize() = 0;20:4519Problem: Sorting data sets too large to fit into main memory.Assume data are stored on disk drive.To sort, portions of the data must be brought into main memory, processed, and returned to disk.An external sort should minimize disk accesses.20:4520Se
15、condary memory is divided into equal-sized blocks (512, 1024, etc)A basic I/O operation transfers the contents of one disk block to/from main memory.Under certain circumstances, reading blocks of a file in sequential order is more efficient. Primary goal is to minimize I/O operations.Assume only one
16、 disk drive is available.20:4521Often, records are large, keys are small.Ex: Payroll entries keyed on ID numberApproach 1: Read in entire records, sort them, then write them out again.Approach 2: Read only the key values, store with each key the location on disk of its associated record.After keys a
17、re sorted the records can be read and rewritten in sorted order.20:4522Quicksort requires random access to the entire set of records.Better: Modified Mergesort algorithm.Process n elements in Q(log n) passes.A group of sorted records is called a run.20:4523Split the file into two run files.Read in a
18、 block from each run file.Take first record from each block, output them in sorted order.Take next record from each block, output them to a second file in sorted order.Repeat until finished, alternating between output files. Read new input blocks as needed.Repeat steps 2-5, except this time input fi
19、les have runs of two sorted records that are merged together.Each pass through the files provides larger runs.20:452420:4525How can we reduce the number of Mergesort passes? Not use Mergesort on small runs, read in a block of data and sort it in memory, and then output it as a single sorted run. (Se
20、e example in page 280)In general, external sorting consists of two phases:Break the files into large initial runsMerge the runs together to form a single sorted run file.20:4526General approaches:Read as much of the data of file into memory as possible.Perform an in-memory sort such as Quicksort or
21、Heapsort.Output this group of sorted records as a single run.20:4527A basic I/O operation is read/write a block. Replacement selection sort is a technology of generating a run as larger as possible based on the basic I/O operations.It is a slight variation on Heapsort algorithm.Break available memor
22、y into an array for the heap, an input buffer, and an output buffer.20:4528 1) Fill the array from disk. Set LAST=M-1; 2) Build a min-heap; 3) Repeat until the array is empty: a) Send the record with the minimum key value (the root) to the output buffer. b) Let R be the next record in the input buff
23、er. If Rs key value is greater than the key value just output, thenReplace the root with this keyelseReplace the root with the record in array position LAST, and add the next record in the file to a new heap (actually, stick it at the end of the array). c) Sift down the root to recorder the heap.20:
24、4529See Figure 8.9 in page 28420:4530 1) Only the record whose key value is greater than the last key value output can be added to the heap. 2) The record with smaller key value can not be output as a part of the run, but is stored as the data to be handled for the next run; -Heap becomes smaller an
25、d smaller, and the discarded heap space is used to store the records not be output. 3) If the size of available RAM used by array is M, then the smallest run generated by Replacement selection sort is M and the average run is 2M. (Proven process see “Snowplow analogy”)20:4531Simple mergesort: Place runs into two files.Merge the first two ru
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 壓力管道安裝申請書
- 物業(yè)公司轉正申請書
- 骨干教師申請書
- 2025至2030年中國無堿玻纖粗紗數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國塑料包裝品數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年網(wǎng)絡提花鉤編機項目投資價值分析報告
- 2025至2030年紫甘藍項目投資價值分析報告
- 特種養(yǎng)殖申請書
- 2025至2030年中國PP卡紙文件夾數(shù)據(jù)監(jiān)測研究報告
- 輔導員申請書
- 血型與輸血檢驗-臨床輸血(臨床檢驗課件)
- 良性前列腺增生癥住院醫(yī)師規(guī)范化培訓教學查房
- 高中數(shù)學知識點大全
- 人機料法環(huán)測5M1E分析法
- 游泳社會指導員專項理論考試復習題庫匯總(附答案)
- 《簡單教數(shù)學》讀書-分享-
- 口腔頜面外科學 功能性外科
- 脊椎動物學知識點歸納各綱特征
- GB/T 27476.5-2014檢測實驗室安全第5部分:化學因素
- 一級醫(yī)院基本標準1
- 霍亂病例分析課件
評論
0/150
提交評論