Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views9 pages

Unit 3 Linked List

The document discusses various data structures including singly linked lists, circularly linked lists, and their applications in stacks and queues, emphasizing the ease of insertion and deletion. It also covers equivalence relations in VLSI circuit design and presents an algorithm for determining equivalence classes, detailing its time complexity. Additionally, it describes the linked list representation of sparse matrices using circularly linked lists for efficient traversal of non-zero elements.

Uploaded by

umar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

Unit 3 Linked List

The document discusses various data structures including singly linked lists, circularly linked lists, and their applications in stacks and queues, emphasizing the ease of insertion and deletion. It also covers equivalence relations in VLSI circuit design and presents an algorithm for determining equivalence classes, detailing its time complexity. Additionally, it describes the linked list representation of sparse matrices using circularly linked lists for efficient traversal of non-zero elements.

Uploaded by

umar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Singly Linked Lists

Assignment - 1

Linked Stacks and Queues


The direction of links for both the stack and the queue facilitates easy insertion and deletion
of nodes.
The following figure depicts, we can easily add or delete a node from the top of the stack;
Similarly, we can easily add a node to the rear of the queue and add or delete a node at the
front, although we normally will not add items to the front of a queue.

To represent ‘n’ stacks simultaneously, the declarations of stack will be as follows:

Assume that the initial condition for the stacks is:


and the boundary conditions are:

Add an element to the linked stack

Delete an element from the linked stack


To represent ‘n’ queues simultaneously, the declarations of queue will be as follows:

Assume that the initial condition for the queue is:

and the boundary conditions are:

Add an element to the rear of the linked queue


Delete a front element from the linked queue

Operations
Assignment – 1(Any 4 enough but insertion, deletion is mandatory)

Circularly Linked Lists


Assignment - 1
Equivalence Relations
VLSI (Very Large-Scale Integrated Circuit) circuit design involves exposing a silicon wafer
to multiple masks, each with polygons (shapes). Polygons that overlap are considered
electrically equivalent, meaning they behave as the same in electrical terms. This electrical
equivalence follows rules like mathematical equivalence relations (like symmetry and
transitivity).

The algorithm to determine equivalence works in two phases:


In the first phase, we read in and store the equivalence pairs <i, j >.
In the second phase we begin at 0 and find all pairs of the form <0, j>, where 0 and j are in
the same equivalence class.
In phase two, we scan the seq array for the first i, 0 ≤i< n, such that out[i] = TRUE. Each
element in the list seq [i] is printed. To process the remaining lists which, by transitivity,
belong in the same class as i, we create a stack of their nodes.
By transitivity, all pairs of the form <j, k> imply that k is in the same equivalence class as 0.
We continue in this way until we have found, marked, and printed the entire equivalence class
containing 0. Then we continue.
Analysis of the equivalence program: The initialization of ‘seq’ and ‘out’ takes O(n) time.
Inputting the equivalence pairs in phase 1 takes a constant amount of time per pair. Hence,
the total time for this phase is O (m +n) where ‘m’ is the number of pairs input. In phase 2,
we put each node onto the linked stack at most once. Since there are only 2m nodes, and we
execute the for loop n times, the time for this phase is O (m + n) Thus, the overall computing
time is O(m + n).

Sparse Matrices: linked list representation


A linked list representation for sparse matrices. In our data representation, we represent each
column of a sparse matrix as a circularly linked list with a head node. We use a similar
representation for each row of a sparse matrix. Each node has a tag field, which we use to
distinguish between head nodes and entry nodes. Each head node has three additional fields:
down, right, and next (Figure (a)). We use the down field to link into a column list and the
right field to link into a row list. The next field links the head nodes together. The head node
for row i is also the head node for column i, and the total number of head nodes is max
{number of rows, number of columns).
Each entry node has five fields in addition to the tag field: row, col, down, right, value
(Figure (b)). We use the down field to link to the next nonzero term in the same column
and the right field to link to the next nonzero term in the same row. Thus, if aij ≠0, there
is a node with tag field = entry, value = aij, row = i, and col = j (Figure (c)). We link this
node into the circular linked lists for row i and column j. Hence, it is simultaneously linked
into two different lists.

As we indicated earlier, each head node is in three lists: a list of rows, a list of columns, and
a list of head nodes. The list of head nodes also has a head node that has the same structure
as an entry node (Figure(b)). We use the row and col fields of this node to store the matrix
dimensions.
Suppose that we have the sample sparse matrix, a, shown in the following Figure.
The linked representation of the above matrix.

Although we have not shown the value of the tag fields, we can easily determine these values
from the node structure. For each nonzero term of a, we have one entry node that is in
exactly one row list and one column list. The head nodes are marked H0-H3. As the figure
shows, we use the right field of the head node list header to link into the list of head nodes.
The entire matrix represented through the head node, a, of the list of head nodes.

A linked list representation for sparse matrices uses circularly linked lists for both rows
and columns, with head nodes. Each head node has three fields: down, right, and next,
linking it to the column, row, and other head nodes. Entry nodes represent non-zero matrix
elements and are linked in both row and column lists.

For each non-zero element a ij, an entry node stores the value a ij, row i, and column j , linking
to the next non-zero elements in the row and column. Head nodes also store matrix
dimensions and are connected to a central head node list.

This structure allows efficient traversal of rows and columns in sparse matrices, as shown in
the example matrix linked in above linked list representation diagram.

Doubly Linked Lists


Assignment - 1

You might also like