Download presentation
Presentation is loading. Please wait.
1
Data structures
2
D1 Data structures The features, applications and implications of data types used in computer systems: stack queue array list. The use and application of data types in computer software. The use and implications of data types in computer hardware.
3
Representation of Data as Bit Patterns – Data Structures – Linked-list
A linked list is usually represented by the following diagram End Start Free Space Free End Data Address of next node Node
4
Representation of Data as Bit Patterns – Data Structures – Linked - list
The Free Space is the available memory that the linked-list can grow into Data can be added and removed from any point A node contains two pieces of information Left the data Right the address of the next node
5
Representation of Data as Bit Patterns – Data Structures – Linked - list
Adding and deleting from a linked-list involves changing the pointers to either incorporate a new node (adding) or redirecting to miss out an existing node (deleting) The new node will be added from the free space The deleted node will be added to the free space There are 3 possible positions that a node can be added or deleted Start of the list End of the list ‘Middle’ of the list
6
Representation of Data as Bit Patterns – Data Structures – Linked - list
If the start of the list is be changed the initial start value needs to be altered to point to the new node If the end of the list is to be changed the new last node needs to be altered so it represents the end of the list Middle nodes have no particular problems
7
Representation of Data as Bit Patterns – Data Structures – Linked – list
Given the following linked-list 1 B 2 F 3 M 4 End
8
Representation of Data as Bit Patterns – Data Structures – Linked – list
The data “K” is to be added to the list 1 B 2 F 3 M 4 End
9
Representation of Data as Bit Patterns – Data Structures – Linked – list
“K” is then added to the free space 1 B 2 F 3 M 4 End Free 5 K 6 7 End
10
Representation of Data as Bit Patterns – Data Structures – Linked – list
The appropriate pointers need moving 1 B 2 F 3 M 4 End Free 5 K 6 7 End
11
Representation of Data as Bit Patterns – Data Structures – Linked – list
Joining the previous node to “K” 1 B 2 F 5 M 4 End Free 5 K 6 7 End
12
Representation of Data as Bit Patterns – Data Structures – Linked – list
Linking “K” to the next node 1 B 2 F 5 M 4 End Free 5 K 3 7 End
13
Representation of Data as Bit Patterns – Data Structures – Linked – list
Recovering the free space 1 B 2 F 3 M 4 End Free 6 K 3 7 End
14
Representation of Data as Bit Patterns – Data Structures – Linked – list
The ‘new’ linked-list 1 B 2 F 5 M 4 End Free 6 K 3 7 End
15
Representation of Data as Bit Patterns – Data Structures – Linked – list
Given the following linked-list 1 B 2 F 3 M 4 End
16
Representation of Data as Bit Patterns – Data Structures – Linked – list
“F” is to be deleted from the list 1 B 2 F 3 M 4 End
17
Representation of Data as Bit Patterns – Data Structures – Linked – list
“F” should be added to the free-space 1 B 2 F 3 M 4 End Free 5 6 7 End
18
Representation of Data as Bit Patterns – Data Structures – Linked – list
“Redirecting the pointers 1 B 2 F 3 M 4 End Free 5 6 7 End
19
Representation of Data as Bit Patterns – Data Structures – Linked – list
Redirecting around “F” 1 B 3 F 3 M 4 End Free 5 6 7 End
20
Representation of Data as Bit Patterns – Data Structures – Linked – list
Adding “F” to the free-space 1 B 3 F 3 M 4 End Free 2 6 7 End
21
Representation of Data as Bit Patterns – Data Structures – Linked – list
Adding “F” to the free-space 1 B 3 F 5 M 4 End Free 2 6 7 End
22
Representation of Data as Bit Patterns – Data Structures – Linked – list
The ‘new’ linked list 1 B 3 F 5 M 4 End Free 2 6 7 End
23
Representation of Data as Bit Patterns – Data Structures – Linked - list
Uses for a linked-list are any situation that would require data to be inserted and deleted at any point – hence retaining the original order of the list
24
Stack A Stack is a Last In, First Out (LIFO) data structure (or FILO)
Items can be added ‘PUSHED’ onto the stack. Items can be removed ‘POPPED’ from the stack It is a dynamic structure as the size of the stack grows depending on how many items are on it. It is controlled by ONE pointer
25
Stacks [6] [5] [4] [3] [2] [1] Katie Millie Joe
Items can be pushed (add), Its can be popped (remove) Can only be added to the top of the Stack maxStackSize = 6 top =3
26
Stacks
27
Push/Pop Pseudocode Procedure Push If Top = MaxStackSize Then Write ‘Stack is full’ Else Add 1 to Top Stack[Top] := NewItem EndIf EndProc Procedure Pop If Top = 0 Then Write ‘Stack is empty’ Else PoppedItem := Stack[Top] Subtract 1 from Top EndIf EndProc
28
Uses of Stacks To store return addresses, parameters, and register contents when subroutines are called When sub routine is called, the return address is pushed onto the stack, until the sub has finished execution where it is then popped off. Undo and Redo functions Reverse Polish Notation
29
Queues
30
Queues A Queue is a First In, First Out (FIFO) data structure (or LILO) Data joins the queue at the rear. Data leaves the queue from the front It is a dynamic data structure. It is controlled by TWO pointers No data is added to a full queue. No data can be removed from an empty queue
31
Queue Declarations Frontpointer position of the first item
Rearpointer position of the last item Max the maximum number allowed Numberinqueue number currently in the queue
32
Queues Fred Jack Matt Ben Front Rear queueSize=4
Add a new item (to the rear) Remove an item (from the front)
33
Uses of Queue Holding jobs waiting to be processed
Spooling output to a disk prior to printing Both having the idea of dealing with tasks in the ‘first come, first served’ manner. It is the ‘fair’ approach.
34
STACKS AND QUEUES- RESEARCH
EXPLAIN WHAT A STACK IS EXPLAIN WHAT A QUEUE IS COMPUTER APPLICATIONS STACKS COULD BE USED FOR COMPUTER APPLICATIONS QUEUES COULD BE USED FOR LABELED DIAGRAM OF STACK LABELED DIAGRAM OF QUEUE
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.