SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Advanced Data
Structures:
Linked Allocation
Sub code: 12CSE102 for Mtech CSE
Hemanth Kumar G,
Assistant Professor,
Department of CSE, NMAMIT, Nitte
http://hemanthglabs.wordpress.in
http://veda-vijnana.blogspot.in
Linked Allocation
Linked vs Sequential Allocation
• Linked allocation
o Additional mem space for links. May be a dominating factor!
o Info in a node doesn’t take up a whole word.
• So already there is a space for link field.
o An app may combine several items into one node
• So only one link for several items of info.
o Implicit gain in storage as tables can overlap, sharing common parts.
• Sequential allocation
o If large no. of mem locs are left vacant, then only it is useful.
Linked vs Sequential Allocation
• Linked allocation
o Easy to delete an item from within a linked list.
o Easy to insert an item into the midst of a list.
o References to random parts of the linked list is slow.
o To gain access to the kth item in the list, we need k iterations to march down
to the right place.
• Sequential allocation
o Deletion requires moving a large part of the list up into different locations.
o Inserting an item into the midst will be extremely time consuming in a long
sequential table.
o References to random parts of the list is faster in the sequential case.
o To gain access to the kth item in the list, takes a fixed time.
Linked vs Sequential Allocation
• Linked allocation
o Easier to join two lists together, or to break one apart into two that will grow
independently.
o Lends itself immediately to more intricate structures like
• variable-size lists
• Any nod of the list may be a starting point for another list
• Nodes may simultaneously linked together in several orders corresponding
to different lists, etc.,
o If the elements of a linked list belong to different pages in a bulk memory, the
memory accesses might take significantly longer.
• Sequential allocation
o Simple operations, like proceeding sequentially through a list, are slightly faster.
Theory of Linked Lists
• Node has one word & broken into 2 fields:
• There must be some mechanism to find empty
space available for new node:
o “list of available space” ---- “AVAIL list (stack)”
o Avail refers to the top element of this list.
• If we want to set link variable X to the address of a
new node, and to reserve that node for future use:
o X ← AVAIL, AVAIL ← LINK (AVAIL) (4)
Operations on Linked List
• When a node is deleted and no longer needed, process
(4) can be reversed:
Link (X)  AVAIL, AVAIL  X. (5)
• This operation puts the node addressed by X back onto
the list of raw material; we denote (5) by “AVAIL <= X”.
• Setting up AVAIL stack:
a) linking together all nodes that are to be used for linked mem,
b) setting AVAIL to the address of the first of these nodes, and
c) Making the last node link to Λ
• The set of all nodes that can be allocated is called the
storage pool.
Handling AVAIL Stack (Technique-1)
• Check (4) if all available mem space has been
taken:
o If AVAIL = Λ, then OVERFLOW;
otherwise X ← AVAIL, AVAIL ← LINK (AVAIL) (6)
• Check always for OVERFLOW:
o terminate with regrets or
o Go to Garbage collection routine that attempts to find more
available space.
Handling AVAIL Stack (Technique-2)
• We often do not know in advance how much mem
space should be used for the storage pool.
• There may be a sequential table of var-size that wants to
coexist in mem with linked tables;
o In such a case we do not want the linked mem area to take any more space
than is absolutely necessary.
• L0 = beginning of ascending mem locs
• SEQMIN = current lower bound of the sequential table.
• If we want to place the linked mem area in Li < SEQMIN,
then we can proceed as follows, using a new var
POOLMAX.
Special recovery procedure for Overflow
Address Sequential Table Pointers
L0 + 5c SEQ Node 3
L0 + 4c SEQ Node 2
L0 + 3c SEQ Node 1  SEQMIN
L0 + 2c AVAIL Node 3  POOLMAX
L0 + c AVAIL Node 2
L0 AVAIL Node 1
Special recovery procedure for Overflow
• Keeps storage pool as small as possible.
• Can be applied when all lists occupy the storage
pool area.
• It avoids time consuming operation of initially linking
all available cells together.
• Facilitates debugging.
• You can put sequential list on the bottom & the
pool on the top:
o POOLMIN & SEQMAX
Common list operations
Insertion Operation – (8)
Deletion Operation – (9)
17 cycles, but
12 cycles in
sequential
table
(overflow is
longer)
Cyclic permutation in list operations
• In the insertion operation let P be the value of AVAIL before
the insertion; if P ≠ Λ, we find that after operation
Insertion & Deletion in Lists
• Insertion of 21/2 would have been done by using (8) with
T=LINK(LINK(FIRST))
• Linked allocation also applies to Queues.
Conditions in List design
• List empty condition
• Programming Error:
1. Failure to handle empty lists properly
Soln:- Examine the boundary conditions carefully.
2. Forget about changing some of the links when a structure
is being manipulated.
Soln:- Draw “before & after” diagrams & compare them, to
see which links must change.
Conditions applied on Q design
Before Insertion:-
Insert @ R:-
After Insertion:-
Boundary situation when the Q is empty: Fig (15) shows
situation after insertion. Situation before insertion is yet
to be determined
Queue Deletion Operation
• Check boundary conditions properly
• Basic operations – one way to do the things, there
will be multiple solutions to a problem.
• Abstract discussions  Practical examples.
Case Study
• Network problems. PERT Charts, linguistics.
• Problems involving ”Partial Ordering”.
• A partial ordering of a set S is a relation between
the objects of S denoted by , satisfying the
following properties for any objects x, y, and z in S:
Case Study
Exercise
GettinG Bored..? Let’s Have
An Activity On Relations..
• I want 9 students to volunteer on the podium and pick the announced card.
• The card(s) you have, will be your relative(s).
• When I ask that anybody have relative- ‘k’ do the following:
• Lift your hand if you have that relative’s card.
• Go & increment the COUNT node on the blackboard to prove your presence in the
class.
• If you have a relative, go & create nodes on the board for each relative, linking from
your node.
• Fill your relative’s number on the SUC field on the board.
• If nobody has a relative card, he/she will become independent, fills the SUC filed if
he/she will have any relative & walks out of the group to create new party ;)
• Based on the entries on the board rearrange yourselves based on SUC, NEXT &
COUNT fields.
Case Study: Topological Sorting
• S is a finite set & we work inside a computer.
• (II) => there are no closed loops in the diagram.
• In Fig.6, 4  1 violates partial ordering
Case Study: Topological Sorting
• Embed the partial order in a linear order:
o Linear sequence: a1a2…. an : whenever
o Boxes are to be rearranged into a line so that all arrows go towards right.
o May not be possible in all the cases. E.g. No reordering In case of loops.
• Algorithm gives useful operation & proves it is
possible for every partial ordering.
Applications of Topological Sorting
1. Large glossary of technical terms.
• if the definition of the word w1 depends
(in)directly on that of word w2.
o A partial ordering if there are no “circular” definitions.
• Goal: Find a way to arrange the words in the glossary so
that no term is used before it has been defined.
2. Writing programs to process the declarations in certain
assembly & compiler languages.
3. User’s manual describing a computer language
4. Writing textbook about Information Structures.
Topological Sorting
• Simple Algorithm:
1. Take an obj that is not preceded by any other obj in the ordering.
2. This obj may be placed first in the output.
3. Remove this obj from the set S;
• Resulting set is again partially ordered.
4. Repeat the process until the whole set has been sorted.
• Failure:- If there were a nonempty partially ordered set in
which every element was preceded by another.
• If every element is preceded by another, we could construct
an arbitrarily long sequence b1, b2, b3….. in which
• Since S is finite, we must have bj = bk for some j < k; =>
Contradicting (ii).
Implementation of Topological Sorting
• Ready to perform the actions like locate & remove the objects
from the set.
• Influenced by desired I/O characteristics:
o Alphabetic names for gigantic objects exceeding memory limit..??
• Let the objects to be sorted are numbered from 1 to n in any
order.
• The input of the program will be on tape unit 1:
o Each tape record contains 50 pairs of numbers
o Pair (j, k) = object j precedes object k.
o First pair is (0, n), n = # objs.
o Pair (0, 0) terminates the input.
o We shall assume that n + # relation pairs will fit comfortably in memory.
o Assume no input validation.
o O/P:- # objs in sorted order, followed by the number 0, on tape unit 2.
Hand trace of Topological data
• E.g.,
• Don’t give unnecessary more pairs.
o can be deduced from
o i.e., Give only the pairs corresponding to arrows on a diagram (fig 6.)
• Algorithm uses a sequential table X[1], X[2], …, X[n], and
each node X[k] has the form:
• Count[k] = # direct predecessors of object k
• Top[k] = Link to the beginning of the list of direct
successors of object k.
• Latter list contains entries in the format:
• SUC = direct successor of k, NEXT = next item of the list.
Computer Representation corresponding to relations (18)
• O/p the fields whose COUNT = 0. Then COUNT[Successors]--
• Trick:- Avoids searching for nodes with COUNT = 0.
• How? By a Queue containing those nodes. Links for this queue are kept in
COUNT field. Reusability!!
• Use QLINK[k] for COUNT[k] when that field is no longer being used for counting
Topological Sorting Flowchart
Algorithm T (Topological Sort)
• I/p: Pairs of relations with 1 ≤ j,k ≤ n.
• O/p: Set of n objects embedded in linear order.
• Internal tables:
o QLINK[0], COUNT[1] = QLINK[1], COUNT[2] = QLINK[2], …, COUNT[N] = QLINK[n];
o TOP[1], TOP[2], …, TOP[n];
o A storage pool with one node for each I/p relation and with SUC & NEXT fields;
o P, a link variable used to refer to the nodes in the storage pool;
o F & R, integer-valued variables of a queue whose links are in QLINK table;
o N, a variable that counts how many objects have yet to be output.
Algorithm T (Topological Sort)
Algorithm T (Topological Sort)
Characteristics of Algorithm T
• Nice interplay b/n Seql mem & linked mem techniques.
• Seql mem: X[1], …, X[n]; with COUNT[k] & TOP[k]
o References to “random” parts of this table in step T3.
• Linked mem: tables of “immediate successors”.
o No particular order in the I/p for these table entries.
• The Q of nodes waiting to be O/p is kept in the midst of the seql
table by linking the nodes together in O/p order.
o This linking is done by table index instead of by address;
• When front of the Q is X[k], we have F=k instead of F = Loc(X[k])
Analysis of Algorithm T
• By Kirchoff’s law Execn time ≈ c1m + c2n
o m = # I/p relations
o n = # Objects
o c1 & c2 = Constants
• Hard to imagine faster algorithm for this algorithm!
• Total running time: (32m + 24n + 7b + 2c + 16)u.
o a = # objects with no predecessor
o b = # tape records in I/p =
o c = # tape records in O/p =
Exercise
Item 5Item 4Item 3Item 2Λ Item 1 First
Programming Practices
• Develop the functions & a test driver for the following:
o Accepts a general list, traverses it, and returns the key of the node with the
minimum key value.
o Traverses a general list and deletes all nodes whose keys are negative.
o Traverses a general list and deletes all nodes that are after a node with a
negative key.
o Traverses a general list and deletes all nodes that are before a node with a
negative key.
o Search list for a given key & return the node number if it is present.
o Returns a pointer to the last node in a general list.
o Appends two general lists together.
o Appends a general list to itself.
o Inverts a general list.
Reference
“The Art of Computer Programming” – Volume 1, on
Fundamental Algorithms by Donald E. Knuth, Stanford
University, published by Pearson Education © 1997.

