Quiz 2
Registry Synced

22 - File Organization

355 words
2 min read

Reading compass

Now · 🎯 Learning Objectives

22 - File Organization

🎯 Learning Objectives

After reading this topic, you will be able to:
  • Compare fixed-length and variable-length record storage
  • Explain slotted page organization
  • Describe heap, sequential, and hash file organizations
  • Understand data structure operations complexity

📖 Core Content

22.1 File Organization Methods

OrganizationDescriptionBest For
HeapRecords stored wherever space availableBulk loading, full scans
SequentialRecords ordered by search keyRange queries, sorted output
HashingRecords distributed by hash functionEquality lookups

22.2 Fixed-Length Records

Each record has the same length. Simple to implement:
  • Record ii starts at offset i×recordlengthi \times record_length
  • Deleting a record: move the last record to fill the gap (or mark as deleted)

22.3 Variable-Length Records

Records have different lengths (e.g., VARCHAR attributes). Two approaches:

Slotted Page Structure

(Diagram) The header contains:
  • Number of record entries
  • Array of (offset, length) for each record
  • Pointer to end of free space Advantages: Supports variable-length records, easy to add/delete records, no external fragmentation.

22.4 Data Structures Review

StructureSearch (Avg)Insert (Avg)Delete (Avg)
ArrayO(n)O(n)O(n)
Linked ListO(n)O(1)O(1)
StackO(n)O(1)O(1)
QueueO(n)O(1)O(1)
BST (balanced)O(log n)O(log n)O(log n)
Hash TableO(1)O(1)O(1)
B-TreeO(log n)O(log n)O(log n)

22.5 Heap File Organization

  • Records stored in any available space
  • No particular ordering
  • Insert: Append to last page (fast)
  • Search: Must scan all pages (slow for large files)
  • Best for: Tables where you always read all rows

📝 Practice Questions

Q1. What is a slotted page? Why is it used?

Answer
A slotted page divides a disk block into slots that can hold variable-length records. The page header contains an array of (offset, length) pairs for each record. Used because DBMS records have variable length (VARCHAR fields), and slotted pages minimize wasted space.

Q2. Compare heap and sequential file organization.

Answer
  • Heap: Unordered; fast inserts, slow searches
  • Sequential: Ordered by key; fast range queries and sorted output, slower inserts (need to maintain order)

🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.