How unit 1 is examined
Address numericals and linked list algorithms carry the marks.
Concepts of Data and Information
Medium weight
Definition. Data is a collection of raw, unprocessed facts and figures; information is data that has been processed, organised and given context so that it is meaningful for decisions. A data type tells the compiler a variable's kind of value, size and operations.
Key points.
- In general data is numeric (integer or real), character or alphanumeric (letters, digits, symbols), or logical/boolean (true or false).
- C data types are primitive or built-in (
int,char,float,double,void), derived (arrays, pointers, functions) and user-defined (struct,union,enum,typedef). - Modifiers
short,long,signed,unsignedchange size or range. intholds whole numbers (%d),charone character (%c),floatanddoublereal numbers of about 6 and 15 digits (%f,%lf).
| Type | Bytes | Range (typical) |
|---|---|---|
char / unsigned char |
1 | -128 to 127 / 0 to 255 |
short / unsigned short |
2 | -32,768 to 32,767 / 0 to 65,535 |
int / unsigned int |
4 (2 in Turbo C) | -2,147,483,648 to 2,147,483,647 / 0 to 4,294,967,295 |
long / unsigned long |
4 (Windows, 32-bit), 8 (64-bit Linux) | as int when 4 bytes |
long long / unsigned long long |
8 | about $\pm 9.2\times10^{18}$ / 0 to $1.8\times10^{19}$ |
float |
4 | 1.2E-38 to 3.4E+38, 6 digits |
double |
8 | 2.2E-308 to 1.8E+308, 15 digits |
long double |
10, 12 or 16 | 3.4E-4932 to 1.2E+4932 |
void |
no size (sizeof(void) is invalid in standard C) |
no value; functions returning nothing, void * |
| Basis | Data | Information |
| --- | --- | --- |
| Nature | Raw facts, no context | Processed, meaningful |
| Dependency | Independent input | Depends on data |
| Form | Raw numbers, symbols | Reports, charts, summaries |
| Reliability | Unspecific, not decision-ready | Specific, reliable for decisions |
| Example | Marks 45, 62, 78 | Average 61.67, result Pass |
Answer frame. Data vs information: definitions, table, example. Types of data: define data, general types (point 1), the three C categories, size table.
Asked: [7 marks] (Nov 2022) Mention the types of data. Write all built-in data types in C. Asked: [7 marks] (Jun 2023) What is the difference between data and information? Give one example of each.
Classification of Data structures
High weight
Definition. A data structure is a particular way of organising and storing data in memory so that it can be accessed and modified efficiently.
Diagram.
Key points.
- Primitive structures are machine types; non-primitive ones are linear or non-linear.
- In a linear structure each element except the first and last has one predecessor and one successor: array, linked list, stack, queue.
- In a non-linear structure an element links to many others: tree, graph.
- A stack is LIFO: push and pop happen only at the top, like a pile of plates.
- A queue is FIFO: enqueue at the rear, dequeue from the front, like a ticket line.
- A tree has one root and each other node one parent (disk folders); a graph is vertices joined by edges (cities and roads).
- Static structures are fixed at compile time (array), dynamic ones grow at run time (linked list); homogeneous ones hold one type, heterogeneous ones mix types (structure).
| Basis | Array | Linked list |
|---|---|---|
| Memory | Contiguous | Scattered nodes joined by pointers |
| Size | Fixed (static) | Dynamic |
| Access | By index, $O(1)$ | Sequential, $O(n)$ |
| Insert/delete | $O(n)$, elements shift | $O(1)$ at a known position |
| Search | $O(n)$; $O(\log n)$ if sorted | $O(n)$ |
| Memory use | Unused slots wasted | No unused slots, but a pointer per node |
Answer frame. Types: define, draw the tree, explain linear and non-linear, then static/dynamic. Differentiate: the table, closing "array suits fast access, list suits frequent insert/delete".
Asked: [7 marks] (Nov 2022, Dec 2025) What do you mean by data structure and mention its types? Asked: [7 marks] (Jun 2024) Differentiate array and linked list. Asked: [7 marks] (Dec 2025) Explain the classification of data structures in detail.
Abstract Data Types
Medium weight
Definition. An Abstract Data Type (ADT) is a mathematical model of a data structure that specifies the data values and the operations on them, without saying how they are implemented.
Key points.
- An ADT gives the set of values and the operations, each with inputs, output, pre-condition (true before) and post-condition (true after).
- The specification (what) is separate from the implementation (how), and users reach the data only through the operations, so the implementation can change freely.
- Stack ADT:
push(S,x)adds x, pre not full;pop(S)removes and returns the top, pre not empty;peek(S)returns the top unchanged;isEmpty(S)/isFull(S)return true or false. - Operations are traversal, insertion, deletion, searching, sorting and merging; cost is time and space: array access $O(1)$, insert/delete $O(n)$, search $O(n)$, push/pop $O(1)$, list insert at head $O(1)$.
Example (Queue ADT). enqueue(Q,x): pre Q not full; post x at rear. dequeue(Q): pre Q not empty; post front removed and returned. front(Q): pre Q not empty; post front returned. isEmpty(Q): true if size is 0.
Answer frame. Definition, Queue ADT, specification versus implementation; Dec 2025: add operations and cost.
Asked: [7 marks] (Jun 2023, Jun 2024) What is Abstract data type? Explain with the help of example. Asked: [7 marks] (Dec 2025) Define Abstract Data Types (ADT). Explain the different operations performed on data structures and describe the criteria for cost estimation.
Implementation aspects: Memory representation
Low weight
Definition. A two-dimensional array is stored in memory as a single contiguous block, either row by row (row-major) or column by column (column-major).
Key points.
- Row-major order stores row 1 completely, then row 2; C uses it. Column-major stores column by column; FORTRAN uses it.
- For an $m \times n$ array with lower bounds $L_r,L_c$, base $BA$ and element size $W$: row-major $\text{LOC}(A[i][j])=BA+W\,[(i-L_r)\,n+(j-L_c)]$.
- Column-major $\text{LOC}(A[i][j])=BA+W\,[(j-L_c)\,m+(i-L_r)]$.
- One-dimensional: $\text{LOC}(A[k])=BA+W(k-LB)$, with $UB-LB+1$ elements.
Example. $A[1..3,1..4]$, $BA=100$, $W=2$, $A[2][3]$: row-major $100+2[4+2]=$ 112; column-major $100+2[6+1]=$ 114.
Asked: [7 marks] (Jun 2023) How to represent 2-D array in memory? Explain with the help of example.
Data structures operations and its cost estimation
High weight
Definition. An algorithm is a finite, step-by-step procedure that takes input and produces the required output; its efficiency is measured by the time and space it needs as the input size $n$ grows.
Key points.
- Characteristics: input, output, definiteness (clear steps), finiteness, effectiveness (basic steps), correctness, generality (solves every instance).
- Criteria for cost estimation: time (count of basic operations), space (auxiliary memory), input size $n$, best/average/worst case, and order of growth, which keeps the estimate machine-independent.
- Best, average and worst case are the fewest, expected and most steps for size $n$: linear search takes 1, about $n/2$ and $n$ comparisons. For $n=1024$ that is up to 1024, $O(n)$, against about $\log_2 1024+1=11$ for binary search on sorted data, $O(\log n)$.
- Big-Oh $f(n)=O(g(n))$ if $f(n) \le c\,g(n)$ for all $n \ge n_0$: an upper bound.
- Big-Omega $f(n)=\Omega(g(n))$ if $f(n) \ge c\,g(n)$ for all $n \ge n_0$: a lower bound.
- Big-Theta: $c_1 g(n) \le f(n) \le c_2 g(n)$, a tight bound.
- Growth: $1<\log n<n<n\log n<n^2<2^n$.
Proof. $3n+2 \le 4n$ for $n \ge 2$, so $c=4$, $n_0=2$.
Frequency count. for (i=0;i<n;i++) sum += a[i]; costs init 1, test $n+1$, increment $n$, body $n$: $3n+2$, $O(n)$.
Space example. An iterative sum uses one variable, $O(1)$ extra space; a recursive sum(n) keeps $n$ stack frames, $O(n)$.
Big-O Omega Theta
| c.g | f | c2.g
| / f | / c.g | / f
| /./ | /./ | /./c1.g
|__/_:___ n |__/_:___ n |__/_:___ n
n0 n0 n0
f<=c.g f>=c.g c1.g<=f<=c2.g
Formula. Master theorem $T(n)=aT(n/b)+f(n)$: if $f(n)=\Theta(n^{\log_b a}\log^k n)$ then $T(n)=\Theta(n^{\log_b a}\log^{k+1} n)$.
Example. $T(n)=2T(n/2)+n\log n$: $a=b=2$, $n^{\log_2 2}=n$, $f(n)=n\log^1 n$, $k=1$, so $T(n)=\Theta(n\log^2 n)$.
Answer frame. Efficiency: time and space, cases, notations, proof, growth chain. Recurrence: $a,b,f(n)$, $n^{\log_b a}$, case, answer.
Pitfall: Writing "Big-O means worst case"; the notations are bounds, and any bound applies to any case (linear search: worst $\Theta(n)$, best $\Theta(1)$).
Asked: [7 marks] (Nov 2022, Jun 2024) Demonstrate the efficiency of an algorithm. How to measure the complexity of an algorithm, also discuss various types of notation for this purpose? Asked: [7 marks] (Dec 2022) Give the solution for following Recursion: $T(n)=2T[n/2]+n \log n$. Asked: [7 marks] (Nov 2022) What do you mean by an algorithm? Write the criteria and characteristics of an algorithm.
Introduction to linear data structures - Arrays
High weight
Definition. An array is a collection of elements of the same type stored in contiguous memory locations and accessed by an index.
Key points.
- Address formulas give $O(1)$ access; middle insertion or deletion shifts elements, $O(n)$.
- Overflow is inserting into a full array (
n<mark>MAX); underflow is deleting from an empty one (n</mark>0). - Compaction shifts live elements together after deletions so free space becomes one block; it costs $O(n)$ and changes element addresses.
- A sparse matrix is mostly zeros; the triplet form stores only (row, column, value) of non-zeros after a header (rows, columns, count).
- Lower triangular: $a_{ij}=0$ for $i<j$; upper triangular: $a_{ij}=0$ for $i>j$. The non-zero triangle fits in $n(n+1)/2$ cells of a 1-D array.
- The other sparse form is a linked list of nodes
struct SNode { int row, col, val; struct SNode *next; };. Column-major, 0-indexed: upper $BA+W[j(j+1)/2+i]$; lower $BA+W[jn-j(j-1)/2+(i-j)]$. - Row-major, 0-indexed: lower $BA+W[i(i+1)/2+j]$; upper $BA+W[i\,n-i(i-1)/2+(j-i)]$. Lower, 1-based: $BA+W[i(i-1)/2+(j-1)]$.
Insert(pos, x): Step 1: If n==MAX, "overflow"; stop. Step 2: For i=n-1 down to pos, A[i+1]=A[i]. Step 3: A[pos]=x; n++.
Delete(pos): Step 1: If n==0, "underflow"; stop. Step 2: For i=pos to n-2, A[i]=A[i+1]. Step 3: n--.
Example (sparse, 0-indexed). $\begin{bmatrix}0&0&3&0\\0&0&0&0\\5&0&0&7\\0&2&0&0\end{bmatrix}$: header (4,4,4), then (0,2,3), (2,0,5), (2,3,7), (3,1,2).
Example 1 (Dec 2023). $A[-100:100,-5:50]$, $BA=10$, $W=4$, row-major, $A[99,49]$: $N=50-(-5)+1=56$; $i-L_r=199$, $j-L_c=54$; offset $199\times 56+54=11198$; $10+4\times 11198$ = 44802.
Example 2 (Nov 2022). Column-major $\text{LOC}(A[i,j])=Base+w[m(j-LB_2)+(i-LB_1)]$. Sizes: AAA 46, BBB 16, CCC 8. Base 300, $w=4$: AAA[15] $=340$, AAA[35] $=420$, AAA[55] $=500$ (outside 5:50).
Example (triangular, 4ร4, 0-indexed, row-major, $BA=100$, $W=2$). Lower: rows $0..i-1$ hold $1+2+\dots+i=i(i+1)/2$ elements, then $j$ more, so $A[3][2]=100+2(6+2)=$ 116. Upper: row $k$ holds $n-k$ elements, so $A[1][3]=100+2(4-0+2)=$ 112.
Example 3 (Dec 2023, 3-D, row-major). $A(-2{:}2,2{:}22)$: lengths 5, 21, so 105 elements. $B(1{:}8,-5{:}5,-10{:}5)$: lengths 8, 11, 16, so 1408. $B[3,3,3]$: $E_1=3-1=2$, $E_2=3+5=8$, $E_3=3+10=13$; $500+2[(2\times11+8)\times16+13]=500+2\times493=$ 1486.
Answer frame. Numerical: Given, formula, working, bold address. Sparse: triplets, formulas.
Pitfall: Using the upper bound instead of $N=UB-LB+1$, or forgetting the lower bound.
Asked: [5 marks] (Dec 2023) 2D array $A[-100:100,-5:50]$: address of $A[99,49]$, base 10, 4 bytes per element, row-major. Asked: [7 marks] (Nov 2022) Column-major formula for $m \times n$; counts of AAA[5:50], BBB[-5:10], CCC[1:8]; addresses of AAA[15], AAA[35], AAA[55] (base 300, $w=4$). Asked: [7 marks] (Dec 2023) A(-2:2, 2:22), B(1:8, -5:5, -10:5) row-major: lengths, element counts, effective indices, address of B[3,3,3] (base 500, W=2). Asked: [7 marks] (Jun 2023) Differentiate array and linked list. Asked: [7 marks] (Jun 2024) What are sparse matrices? Explain their representation, upper and lower triangular forms, a space-efficient representation and its address formulas. Asked: [7 marks] (Jun 2024) Write a note on Compaction, overflow and underflow in array term.
Linked List: Representation of linked list in memory
Medium weight
Definition. A singly linked list is a linear collection of nodes in which each node holds a data field and a pointer to the next node, and the last node points to NULL.
Diagram.
head = 1000
[1000: 10 | 2050] -> [2050: 20 | 1300] -> [1300: 30 | NULL]
Key points.
- Node:
struct Node { int data; struct Node *next; };. mallocplaces nodes anywhere; only the next fields give the order, andheadholds the first address (empty list:NULL).- Advantages: run-time size, no shifting.
- Applications: a polynomial keeps one node per term, a stack or queue pushes and pops at the list ends, an adjacency list keeps one list of neighbours per vertex, and dynamic memory management keeps free blocks on a free (available-space) list. Disadvantages: no random access, a pointer per node.
Step 1: head=tail=NULL.
Step 2: For each x, allocate n; if head is NULL, head=tail=n, else tail->next=n, tail=n.
Step 3: t=head; while t, print t->data, t=t->next.
#include <stdio.h>
#include <stdlib.h>
struct Node { int data; struct Node *next; };
int main(void) {
struct Node *head=NULL, *tail=NULL, *n;
int x;
while (scanf("%d", &x)==1) { // input loop, stop at EOF
n=malloc(sizeof *n); n->data=x; n->next=NULL;
if (!head) head=tail=n; else { tail->next=n; tail=n; }
}
for (n=head; n; n=n->next) printf("%d -> ", n->data);
printf("NULL\n"); // 5 -> 6 -> 7 -> NULL
return 0;
}
Worked cases (list above, new node n). pos 1: n->next=1000, head = n. pos 3 (middle): p makes 1 move to 2050 (node 20); n->next=1300, 2050's next = n. pos 4 (end): p makes 2 moves to 1300 (node 30); n->next=NULL, 1300's next = n. pos 5 or more: p becomes NULL, "invalid position".
Insert at position pos.
Step 1: If pos<1, print "invalid position"; stop.
Step 2: Create n. If pos=1, n->next=head, head=n; stop.
Step 3: Move p from head pos-2 times; if p is NULL, print "invalid position"; stop.
Step 4: n->next=p->next, then p->next=n.
Answer frame. Define, address diagram, node, advantages, algorithm, program, $O(n)$.
Asked: [7 marks] (Nov 2022) What is a singly linked list? Write its advantage and application and explain its node structure. Write the algorithm and program in C to create and traverse a singly linked list. Asked: [7 marks] (Dec 2025) Describe the memory representation of a singly linked list. Write an algorithm to insert a node at a specific position in a linked list.
Different implementation of linked list
Medium weight
Definition. The operations on a linked list are creation, traversal, counting, searching, updating, insertion, deletion, reversing, sorting and merging.
Diagram.
Key points.
- Insert at beginning:
new->next=head; head=new;, $O(1)$; at end: walk to the last node,last->next=new;, $O(n)$. - Insert after
prev:new->next=prev->next; prev->next=new;in this order, or the rest is lost. - Delete first:
temp=head; head=head->next; free(temp);. Delete a value: find its predecessor,pred->next=node->next, free it. - Delete at end: if
head->nextis NULL, freehead, set it NULL; else walkpto the second-last node,free(p->next); p->next=NULL;. - Traverse, count, search and update each walk the nodes to NULL, $O(n)$.
- Reverse with three pointers:
prev=NULL, curr=head; whilecurr:next=curr->next; curr->next=prev; prev=curr; curr=next;; thenhead=prev. - Merge: if A is empty the result is B; else walk
pto A's last node,p->next=B. - Sort: for each
pand laterq, swap data ifp->data>q->data($O(n^2)$).
void insertAfter(struct Node *prev, int x) {
if (!prev) { printf("Previous node is NULL\n"); return; }
struct Node *n=malloc(sizeof *n);
n->data=x; n->next=prev->next; prev->next=n;
}
Answer frame. Operations one line each, the figures, three insertion cases.
Asked: [7 marks] (Nov 2022, Jun 2024) Explore all types of operations that can be performed on a linked list. Asked: [7 marks] (Dec 2024) Explain the insertion operation in linked list. How nodes are inserted after a specified node?
Circular linked list
Not asked since 2022
Definition. A circular linked list is a linked list in which the last node points back to the first node instead of NULL.
Key points.
- Any node can be the start; traversal stops on returning to it, with
while (p->next!=head). - A last-node pointer makes insertion at both ends $O(1)$; it suits round-robin scheduling.
Doubly linked list, etc
High weight
Definition. A doubly linked list is a linked list in which each node has three fields, prev, data and next, so it can be traversed in both directions.
Diagram.
Key points.
- It traverses forward by
nextand backward byprev(fromtail); a singly list only goes forward, so reverse traversal or a backward search must re-scan from the head. - Given the node's address, a doubly list deletes in $O(1)$ (
prevgives the predecessor, code below); a singly list must scan from the head for the predecessor, $O(n)$. - Disadvantages: an extra pointer per node and more updates.
void delDLL(struct Node *node) { // doubly: O(1)
if (!node) return;
if (node->prev) node->prev->next=node->next; else head=node->next; // head
if (node->next) node->next->prev=node->prev; else tail=node->prev; // last/only
free(node);
}
Insert at beginning.
Step 1: Create n, n->prev=NULL, n->next=head.
Step 2: If head!=NULL, head->prev=n.
Step 3: head=n.
Delete from end.
Step 1: If head is NULL, print "underflow"; stop.
Step 2: Move p to the last node.
Step 3: If p->prev is NULL, head=NULL; else p->prev->next=NULL. free(p).
Search and modify.
Search(key): Step 1: p=head, pos=1. Step 2: While p: if p->data==key, return p (pos); else p=p->next, pos++. Step 3: Return NULL, "not found".
Modify(key, val): Step 1: p=Search(key). Step 2: If p is NULL, report not found; else p->data=val.
Trace on 10 <-> 20 <-> 30: key 20 is found at pos 2 after 2 comparisons, and modify to 25 gives 10 <-> 25 <-> 30. Key 40 compares 10, 20, 30, then p is NULL: "not found". Backward search starts at tail with p=p->prev: key 10 compares 30, 20, 10.
Insert at position pos (C).
#include <stdio.h>
#include <stdlib.h>
struct Node { int data; struct Node *prev, *next; } *head=NULL;
void insertAt(int val, int pos) {
struct Node *n, *p=head;
if (pos<1||!(n=malloc(sizeof *n))) { printf("Error\n"); return; }
n->data=val; n->prev=n->next=NULL;
if (pos==1) { n->next=head; if (head) head->prev=n; head=n; return; }
for (int i=1; p&&i<pos - 1; i++) p=p->next;
if (!p) { printf("Invalid position\n"); free(n); return; }
n->next=p->next; n->prev=p;
if (p->next) p->next->prev=n;
p->next=n;
}
void display(void) { for (struct Node *p=head; p; p=p->next) printf("%d ", p->data); }
int main(void) { insertAt(10, 1); insertAt(30, 2); insertAt(20, 2); display(); return 0; } // 10 20 30
Answer frame. Versus singly: points 1-3, delete code. Algorithms: steps, before/after diagrams, pros, cons. Search: algorithm, both traces. Program: checks, walk to pos-1, four updates.
Pitfall: Missing NULL checks on
p->nextandhead, or wrong pointer-update order.
Asked: [7 marks] (Nov 2022) How doubly linked list is better than a linked list? Justify with examples. Asked: [14 marks] (Dec 2023) Define doubly linked list; algorithms to insert at the beginning and delete from the end; advantages and disadvantages. Asked: [7 marks] (Jun 2023) Write a program in C to insert a node at any specified position in doubly linked list. Asked: [7 marks] (Dec 2024) What are the drawbacks of single linked list? Write and explain the algorithm for search and modify operations in doubly linked list with example.
Application of linked list: polynomial manipulation
Low weight
Definition. A polynomial is stored as a linked list whose nodes hold a coefficient, an exponent and a next pointer, in decreasing order of exponent.
Key points.
- Node:
struct Term { int coef, exp; struct Term *next; };. - Other applications: stacks, queues, adjacency lists, and the free (available-space) list from which
malloctakes blocks and to whichfreereturns them.
Step 1: p=A, q=B, result R=NULL.
Step 2: While p and q: if exponents are equal, append the coefficient sum unless 0, advance both; else append the larger-exponent term, advance it.
Step 3: Append the remaining terms.
struct Term *R=NULL, *t; // result and its tail
void append(int c, int e) { // create a node, add at R's tail
if (c==0) return; struct Term *n=malloc(sizeof *n); n->coef=c; n->exp=e; n->next=NULL;
if (!R) R=n; else t->next=n;
t=n;
}
void add(struct Term *p, struct Term *q) {
while (p&&q)
if (p->exp==q->exp) { append(p->coef+q->coef, p->exp); p=p->next; q=q->next; }
else if (p->exp>q->exp) { append(p->coef, p->exp); p=p->next; }
else { append(q->coef, q->exp); q=q->next; }
for (; p; p=p->next) append(p->coef, p->exp);
for (; q; q=q->next) append(q->coef, q->exp);
}
Example. $A=5x^3+4x^2+2$, $B=3x^3-4x^2+6x+1$: $x^3$: $5+3=8$; $x^2$: $4-4=0$, dropped; $x$: 6 from $B$; constant $2+1=3$. $R=8x^3+6x+3$.
Asked: [7 marks] (Jun 2023) What is the application of linked list? Also write the algorithm how to add two polynomials using linked list.
Last-minute revision
- O upper, Omega lower, Theta tight.
- $A[99,49]$ is 44802; $B[3,3,3]$ is 1486.
Memory hooks
- Big-O Over, Omega floor, Theta Together.
- Array: address by arithmetic; list: by pointer.
- Overflow
n<mark>MAX, underflown</mark>0.
Coverage checklist
- Concepts of Data and Information: data types; data versus information.
- Classification of Data structures: types; array versus linked list; classification.
- Abstract Data Types: ADT with example; ADT, operations, cost.
- Implementation aspects: Memory representation: 2-D array in memory.
- Data structures operations and its cost estimation: notations; recurrence.
- Introduction to linear data structures- Arrays: numericals; sparse; compaction.
- Linked List: Representation of linked list in memory: create; insert at position.
- different implementation of linked list: operations; insert after.
- Circular linked list: not asked.
- doubly linked list, etc: versus singly; program; search, modify.
- Application of linked list: polynomial manipulation using linked list, etc: polynomial addition.