0% found this document useful (0 votes)
51 views11 pages

Mem 9

1) Linked data structures like lists, stacks, trees and graphs use connections between nodes to represent relationships and model complex real-world scenarios. Binary search trees store data with nodes connected in a left/right ordering. 2) This document discusses serialization of linked data structures by allocating nodes sequentially in memory segments called an "arena" and adjusting pointers to be relative offsets within segments. 3) Serialization allows the data structure to be easily moved, transmitted or stored by treating the contiguous segments as a single unit, rather than relying on absolute memory addresses. Pointers become (segment, offset) pairs, and examples show building and relativizing a binary search tree in an arena.

Uploaded by

api-3738981
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views11 pages

Mem 9

1) Linked data structures like lists, stacks, trees and graphs use connections between nodes to represent relationships and model complex real-world scenarios. Binary search trees store data with nodes connected in a left/right ordering. 2) This document discusses serialization of linked data structures by allocating nodes sequentially in memory segments called an "arena" and adjusting pointers to be relative offsets within segments. 3) Serialization allows the data structure to be easily moved, transmitted or stored by treating the contiguous segments as a single unit, rather than relying on absolute memory addresses. Pointers become (segment, offset) pairs, and examples show building and relativizing a binary search tree in an arena.

Uploaded by

api-3738981
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Linked Data Structures:

Linked data structures - versatile data structures to model complex


real world situations and entities. List, stacks, trees, graphs etc. just
to mention some.
Consider a simple binary search tree for characters:
Analyze chapter9_1 program:

Average time complexity to search for an item is O(n log n)


Organization: Binary tree, left child has value less than the parent,
the right child has value greater than the parent.

Chapter 9, Slide 1
E

B K NULL

A NULL NULL
D NULL NULL
J NULL NULL

Depth first traversal will produce alphabetically ordered sequence:


ABDEJK

Chapter 9, Slide 2
The nature of “links” -- usually pointers, but any reference will do:

Analyze chapter9_2 program:

The references are array indexes (arrays are modeled on memory!).


This will work fine for a tree with up to 100 nodes. A natural way to
serialize a binary tree.
Not necessarily are linked data structures created on the heap only:

Analyze chapter9_3 program that is a recursive descent parser for a


list of characters separated by commas and builds a binary search
tree on the stack.

Though, it is not very practical.


Most commonly, linked data structures are linked by pointers and are
build on the heap.
Chapter 9, Slide 3
Pointer-based linked data structures are “flexible”, which is mostly
good, however it is bad for “moving” the structure elsewhere in
memory, or “transmitting” it over a communication channel, or
“recording” it to auxiliary memory.
• compaction: we say that a linked data structure is compacted if it
occupies a contiguous segment of memory and all pointers (addresses)
are relative to the beginning of that segment.
• serialization: we say that a linked data structure is serialized if it
occupies several contiguous segments of memory and all pointers
(addresses) are relative to the beginning of that segment where the
pointer is stored.
Thus compaction is the extreme form of serialization. A serialized
structure can easily by “moved” in memory just by “moving” the
whole segment(s), “transmitted” byte by byte over a communication
channel, or “recorded” to auxiliary memory and later restored.
Chapter 9, Slide 4
Illustration of serialization+allocation from arena: chapter9_4
program.

The “relativized” addresses are a pair of short integers, the first is


segment+1 and the second is offset. Let us now visualize the arena
after each stage of the process.
First “building” the tree:
root

d NULL NULL
address
4398592

Chapter 9, Slide 5
root

d NULL c NULL NULL


address
4398592

root

address
4398592

d c NULL NULL

e NULL NULL
address
4399604

Chapter 9, Slide 6
root

address
4398592
d c NULL

e NULL NULL a NULL NULL


address
4399604
root

address
4398592
d c NULL

e NULL NULL a NULL


address
4399604

b NULL NULL
address
4399648 Chapter 9, Slide 7
The tree is build, now we start the relativization process:

root
(1,0)

d (1,12) (2,0) c (2,12) (0,0)


address
4398592

e (0,0) (0,0) a (0,0) (3,0)


address
4399604

b (0,0) (0,0)
address
4399648

Chapter 9, Slide 8
root
(1,0)

d (1,12) (2,0) c (2,12) (0,0)


address
8904304

e (0,0) (0,0) a (0,0) (3,0)


address
8905200

b (0,0) (0,0)
address
8905284

We deliberately designed the structure/class NODE so that it has


size of 12 bytes, but 3 bytes are wasted on padding:

a NULL NULL

Chapter 9, Slide 9
We can compact the nodes with no space wasted:

a NULL NULL

But then we cannot use p->lch or p->rch, we must have our


custom-made access functions: analyze chapter9_5 program.

croot

b NULL NULL a NULL c NULL e NULL NULL d

Chapter 9, Slide 10
After relativization:
croot
37

b 0 0 a 0 1 c 10 0 e 0 0 d 19 28
29
1 2 6 10 11 15 19 20 24 33 37 38 42
28

End of slides for chapter 9

Chapter 9, Slide 11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy