80 likes | 92 Views
Data Organization. Example 1: A simple text editor Store the text buffer as a list of lines. How would we implement the UNDO operation? Example 2: Parsing How does the compiler check the syntax? Example 3: Bracket matching Example 4: Runtime storage organization. Stack ADT. Data
E N D
Data Organization • Example 1: A simple text editor • Store the text buffer as a list of lines. • How would we implement the UNDO operation? • Example 2: Parsing • How does the compiler check the syntax? • Example 3: Bracket matching • Example 4: Runtime storage organization
Stack ADT • Data • A collection of homogeneous elements arranged in a sequence. • LIFO structure • Operations • Push • Pop • Top • isEmpty
Stack ADT • Implementation • Contiguous memory • Which end of the array is the top of the stack? • Linked memory • Which end of the "list" is the top of the stack?
Data Organization • Example 1: Discrete Event Simulation • Bank waiting line • Each new customer joins the end of the line • The next customer to walk up to a teller is the one at the front of the line • Run a sim to process arrival and departure events and collect information about waiting times. • Example 2: Process scheduling • Round-robin
Queue ADT • Data • A collection of homogeneous elements arranged in a sequence. • FIFO structure • Operations • Enqueue • Dequeue • Front • isEmpty
Queue ADT • Implementation • Contiguous memory • Which end of the array is the front/end? • Linked memory • Which end of the "list" is the front?
A different kind of queue • Queues are used to model waiting lines. • In some situations (e.g. aircraft boarding), certain elements in a line (e.g. first class passengers) have a higher priority: the FIFO model is not strictly applicable. • We need a data structure similar to a queue, where elements are ordered, not based on arrival, but based on some priority.
Priority queue I • Data • A collection of elements, where each element is assigned a priority • Efficient extraction of the highest-priority element should be supported. • Operations • Enqueue • Dequeue • GetMax • Implementation • How would you modify your regular queue implementation?