1) What is a Data Structure?
Explain its o Built using primitive data types
classification. Examples: Stack, Queue, Linked
List, Tree, Graph.
A data structure is a way of organizing, managing, o Example: Stack ADT built using
and storing data so that it can be accessed and array (primitive):
modified efficiently. It provides a systematic way of
handling large amounts of data, such as Operations: push(), pop(), peek().
performing operations like searching, sorting, Internally implemented using int
inserting, deleting, and updating. arr[SIZE];
Classification of Data Structures:
5) Algorithm for Sorting the Elements of an Array
1. Primitive Data Structures (Bubble Sort Example):
o These are the basic building blocks
of data structures. Algorithm: Bubble Sort
o Examples: Integer, Float, Step 1: Start
Character, Boolean. Step 2: Input the array A of size n
2. Non-Primitive Data Structures Step 3: Repeat for i = 0 to n-1
These are more complex and built using Repeat for j = 0 to n-i-
primitive types. They are classified as: 1
o Linear Data Structures: Elements If A[j] > A[j+1]
are stored sequentially. then
Examples: Arrays, Linked Swap A[j] and
Lists, Stacks, Queues. A[j+1]
o Non-Linear Data Structures: Step 4: Print the sorted array
Elements are stored in a Step 5: Stop
hierarchical or graph manner.
Examples: Trees, Graphs.
👉 Example:
Diagram (classification):
Array = [5, 3, 8, 2] → Sorted = [2, 3, 5, 8]
Data Structure
│
├── Primitive (int, float, char,
bool) 13) Differences between Primitive Data Types and
│ Abstract Data Types
└── Non-Primitive Primitive Abstract Data
Feature
├── Linear (Array, Linked Data Type Type (ADT)
List, Stack, Queue) Basic built-in User-defined,
└── Non-Linear (Tree, Graph) Definition
data types specify operations
2) Define primitive data types and abstract data
Stack, Queue,
types (ADTs). Provide examples. Examples int, float, char
Linked List
Store single Store collection of
1. Primitive Data Types: Storage
o Basic data types provided by values values
programming languages. Direct (+, -, *, Defined by user
Operations
o Examples: int, float, char, /) (push, pop, enqueue)
bool. Provided by Implemented using
Implementation
o They directly store values. language primitives
o Example: int x = 10; char
c = 'A';
👉 Example:
2. Abstract Data Types (ADTs):
o User-defined data types that specify
what operations can be performed Primitive → int x = 5;
but not how they are implemented. ADT → Stack of integers (push(5), pop())
16) Insertion and Deletion in a One-Dimensional 5) Applications of Linked Lists
Array
1. Dynamic memory allocation.
Let array = [10, 20, 30, 40], size = 4 2. Implementation of stacks and queues.
3. Undo functionality in text editors.
1. Insertion (Insert 25 at position 2): 4. Navigation in browsers (forward/backward).
o Shift elements right from position. 5. Polynomial arithmetic in mathematics.
o New array: [10, 20, 25, 30, 40]
2. Deletion (Delete element at position 3): 10) Short Note on Header Linked List
o Remove element, shift left.
o New array: [10, 20, 30, 40] → A header linked list has a special node
delete index 2 → [10, 20, 40] called header node at the beginning.
Header node does not store actual data but
1) Algorithm for Appending a Node in a One-Way stores metadata (like count of nodes, pointer
Linked List to first node, etc.).
Useful for simplifying insertion, deletion,
Algorithm: and traversal operations.
Step 1: Create a new node (newNode)
Step 2: Set newNode->data = value 13) Algorithm to Insert a Node at Beginning &
Step 3: Set newNode->next = NULL End of Single Linked List
Step 4: If head == NULL then
head = newNode
Insert at Beginning:
Else
Step 1: Create newNode
temp = head
Step 2: newNode->data = value
While temp->next != NULL
Step 3: newNode->next = head
temp = temp->next
Step 4: head = newNode
temp->next = newNode
Step 5: Stop
Insert at End:
Step 1: Create newNode
2) Explain Two-Way Linked Lists Step 2: newNode->data = value,
newNode->next = NULL
A two-way (doubly) linked list is a type of Step 3: If head == NULL → head =
linked list where each node has two newNode
pointers: Else
o One points to the previous node. temp = head
o One points to the next node. While temp->next !=
This allows traversal in both directions. NULL
temp = temp->next
👉 Structure Example in C: temp->next = newNode
struct Node {
int data;
struct Node* prev;
struct Node* next;
};
Advantages:
Can traverse forward and backward.
Easier deletion (no need to traverse from
head).