MCS-208 · Unit 3

Lists

Section 8 of 8

Block 1 · Unit 3Lists12 min · Section 8 of 8

3.8Applications of Linked Lists

Covers IGNOU MCS-208 §3.7, 3.8

Linked lists are used wherever the amount of data changes often or is not known in advance. This page shows the classic textbook application, polynomials, and then sums up when to choose an array and when a linked list.

Polynomials as linked lists

Each node holds one term: a coefficient, an exponent and a link to the next term. The nodes are kept in decreasing order of exponent, and only non-zero terms are stored.

f(x) = 7x^5 + 9x^4 - 6x^3 + 3x^2 as a linked list
head --> [ 7 | 5 | o-]--> [ 9 | 4 | o-]--> [ -6 | 3 | o-]--> [ 3 | 2 | NULL ]
          coef exp next

Compared with the array of terms in Unit 2, the linked version can grow without a fixed maximum, and a term can be inserted or removed without shifting. Addition uses the same merge idea: walk both lists together and append a node to the result for each exponent.

Arrays versus linked lists

Array (contiguous) listLinked list
SizeFixed in advance; overflow possibleGrows and shrinks at run time; “full” only when memory runs out
Memory per elementData onlyData + one or two pointers
Access to the ii-th elementO(1)O(1) (random access)O(i)O(i) (sequential access)
Insert/delete at a known placeO(n)O(n) (shifting)O(1)O(1) (pointer changes)
Binary searchPossible on sorted dataNot possible (use a skip list)
Memory layoutOne contiguous block, cache-friendlyNodes scattered in memory

The summary of the study material puts it briefly: lists are flexible and avoid overflow, but the links take extra space and lists are not suited to random access.

Which list where?

Kind of listTypical applications
Singly linkedStacks and queues (Units 4–5), adjacency lists of graphs (Unit 8), chaining in hash tables (Unit 10), polynomials, sparse matrices
Doubly linkedBrowser back/forward history, undo/redo in editors, LRU caches, music players with previous/next
CircularRound-robin CPU scheduling, multiplayer turns, repeating playlists
Skip listSorted sets and indexes (e.g. Redis), concurrent sorted maps

Key takeaways

  • A polynomial node holds (coef, exp, next); terms are kept in decreasing exponent order and added by merging in O(m+n)O(m + n).
  • Arrays: O(1)O(1) access, fixed size, O(n)O(n) insertion/deletion.
  • Linked lists: flexible size, O(1)O(1) pointer changes, O(n)O(n) access, extra memory for links.
  • Singly, doubly, circular and skip lists each suit different access patterns.

Practice questions

Answer on paper first, then check. The explanation matters more than the letter you chose.

Question 1 · multiple choice

Which operation is faster in an array list than in a linked list?

Show answer

Answer: A. Accessing the 500th element

An array computes the address of element 500 directly in O(1)O(1); a linked list must follow 499 links. The other three are faster (or only possible) with linked lists.

Question 2 · multiple choice

A polynomial 4x6−3x2+84x^6 - 3x^2 + 8 is stored as a linked list of terms. How many nodes does it have?

Show answer

Answer: C. 3

Only the non-zero terms are stored: (4,6)(4, 6), (−3,2)(-3, 2), (8,0)(8, 0). 7 would be the size of a coefficient array for degree 6.

Question 3 · multiple choice

Which kind of list best fits the “back” and “forward” buttons of a web browser?

Show answer

Answer: B. Doubly linked list

You need to move both backwards and forwards from the current page. A singly linked list allows only one direction.

Question 4 · multiple choice

What does this program print?

C · q3-poly.c
#include <stdio.h>

typedef struct term {
    int coef, exp;
    struct term *next;
} Term;

int main(void)
{
    Term t3 = {5, 0, NULL}, t2 = {-2, 1, &t3}, t1 = {3, 2, &t2};
    int x = 2, value = 0;
    for (Term *p = &t1; p != NULL; p = p->next) {
        int power = 1;
        for (int i = 0; i < p->exp; i++)
            power *= x;
        value += p->coef * power;
    }
    printf("%d\n", value);
    return 0;
}
Show answer

Answer: D. 13

The list holds 3x2−2x+53x^2 - 2x + 5; at x=2x = 2: 3⋅4−2⋅2+5=12−4+5=133 \cdot 4 - 2 \cdot 2 + 5 = 12 - 4 + 5 = 13. 21 comes from adding 2x2x instead of subtracting it.

Question 5 · multiple choice

Which application uses a circular linked list most naturally?

Show answer

Answer: C. Giving each running process a CPU time slice in turn

Round-robin scheduling goes round the processes again and again; after the last process comes the first. Undo needs a stack, and sorted dictionaries need fast search.

Question 6 · short answer

Compare arrays and linked lists as implementations of the list ADT (at least four points).

Show worked answer

(1) Size: an array’s size is fixed when it is created and can overflow; a linked list grows and shrinks at run time and is limited only by available memory. (2) Access: an array gives O(1)O(1) access to any element by index; a linked list needs O(n)O(n) sequential access. (3) Insertion/deletion: an array must shift elements, O(n)O(n); a linked list only changes pointers, O(1)O(1) once the position is known. (4) Memory: an array stores only data in one contiguous block; a linked list needs one or two extra pointers per node and its nodes may be scattered. (5) Searching: a sorted array allows binary search, O(log⁡n)O(\log n); a sorted linked list needs O(n)O(n) (unless it is a skip list).

↑ ↓ move↵ openTab switch type