Weitere ähnliche Inhalte

Was ist angesagt?

Sejarah Proses Perumusan Pancasila
Sejarah Proses Perumusan PancasilaSejarah Proses Perumusan Pancasila
Sejarah Proses Perumusan Pancasilaveronicalenore14
 
Geostrategis dan ketahanan nasional
Geostrategis dan ketahanan nasionalGeostrategis dan ketahanan nasional
Geostrategis dan ketahanan nasionalWidiya Ocek
 
Politik Luar Negeri, Bebas Aktif Indonesia dan Lembaga Internasional (ASEAN, ...
Politik Luar Negeri, Bebas Aktif Indonesia dan Lembaga Internasional (ASEAN, ...Politik Luar Negeri, Bebas Aktif Indonesia dan Lembaga Internasional (ASEAN, ...
Politik Luar Negeri, Bebas Aktif Indonesia dan Lembaga Internasional (ASEAN, ...Alviony Charisa
 
Kewajiban warga negara dalam demokrasi
Kewajiban warga negara dalam demokrasiKewajiban warga negara dalam demokrasi
Kewajiban warga negara dalam demokrasiRacmat Ridho
 
Pancasila sebagai ideologi dan dasar negara
Pancasila sebagai ideologi dan dasar negaraPancasila sebagai ideologi dan dasar negara
Pancasila sebagai ideologi dan dasar negaraAnnisa Suci Priyanti
 
Resume Buku Ilmu Negara Karangan Soehino
Resume Buku Ilmu Negara Karangan SoehinoResume Buku Ilmu Negara Karangan Soehino
Resume Buku Ilmu Negara Karangan SoehinoSigit Budhiarto
 
Sistem Komputer Kelas 8
Sistem Komputer Kelas 8Sistem Komputer Kelas 8
Sistem Komputer Kelas 8Farichah Riha
 
Persatuan dan kesatuan bangsa indonesia dari masa ke masa
Persatuan dan kesatuan bangsa indonesia dari masa ke masaPersatuan dan kesatuan bangsa indonesia dari masa ke masa
Persatuan dan kesatuan bangsa indonesia dari masa ke masaafifahdhaniyah
 
Proses perumusan pancasila sebagai dasar negara indonesia
Proses perumusan pancasila sebagai dasar negara indonesiaProses perumusan pancasila sebagai dasar negara indonesia
Proses perumusan pancasila sebagai dasar negara indonesiaYsugeng Prihanto
 
Persatuan dan kesatuan bangsa indonesia dari masa ke masa
Persatuan dan kesatuan bangsa indonesia dari masa ke masaPersatuan dan kesatuan bangsa indonesia dari masa ke masa
Persatuan dan kesatuan bangsa indonesia dari masa ke masaRezaWahyuni5
 
BAB 1 menggali ide gagasan pendiri bangsa.pptx
BAB 1 menggali ide gagasan pendiri bangsa.pptxBAB 1 menggali ide gagasan pendiri bangsa.pptx
BAB 1 menggali ide gagasan pendiri bangsa.pptxChiiaaPunyaCerita
 
Ppt tentang Eksekutif Legislatif dan Yudikatif - ppkn
Ppt tentang Eksekutif Legislatif dan Yudikatif - ppknPpt tentang Eksekutif Legislatif dan Yudikatif - ppkn
Ppt tentang Eksekutif Legislatif dan Yudikatif - ppknIrfanHakim54
 
ancaman di bidang ideologi dan politik
ancaman di bidang ideologi dan politikancaman di bidang ideologi dan politik
ancaman di bidang ideologi dan politikNoname Noname
 
Menerapkan Berpikir Komputasional dan Praktik Lintas Bidang Muhammad Omar Adr...
Menerapkan Berpikir Komputasional dan Praktik Lintas Bidang Muhammad Omar Adr...Menerapkan Berpikir Komputasional dan Praktik Lintas Bidang Muhammad Omar Adr...
Menerapkan Berpikir Komputasional dan Praktik Lintas Bidang Muhammad Omar Adr...Muhammad Omar Adriansyah
 
Tabel perbandingan upaya AS dan Uni Soviet untuk Menguasai Dunia
Tabel perbandingan upaya AS dan Uni Soviet untuk Menguasai DuniaTabel perbandingan upaya AS dan Uni Soviet untuk Menguasai Dunia
Tabel perbandingan upaya AS dan Uni Soviet untuk Menguasai DuniaDwi Anita
 
ILMU NEGARA “PROSES TERJADINYA NEGARA SECARA PRIMER dan SEKUNDER”
ILMU NEGARA “PROSES TERJADINYA NEGARA SECARA PRIMER dan SEKUNDER”ILMU NEGARA “PROSES TERJADINYA NEGARA SECARA PRIMER dan SEKUNDER”
ILMU NEGARA “PROSES TERJADINYA NEGARA SECARA PRIMER dan SEKUNDER”Fenti Anita Sari
 
Perbandingan sistem pemilu di indonesia
Perbandingan sistem pemilu di indonesiaPerbandingan sistem pemilu di indonesia
Perbandingan sistem pemilu di indonesiaElection Commision
 
Sistem Politik Di Indonesia
Sistem Politik Di IndonesiaSistem Politik Di Indonesia
Sistem Politik Di Indonesiaomcivics
 

Was ist angesagt? (20)

Sejarah Proses Perumusan Pancasila
Sejarah Proses Perumusan PancasilaSejarah Proses Perumusan Pancasila
Sejarah Proses Perumusan Pancasila
 
Geostrategis dan ketahanan nasional
Geostrategis dan ketahanan nasionalGeostrategis dan ketahanan nasional
Geostrategis dan ketahanan nasional
 
Politik Luar Negeri, Bebas Aktif Indonesia dan Lembaga Internasional (ASEAN, ...
Politik Luar Negeri, Bebas Aktif Indonesia dan Lembaga Internasional (ASEAN, ...Politik Luar Negeri, Bebas Aktif Indonesia dan Lembaga Internasional (ASEAN, ...
Politik Luar Negeri, Bebas Aktif Indonesia dan Lembaga Internasional (ASEAN, ...
 
Kewajiban warga negara dalam demokrasi
Kewajiban warga negara dalam demokrasiKewajiban warga negara dalam demokrasi
Kewajiban warga negara dalam demokrasi
 
Sejarah Kelas 12
Sejarah Kelas 12Sejarah Kelas 12
Sejarah Kelas 12
 
Pancasila sebagai ideologi dan dasar negara
Pancasila sebagai ideologi dan dasar negaraPancasila sebagai ideologi dan dasar negara
Pancasila sebagai ideologi dan dasar negara
 
Resume Buku Ilmu Negara Karangan Soehino
Resume Buku Ilmu Negara Karangan SoehinoResume Buku Ilmu Negara Karangan Soehino
Resume Buku Ilmu Negara Karangan Soehino
 
Sistem Komputer Kelas 8
Sistem Komputer Kelas 8Sistem Komputer Kelas 8
Sistem Komputer Kelas 8
 
Persatuan dan kesatuan bangsa indonesia dari masa ke masa
Persatuan dan kesatuan bangsa indonesia dari masa ke masaPersatuan dan kesatuan bangsa indonesia dari masa ke masa
Persatuan dan kesatuan bangsa indonesia dari masa ke masa
 
Proses perumusan pancasila sebagai dasar negara indonesia
Proses perumusan pancasila sebagai dasar negara indonesiaProses perumusan pancasila sebagai dasar negara indonesia
Proses perumusan pancasila sebagai dasar negara indonesia
 
Persatuan dan kesatuan bangsa indonesia dari masa ke masa
Persatuan dan kesatuan bangsa indonesia dari masa ke masaPersatuan dan kesatuan bangsa indonesia dari masa ke masa
Persatuan dan kesatuan bangsa indonesia dari masa ke masa
 
BAB 1 menggali ide gagasan pendiri bangsa.pptx
BAB 1 menggali ide gagasan pendiri bangsa.pptxBAB 1 menggali ide gagasan pendiri bangsa.pptx
BAB 1 menggali ide gagasan pendiri bangsa.pptx
 
Ppt tentang Eksekutif Legislatif dan Yudikatif - ppkn
Ppt tentang Eksekutif Legislatif dan Yudikatif - ppknPpt tentang Eksekutif Legislatif dan Yudikatif - ppkn
Ppt tentang Eksekutif Legislatif dan Yudikatif - ppkn
 
Sistem Operasi Komputer
Sistem Operasi KomputerSistem Operasi Komputer
Sistem Operasi Komputer
 
ancaman di bidang ideologi dan politik
ancaman di bidang ideologi dan politikancaman di bidang ideologi dan politik
ancaman di bidang ideologi dan politik
 
Menerapkan Berpikir Komputasional dan Praktik Lintas Bidang Muhammad Omar Adr...
Menerapkan Berpikir Komputasional dan Praktik Lintas Bidang Muhammad Omar Adr...Menerapkan Berpikir Komputasional dan Praktik Lintas Bidang Muhammad Omar Adr...
Menerapkan Berpikir Komputasional dan Praktik Lintas Bidang Muhammad Omar Adr...
 
Tabel perbandingan upaya AS dan Uni Soviet untuk Menguasai Dunia
Tabel perbandingan upaya AS dan Uni Soviet untuk Menguasai DuniaTabel perbandingan upaya AS dan Uni Soviet untuk Menguasai Dunia
Tabel perbandingan upaya AS dan Uni Soviet untuk Menguasai Dunia
 
ILMU NEGARA “PROSES TERJADINYA NEGARA SECARA PRIMER dan SEKUNDER”
ILMU NEGARA “PROSES TERJADINYA NEGARA SECARA PRIMER dan SEKUNDER”ILMU NEGARA “PROSES TERJADINYA NEGARA SECARA PRIMER dan SEKUNDER”
ILMU NEGARA “PROSES TERJADINYA NEGARA SECARA PRIMER dan SEKUNDER”
 
Perbandingan sistem pemilu di indonesia
Perbandingan sistem pemilu di indonesiaPerbandingan sistem pemilu di indonesia
Perbandingan sistem pemilu di indonesia
 
Sistem Politik Di Indonesia
Sistem Politik Di IndonesiaSistem Politik Di Indonesia
Sistem Politik Di Indonesia
 

Andere mochten auch

Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and pythonHoang Nguyen
 
Nilesh bimani mtech-cse
Nilesh bimani mtech-cseNilesh bimani mtech-cse
Nilesh bimani mtech-csebhimaninilesh
 
Computer System Architecture - BUN instruction
Computer System Architecture - BUN instructionComputer System Architecture - BUN instruction
Computer System Architecture - BUN instructionDrishti Bhalla
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked ListsJ.T.A.JONES
 
Denial of password guessing attack using turing test
Denial of password guessing attack using turing testDenial of password guessing attack using turing test
Denial of password guessing attack using turing testVikram Verma
 
An Efficient encryption using Data compression towards Steganography,introduc...
An Efficient encryption using Data compression towards Steganography,introduc...An Efficient encryption using Data compression towards Steganography,introduc...
An Efficient encryption using Data compression towards Steganography,introduc...prashantdahake
 
Blueeyetechnology ppt
Blueeyetechnology pptBlueeyetechnology ppt
Blueeyetechnology pptRohit Jamuar
 
HyperText Transfer Protocol
HyperText Transfer ProtocolHyperText Transfer Protocol
HyperText Transfer Protocolponduse
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Representation of binary tree in memory
Representation of binary tree in memoryRepresentation of binary tree in memory
Representation of binary tree in memoryRohini Shinde
 
Flow Chart & Input Output Statement [3] M
Flow Chart & Input Output Statement [3] MFlow Chart & Input Output Statement [3] M
Flow Chart & Input Output Statement [3] Mecko_disasterz
 
Natural language processing
Natural language processingNatural language processing
Natural language processingprashantdahake
 

Andere mochten auch (20)

Cobol, lisp, and python
Cobol, lisp, and pythonCobol, lisp, and python
Cobol, lisp, and python
 
Nilesh bimani mtech-cse
Nilesh bimani mtech-cseNilesh bimani mtech-cse
Nilesh bimani mtech-cse
 
Computer System Architecture - BUN instruction
Computer System Architecture - BUN instructionComputer System Architecture - BUN instruction
Computer System Architecture - BUN instruction
 
EESRDA
EESRDAEESRDA
EESRDA
 
Static Networks
Static NetworksStatic Networks
Static Networks
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Denial of password guessing attack using turing test
Denial of password guessing attack using turing testDenial of password guessing attack using turing test
Denial of password guessing attack using turing test
 
An Efficient encryption using Data compression towards Steganography,introduc...
An Efficient encryption using Data compression towards Steganography,introduc...An Efficient encryption using Data compression towards Steganography,introduc...
An Efficient encryption using Data compression towards Steganography,introduc...
 
Flow chart
Flow chartFlow chart
Flow chart
 
Neural network and mlp
Neural network and mlpNeural network and mlp
Neural network and mlp
 
Blueeyetechnology ppt
Blueeyetechnology pptBlueeyetechnology ppt
Blueeyetechnology ppt
 
Hybrid encryption ppt
Hybrid encryption pptHybrid encryption ppt
Hybrid encryption ppt
 
Afforestation environmental issue
Afforestation environmental issueAfforestation environmental issue
Afforestation environmental issue
 
HyperText Transfer Protocol
HyperText Transfer ProtocolHyperText Transfer Protocol
HyperText Transfer Protocol
 
Information systems
Information systemsInformation systems
Information systems
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Representation of binary tree in memory
Representation of binary tree in memoryRepresentation of binary tree in memory
Representation of binary tree in memory
 
Flow Chart & Input Output Statement [3] M
Flow Chart & Input Output Statement [3] MFlow Chart & Input Output Statement [3] M
Flow Chart & Input Output Statement [3] M
 
Natural language processing
Natural language processingNatural language processing
Natural language processing
 
Number system
Number systemNumber system
Number system
 

Ähnlich wie ADS_Lec2_Linked_Allocation

Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked listsAbdullah Al-hazmy
 
Remove Duplicates in an Unsorted Linked List in Python
Remove Duplicates in an Unsorted Linked List in PythonRemove Duplicates in an Unsorted Linked List in Python
Remove Duplicates in an Unsorted Linked List in PythonKal Bartal
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for publiciqbalphy1
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1SSE_AndyLi
 
1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptxBlueSwede
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxAhmedEldesoky24
 
Arrays and linked lists
Arrays and linked listsArrays and linked lists
Arrays and linked listsAfriyieCharles
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.pptLegesseSamuel
 
mbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxmbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxjotaro11
 
ADS_Lec1_Linear_lists_Stacks
ADS_Lec1_Linear_lists_StacksADS_Lec1_Linear_lists_Stacks
ADS_Lec1_Linear_lists_StacksHemanth Kumar
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-dequesRishabh Jindal
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm KristinaBorooah
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiSowmya Jyothi
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power pMeghaKulkarni27
 

Ähnlich wie ADS_Lec2_Linked_Allocation (20)

Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Remove Duplicates in an Unsorted Linked List in Python
Remove Duplicates in an Unsorted Linked List in PythonRemove Duplicates in an Unsorted Linked List in Python
Remove Duplicates in an Unsorted Linked List in Python
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
 
LEC3-DS ALGO(updated).pdf
LEC3-DS  ALGO(updated).pdfLEC3-DS  ALGO(updated).pdf
LEC3-DS ALGO(updated).pdf
 
Queues
Queues Queues
Queues
 
1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx1.Introduction to Data Structures and Algorithms.pptx
1.Introduction to Data Structures and Algorithms.pptx
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
 
Arrays and linked lists
Arrays and linked listsArrays and linked lists
Arrays and linked lists
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
mbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptxmbit_Unit-2_Linked List.pptx
mbit_Unit-2_Linked List.pptx
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
ADS_Lec1_Linear_lists_Stacks
ADS_Lec1_Linear_lists_StacksADS_Lec1_Linear_lists_Stacks
ADS_Lec1_Linear_lists_Stacks
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-deques
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Queues
QueuesQueues
Queues
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power p
 

Kürzlich hochgeladen

Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 

Kürzlich hochgeladen (20)

Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 

ADS_Lec2_Linked_Allocation

  • 1. Advanced Data Structures: Linked Allocation Sub code: 12CSE102 for Mtech CSE Hemanth Kumar G, Assistant Professor, Department of CSE, NMAMIT, Nitte http://hemanthglabs.wordpress.in http://veda-vijnana.blogspot.in
  • 3. Linked vs Sequential Allocation • Linked allocation o Additional mem space for links. May be a dominating factor! o Info in a node doesn’t take up a whole word. • So already there is a space for link field. o An app may combine several items into one node • So only one link for several items of info. o Implicit gain in storage as tables can overlap, sharing common parts. • Sequential allocation o If large no. of mem locs are left vacant, then only it is useful.
  • 4. Linked vs Sequential Allocation • Linked allocation o Easy to delete an item from within a linked list. o Easy to insert an item into the midst of a list. o References to random parts of the linked list is slow. o To gain access to the kth item in the list, we need k iterations to march down to the right place. • Sequential allocation o Deletion requires moving a large part of the list up into different locations. o Inserting an item into the midst will be extremely time consuming in a long sequential table. o References to random parts of the list is faster in the sequential case. o To gain access to the kth item in the list, takes a fixed time.
  • 5. Linked vs Sequential Allocation • Linked allocation o Easier to join two lists together, or to break one apart into two that will grow independently. o Lends itself immediately to more intricate structures like • variable-size lists • Any nod of the list may be a starting point for another list • Nodes may simultaneously linked together in several orders corresponding to different lists, etc., o If the elements of a linked list belong to different pages in a bulk memory, the memory accesses might take significantly longer. • Sequential allocation o Simple operations, like proceeding sequentially through a list, are slightly faster.
  • 6. Theory of Linked Lists • Node has one word & broken into 2 fields: • There must be some mechanism to find empty space available for new node: o “list of available space” ---- “AVAIL list (stack)” o Avail refers to the top element of this list. • If we want to set link variable X to the address of a new node, and to reserve that node for future use: o X ← AVAIL, AVAIL ← LINK (AVAIL) (4)
  • 7. Operations on Linked List • When a node is deleted and no longer needed, process (4) can be reversed: Link (X)  AVAIL, AVAIL  X. (5) • This operation puts the node addressed by X back onto the list of raw material; we denote (5) by “AVAIL <= X”. • Setting up AVAIL stack: a) linking together all nodes that are to be used for linked mem, b) setting AVAIL to the address of the first of these nodes, and c) Making the last node link to Λ • The set of all nodes that can be allocated is called the storage pool.
  • 8. Handling AVAIL Stack (Technique-1) • Check (4) if all available mem space has been taken: o If AVAIL = Λ, then OVERFLOW; otherwise X ← AVAIL, AVAIL ← LINK (AVAIL) (6) • Check always for OVERFLOW: o terminate with regrets or o Go to Garbage collection routine that attempts to find more available space.
  • 9. Handling AVAIL Stack (Technique-2) • We often do not know in advance how much mem space should be used for the storage pool. • There may be a sequential table of var-size that wants to coexist in mem with linked tables; o In such a case we do not want the linked mem area to take any more space than is absolutely necessary. • L0 = beginning of ascending mem locs • SEQMIN = current lower bound of the sequential table. • If we want to place the linked mem area in Li < SEQMIN, then we can proceed as follows, using a new var POOLMAX.
  • 10. Special recovery procedure for Overflow Address Sequential Table Pointers L0 + 5c SEQ Node 3 L0 + 4c SEQ Node 2 L0 + 3c SEQ Node 1  SEQMIN L0 + 2c AVAIL Node 3  POOLMAX L0 + c AVAIL Node 2 L0 AVAIL Node 1
  • 11. Special recovery procedure for Overflow • Keeps storage pool as small as possible. • Can be applied when all lists occupy the storage pool area. • It avoids time consuming operation of initially linking all available cells together. • Facilitates debugging. • You can put sequential list on the bottom & the pool on the top: o POOLMIN & SEQMAX
  • 12. Common list operations Insertion Operation – (8) Deletion Operation – (9) 17 cycles, but 12 cycles in sequential table (overflow is longer)
  • 13. Cyclic permutation in list operations • In the insertion operation let P be the value of AVAIL before the insertion; if P ≠ Λ, we find that after operation
  • 14. Insertion & Deletion in Lists • Insertion of 21/2 would have been done by using (8) with T=LINK(LINK(FIRST)) • Linked allocation also applies to Queues.
  • 15. Conditions in List design • List empty condition • Programming Error: 1. Failure to handle empty lists properly Soln:- Examine the boundary conditions carefully. 2. Forget about changing some of the links when a structure is being manipulated. Soln:- Draw “before & after” diagrams & compare them, to see which links must change.
  • 16. Conditions applied on Q design Before Insertion:- Insert @ R:- After Insertion:- Boundary situation when the Q is empty: Fig (15) shows situation after insertion. Situation before insertion is yet to be determined
  • 17. Queue Deletion Operation • Check boundary conditions properly • Basic operations – one way to do the things, there will be multiple solutions to a problem. • Abstract discussions  Practical examples.
  • 18. Case Study • Network problems. PERT Charts, linguistics. • Problems involving ”Partial Ordering”. • A partial ordering of a set S is a relation between the objects of S denoted by , satisfying the following properties for any objects x, y, and z in S:
  • 20. GettinG Bored..? Let’s Have An Activity On Relations.. • I want 9 students to volunteer on the podium and pick the announced card. • The card(s) you have, will be your relative(s). • When I ask that anybody have relative- ‘k’ do the following: • Lift your hand if you have that relative’s card. • Go & increment the COUNT node on the blackboard to prove your presence in the class. • If you have a relative, go & create nodes on the board for each relative, linking from your node. • Fill your relative’s number on the SUC field on the board. • If nobody has a relative card, he/she will become independent, fills the SUC filed if he/she will have any relative & walks out of the group to create new party ;) • Based on the entries on the board rearrange yourselves based on SUC, NEXT & COUNT fields.
  • 21. Case Study: Topological Sorting • S is a finite set & we work inside a computer. • (II) => there are no closed loops in the diagram. • In Fig.6, 4  1 violates partial ordering
  • 22. Case Study: Topological Sorting • Embed the partial order in a linear order: o Linear sequence: a1a2…. an : whenever o Boxes are to be rearranged into a line so that all arrows go towards right. o May not be possible in all the cases. E.g. No reordering In case of loops. • Algorithm gives useful operation & proves it is possible for every partial ordering.
  • 23. Applications of Topological Sorting 1. Large glossary of technical terms. • if the definition of the word w1 depends (in)directly on that of word w2. o A partial ordering if there are no “circular” definitions. • Goal: Find a way to arrange the words in the glossary so that no term is used before it has been defined. 2. Writing programs to process the declarations in certain assembly & compiler languages. 3. User’s manual describing a computer language 4. Writing textbook about Information Structures.
  • 24. Topological Sorting • Simple Algorithm: 1. Take an obj that is not preceded by any other obj in the ordering. 2. This obj may be placed first in the output. 3. Remove this obj from the set S; • Resulting set is again partially ordered. 4. Repeat the process until the whole set has been sorted. • Failure:- If there were a nonempty partially ordered set in which every element was preceded by another. • If every element is preceded by another, we could construct an arbitrarily long sequence b1, b2, b3….. in which • Since S is finite, we must have bj = bk for some j < k; => Contradicting (ii).
  • 25. Implementation of Topological Sorting • Ready to perform the actions like locate & remove the objects from the set. • Influenced by desired I/O characteristics: o Alphabetic names for gigantic objects exceeding memory limit..?? • Let the objects to be sorted are numbered from 1 to n in any order. • The input of the program will be on tape unit 1: o Each tape record contains 50 pairs of numbers o Pair (j, k) = object j precedes object k. o First pair is (0, n), n = # objs. o Pair (0, 0) terminates the input. o We shall assume that n + # relation pairs will fit comfortably in memory. o Assume no input validation. o O/P:- # objs in sorted order, followed by the number 0, on tape unit 2.
  • 26. Hand trace of Topological data • E.g., • Don’t give unnecessary more pairs. o can be deduced from o i.e., Give only the pairs corresponding to arrows on a diagram (fig 6.) • Algorithm uses a sequential table X[1], X[2], …, X[n], and each node X[k] has the form: • Count[k] = # direct predecessors of object k • Top[k] = Link to the beginning of the list of direct successors of object k. • Latter list contains entries in the format: • SUC = direct successor of k, NEXT = next item of the list.
  • 27. Computer Representation corresponding to relations (18) • O/p the fields whose COUNT = 0. Then COUNT[Successors]-- • Trick:- Avoids searching for nodes with COUNT = 0. • How? By a Queue containing those nodes. Links for this queue are kept in COUNT field. Reusability!! • Use QLINK[k] for COUNT[k] when that field is no longer being used for counting
  • 29. Algorithm T (Topological Sort) • I/p: Pairs of relations with 1 ≤ j,k ≤ n. • O/p: Set of n objects embedded in linear order. • Internal tables: o QLINK[0], COUNT[1] = QLINK[1], COUNT[2] = QLINK[2], …, COUNT[N] = QLINK[n]; o TOP[1], TOP[2], …, TOP[n]; o A storage pool with one node for each I/p relation and with SUC & NEXT fields; o P, a link variable used to refer to the nodes in the storage pool; o F & R, integer-valued variables of a queue whose links are in QLINK table; o N, a variable that counts how many objects have yet to be output.
  • 32. Characteristics of Algorithm T • Nice interplay b/n Seql mem & linked mem techniques. • Seql mem: X[1], …, X[n]; with COUNT[k] & TOP[k] o References to “random” parts of this table in step T3. • Linked mem: tables of “immediate successors”. o No particular order in the I/p for these table entries. • The Q of nodes waiting to be O/p is kept in the midst of the seql table by linking the nodes together in O/p order. o This linking is done by table index instead of by address; • When front of the Q is X[k], we have F=k instead of F = Loc(X[k])
  • 33. Analysis of Algorithm T • By Kirchoff’s law Execn time ≈ c1m + c2n o m = # I/p relations o n = # Objects o c1 & c2 = Constants • Hard to imagine faster algorithm for this algorithm! • Total running time: (32m + 24n + 7b + 2c + 16)u. o a = # objects with no predecessor o b = # tape records in I/p = o c = # tape records in O/p =
  • 34. Exercise Item 5Item 4Item 3Item 2Λ Item 1 First
  • 35. Programming Practices • Develop the functions & a test driver for the following: o Accepts a general list, traverses it, and returns the key of the node with the minimum key value. o Traverses a general list and deletes all nodes whose keys are negative. o Traverses a general list and deletes all nodes that are after a node with a negative key. o Traverses a general list and deletes all nodes that are before a node with a negative key. o Search list for a given key & return the node number if it is present. o Returns a pointer to the last node in a general list. o Appends two general lists together. o Appends a general list to itself. o Inverts a general list.
  • 36. Reference “The Art of Computer Programming” – Volume 1, on Fundamental Algorithms by Donald E. Knuth, Stanford University, published by Pearson Education © 1997.