CBSE Class 12 Computer Science Data Structures Concepts

Download CBSE Class 12 Computer Science Assignments

Explore structured practice materials through the CBSE Class 12 Computer Science Data Structures Concepts. Tailored for Class 12 learners, utilizing these Computer Science assignments ensures thorough preparation and strengthens foundational knowledge before final CBSE evaluations.

Access CBSE School Assignments and Answers

Navigate directly to the solved Computer Science assignments using the digital viewer below. Each practice set includes detailed step-by-step solutions, allowing students to instantly cross-check their work and identify areas requiring further revision.

Unit-2 Data Structures

2,3 & 4 Marks Practice Questions

 

Question 1. Convert the following infix expressions to postfix expressions using stack
1. A + (B * C) ^ D - (E / F - G)
Answer:

Symbol ScannedStack StatusPostfix Expression
A(empty)A
++A
(+, (A
B+, (A B
*+, (, *A B
C+, (, *A B C
)+A B C *
^+, ^A B C *
D+, ^A B C * D
-+ (Wait, pop ^ and +, then push -? Wait: top is ^ which has higher or equal precedence than -. Pop ^, then pop +. Then push -. Let's check precedence: ^ is highest, then *, /, then +, -. So stack becomes -)A B C * D ^ +
(-, (A B C * D ^ +
E-, (A B C * D ^ + E
/-, (, /A B C * D ^ + E
F-, (, /A B C * D ^ + E F
--, (, -A B C * D ^ + E F /
G-, (, -A B C * D ^ + E F / G
)-A B C * D ^ + E F / G -
End(empty)A B C * D ^ + E F / G - -
Final Postfix Expression: \(ABC^*D^{\wedge}+EF/G--\)
In simple words: Operators are placed after their operands following operator precedence rules using a stack.

Exam Tip: Remember operator precedence: Exponentiation (\(\wedge\)) > Multiplication/Division (*, /) > Addition/Subtraction (+, -).

 

Question 1 (continued). 2. A * B / C * D ^ E * G / H
Answer:
Evaluating strictly from left to right with equal precedence operators associating from left to right:
\(A * B \rightarrow AB*\)
\(/ C \rightarrow AB*C/\)
\(* D \rightarrow AB*C/D*\)
\(^ E \rightarrow AB*C/DE^*\)
\(* G \rightarrow AB*C/DE^*G*\)
\(/ H \rightarrow AB*C/DE^*G*H/\)
Final Postfix Expression: \(AB*C/DE^*G*H/\)
In simple words: Operators with the same precedence are evaluated from left to right.

Exam Tip: For chain multiplication and division, strictly proceed from left to left-associative order.

 

Question 1 (continued). 3. ((A*B)-((C-D)*E/F)*G (Note: Source OCR shows C_D and missing parenthesis, standard form parsed as given)
Answer:
Applying standard stack-based infix-to-postfix conversion yields: \(AB*CD-EF/*G*-\)
In simple words: Resolve innermost parentheses first before applying operator precedence to outer levels.

Exam Tip: Balance parentheses carefully before starting your conversion table.

 

Question 2. Evaluate the following postfix expression E given below; show the contents of the stack during the evaluation
1. E = 5, 9, +, 2, /, 4, 1, 1, 3, -, *, +
Answer:
Step-by-step evaluation:
- Push 5, 9 → Stack: [5, 9]
- Operator + → \(5 + 9 = 14\) → Stack: [14]
- Push 2 → Stack: [14, 2]
- Operator / → \(14 / 2 = 7\) → Stack: [7]
- Push 4, 1, 1, 3 → Stack: [7, 4, 1, 1, 3]
- Operator - (on 1 and 3) → \(1 - 3 = -2\) → Stack: [7, 4, 1, -2]
- Operator * (on 1 and -2) → \(1 \times (-2) = -2\) → Stack: [7, 4, -2]
- Operator * (on 4 and -2) → \(4 \times (-2) = -8\) → Stack: [7, -8]
- Operator + (on 7 and -8) → \(7 + (-8) = -1\)
Final Result = -1
In simple words: Pop operands when an operator is encountered, perform the calculation, and push the result back.

Exam Tip: Always pop Operand2 first, then Operand1, for non-commutative operations like subtraction and division: \(\text{Op1} - \text{Op2}\).

 

Question 2 (continued). 2. E = 80, 35, 20, -, 25, 5, +, -, *
Answer:
- Push 80, 35, 20
- 35 - 20 = 15 → Stack: [80, 15]
- Push 25, 5
- 25 + 5 = 30 → Stack: [80, 15, 30]
- 15 - 30 = -15 → Stack: [80, -15]
- 80 * (-15) = -1200
Final Result = -1200
In simple words: Systematic popping and evaluation lead straight to the final arithmetic value.

Question 2 (continued). 3. E = 30, 5, 2, ^, 12, 6, /, +, -
Answer:
- Push 30, 5, 2
- 5 ^ 2 = 25 → Stack: [30, 25]
- Push 12, 6
- 12 / 6 = 2 → Stack: [30, 25, 2]
- 25 + 2 = 27 → Stack: [30, 27]
- 30 - 27 = 3
Final Result = 3
In simple words: Exponentiation is evaluated first among the operands present.

Exam Tip: Verify exponentiation rules carefully (\(5^2 = 25\), not 10).

 

Question 2 (continued). 4. E = 15, 3, 2, +, /, 7, +, 2, *
Answer:
- Push 15, 3, 2
- 3 + 2 = 5 → Stack: [15, 5]
- 15 / 5 = 3 → Stack: [3]
- Push 7 → Stack: [3, 7]
- 3 + 7 = 10 → Stack: [10]
- Push 2 → Stack: [10, 2]
- 10 * 2 = 20
Final Result = 20
In simple words: Follow the strict sequence of incoming tokens from left to right.

Exam Tip: Double check division order: 15 / (3 + 2) = 15 / 5 = 3.

 

Question 3. An array A[40][10] is stored in the memory along the column with each element occupying 4 bytes. Find out the address of the location A[3][6] if the location A[30][10] is stored at the address 9000.
Answer:
For a column-major two-dimensional array \(A[M][N]\):
Address of \(A[I][J] = \text{base address} + (J \times M + I) \times \text{sizeof(type)}\)
Here, \(M = 40, N = 10, \text{sizeof(type)} = 4\) bytes.
Given address of \(A[30][10] = 9000\). Note: Row index goes from 0 to 39, column index from 0 to 9. Wait, the question specifies \(A[30][10]\), let us compute using indices \(I = 30, J = 9\) or as given \(I = 30, J = 10\). Assuming standard indexing where column is 9, let's use the exact formula with given coordinates:
\(\text{Address}(A[30][10]) = \text{base address} + (10 \times 40 + 30) \times 4 = 9000\)
\(9000 = \text{base address} + (400 + 30) \times 4\)
\(9000 = \text{base address} + 430 \times 4\)
\(9000 = \text{base address} + 1720\)
Base Address = \(9000 - 1720 = 7280\)
Now, find address of \(A[3][6]\) where \(I = 3, J = 6\):
\(\text{Address}(A[3][6]) = 7280 + (6 \times 40 + 3) \times 4\)
\(= 7280 + (240 + 3) \times 4\)
\(= 7280 + 243 \times 4\)
\(= 7280 + 972 = 8252\)
Final Address = 8252
In simple words: First find the base address using the given location, then apply the column-major formula to find the target address.

Exam Tip: In column-major order, the column index multiplies the total number of rows (\(J \times M + I\)).

 

Question 4. Define functions in C++ to perform a PUSH and POP operation in a dynamically allocated stack considering the following:
struct Node
{ int X,Y;
Node *Link; };
class STACK
{ Node * Top;
public:
STACK( ) { TOP=NULL;}
void PUSH( );
void POP( );
~STACK( );
};
Answer:
void STACK::PUSH()
{
Node *p = new Node;
cout << "Enter X and Y: ";
cin >> p->X >> p->Y;
p->Link = TOP;
TOP = p;
}

void STACK::POP()
{
if(TOP == NULL)
{
cout << "Stack Underflow \n";
}
else
{
Node *t = TOP;
TOP = TOP->Link;
cout << "Deleted: " << t->X << ", " << t->Y << endl;
delete t;
}
}
In simple words: PUSH creates a new node at the top, while POP removes the topmost node and frees memory.

Exam Tip: Always check for overflow (new returning NULL) and underflow (TOP == NULL) in dynamic structures.

 

Question 5. Write a function in C++ to perform a Add and Delete operation in a dynamically allocated Queue considering the following:
struct node
{ int empno; char name[20]; float sal;
Node *Link;
};
Answer:
class Queue {
Node *front, *rear;
public:
Queue() { front = rear = NULL; }
void Add();
void Delete();
};

void Queue::Add()
{
Node *p = new Node;
cout << "Enter empno, name, sal: ";
cin >> p->empno >> p->name >> p->sal;
p->Link = NULL;
if(rear == NULL)
{
front = rear = p;
}
else
{
rear->Link = p;
rear = p;
}
}

void Queue::Delete()
{
if(front == NULL)
{
cout << "Queue Underflow\n";
}
else
{
Node *t = front;
front = front->Link;
if(front == NULL) rear = NULL;
cout << "Deleted Employee Number: " << t->empno << endl;
delete t;
}
}
In simple words: Elements are added at the rear and deleted from the front in a linked queue.

Exam Tip: Handle the edge case when the queue becomes completely empty (setting both front and rear to NULL).

 

A data structure provides an organized mechanism for storing, managing, and manipulating data within a computer system to ensure optimal computational efficiency. Varied data structures cater to distinct operational requirements. For instance, execution call stacks manage function invocations, whereas B-trees support database index lookups. Data structures generally fall into two broad classifications:

  • Simple Data Structure: Constructed directly from primitive types such as integers, floating-point values, and characters (for example, individual arrays and structures).
  • Compound Data Structure: Formed by assembling simple data structures into sophisticated, higher-level architectures. Common compound structures include linked lists, stacks, queues, and trees.

Data Structure Arrays

An array represents a contiguous, indexed collection of a fixed number of homogeneous data items. Standard operations supported on arrays include:

  • Creation: Allocating contiguous storage of a specified capacity.
  • Insertion: Appending or placing a new element at a defined position.
  • Deletion: Removing an existing element and adjusting remaining elements.
  • Searching: Locating the index of a targeted key element.
  • Traversal: Sequentially visiting every element to perform an operation (such as printing or accumulation).
  • Sorting: Ordering items in ascending or descending sequence.
  • Merging: Combining two separate arrays into a single composite array.

In C++, an array is declared using the syntax:

Here, size defines the fixed capacity of the allocated memory block. For example:

When an array is partially initialized at declaration, such as int b[10] = {3, 5, 7, 8, 9};, the specified entries occupy the initial indices (from 0 to 4), while the remaining unfilled locations (indices 5 through 9) automatically default to zero.

Indexb[0]b[1]b[2]b[3]b[4]b[5]b[6]b[7]b[8]b[9]
Value3578900000

Searching Algorithms

Searching is the algorithmic procedure of scanning an array to locate a target element. The two primary approaches are:

1. Linear Search: Every entry is systematically inspected from the beginning index onward until a match is detected or the end of the array is reached. It operates on both sorted and unsorted collections.

  • Best Case: Target is located at index 0 (1 comparison).
  • Worst Case: Target is at the final index or absent altogether (\( n \) comparisons).
  • Average Case: Target is found near the middle (\( n/2 \) comparisons).

2. Binary Search: Applicable exclusively to sorted arrays. The search segment is repeatedly halved by contrasting the target key with the middle element:

  • If the target matches the midpoint, the search terminates successfully.
  • If the target is smaller than the midpoint value, the search continues in the left subarray (indices first to middle - 1).
  • If the target is larger, the search continues in the right subarray (indices middle + 1 to last).
  • For an array of size \( N \), binary search requires at most \( \lceil \log_2 N \rceil \) comparisons, making it drastically faster than linear search for substantial datasets (for instance, around 10 comparisons versus 1000 comparisons for \( N = 1000 \)).

Array Insertion and Deletion

Insertion into a Sorted Array: To maintain sorting order without re-sorting the whole structure, elements exceeding the incoming value must shift rightward by one slot to vacate an insertion position.

Deletion from a Sorted Array: Once the target value is identified and removed, all subsequent higher-indexed elements must shift leftward by one slot to close the gap, decrementing the effective element count by one.

Sorting Algorithms

  • Selection Sort: Iteratively identifies the minimum item remaining in the unsorted portion and exchanges it with the first unsorted position. Regardless of the initial order (best, average, or worst case), selection sort always carries out \( \frac{n(n - 1)}{2} \) comparisons.
  • Insertion Sort: Divides the array conceptually into sorted and unsorted segments. In each pass, the first item from the unsorted segment is lifted and shifted into its correct relative position within the sorted segment. It executes with high efficiency on pre-sorted or nearly-sorted data, requiring only \( n - 1 \) comparisons in the best case.
  • Bubble Sort: Sequentially compares contiguous pairs of elements (a[i] and a[i+1]), swapping them if they violate the intended order. Each pass bubbles the largest unsorted element to its terminal position. The algorithm terminates early if an entire pass executes with zero swaps.

Two-Dimensional Arrays: Memory Storage Layouts

Because physical computer memory is strictly linear (one-dimensional), multi-dimensional arrays must be flattened using a standardized mapping convention:

1. Row-Major Order (RMO): Used by languages like C and C++. Elements are positioned row by row in continuous succession.

For an array declared as A[M][N] with base address B, row index I, column index J, and element size W bytes:

\[ \text{Address}(A[I][J]) = B + (I \times N + J) \times W \]

For generalized lower bounds \( L_1 \le I \le U_1 \) and \( L_2 \le J \le U_2 \):

\[ \text{Address}(A[I][J]) = B + [(I - L_1) \times N + (J - L_2)] \times W \]

2. Column-Major Order (CMO): Used by languages such as Fortran and MATLAB. Elements are stored column by column in continuous memory.

For an array A[M][N] with M rows:

\[ \text{Address}(A[I][J]) = B + (J \times M + I) \times W \]

For generalized lower bounds:

\[ \text{Address}(A[I][J]) = B + [(J - L_2) \times M + (I - L_1)] \times W \]

Worked Address Calculation Examples

Row-Major Example: Given A[10][20], element size = 4 bytes, Base = 5000. Finding address of A[3][5]:

\[ \text{Address}(A[3][5]) = 5000 + (3 \times 20 + 5) \times 4 = 5000 + 65 \times 4 = 5000 + 260 = 5260 \]

Column-Major Example: Given A[10][20], element size = 4 bytes, Base = 5000. Finding address of A[3][5]:

\[ \text{Address}(A[3][5]) = 5000 + (5 \times 10 + 3) \times 4 = 5000 + 53 \times 4 = 5000 + 212 = 5212 \]

4 Marks Questions

Question 1. Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having even values with its half and elements having odd values with twice its value
Answer: We iterate through the array from index 0 to size - 1. For each entry, we test whether its numerical value is divisible by 2. If it is even, we assign it half its original value; otherwise, if odd, we double it.

 

In simple words: The function checks every number in the list. Even numbers are divided by two, while odd numbers are multiplied by two.

Exam Tip: Be sure to check the element value arr[i] % 2 rather than the index i % 2 when deciding to modify array content.

Question 2. Write a function in C++ which accepts an integer array and its size as argument and exchanges the value of first half side elements with the second half side elements of the array. Example: If an array of eight elements has initial content as 2,4,1,6,7,9,23,10. The function should rearrange the array as 7,9,23,10,2,4,1,6.
Answer: We determine the midpoint boundary using integer division (mid = size / 2). A loop then traverses the first half of the array (from index 0 to mid - 1) and swaps each element with its counterpart located at an offset of mid positions ahead.

 

In simple words: The code pairs each element in the first half with the matching element in the second half and swaps them using a temporary variable.

Exam Tip: For even-sized arrays, the partner of element i is simply i + size/2. Always verify swap logic with both halves clearly separated.

Question 3. Write a function in c++ to find and display the sum of each row and each column of 2 dimensional array. Use the array and its size as parameters with int as the data type of the array.
Answer: We implement nested loops to calculate the cumulative total of each row and each column independently. The outer loop of the row-sum computation traverses rows while its inner loop aggregates across columns. Conversely, the column-sum routine iterates column by column on the outer level.

 

In simple words: Add up the numbers along each horizontal row, and then separately add up the numbers along each vertical column.

Exam Tip: Remember to reset the accumulator variable (rSum = 0 or cSum = 0) inside the outer loop so each line starts totaling from zero.

Question 4. Write a function in C++, which accepts an integer array and its size as parameters and rearrange the array in reverse. Example if an array of five members initially contains the elements as 6,7,8,13,9,19 Then the function should rearrange the array as 19,9,13,8,7,6
Answer: We use two pointers or a loop stepping up to size / 2. In each step, the element at index i is swapped with the symmetrical element from the rear at index size - 1 - i.

 

In simple words: Take numbers from the outer ends, swap them, and work toward the middle until the whole array is flipped.

Exam Tip: Ensure the loop stops strictly at size / 2. Running the loop all the way to size would reverse the array twice, restoring original positions.

Question 5. Write a function in C++, which accept an integer array and its size as arguments and swap the elements of every even location with its following odd location. Example : if an array of nine elements initially contains the elements as 2,4,1,6,5,7,9,23,10 Then the function should rearrange the array as 4,2,6,1,7,5,23,9,10
Answer: We iterate through the array advancing the index counter by increments of 2 (i += 2). Provided that index i + 1 lies within the bounds of the array (i + 1 < size), we exchange the element at index i with the element at index i + 1. If the array has an odd count, the trailing element remains untouched.

 

In simple words: Move along the array in pairs of two, swapping each pair while leaving any single leftover element at the end as is.

Exam Tip: Using the loop boundary condition i + 1 < size avoids out-of-bounds memory access on arrays with an odd length.

Question 6. Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having odd values with thrice and elements having even values with twice its value. Example: If an array of five elements initially contains the elements 3,4,5,16,9 Then the function should rearrange the content of the array as 9,8,15,32,27
Answer: We inspect every item in the array via a linear pass. If an item is odd, we multiply it by 3; if an item is even, we multiply it by 2.

 

In simple words: Check each number in the array. If it cannot be halved evenly, multiply it by 3; otherwise, double it.

Exam Tip: Test the condition using arr[i] % 2 != 0 for odd values, ensuring negative integers are also recognized correctly.

Stacks, Queues and Linked List

Stack Architecture

A stack is a linear collection governed by the Last-In, First-Out (LIFO) protocol. All insertions and removals occur at a single accessible end termed the top. The two foundational operations are:

  • Push: Inserts an element on top of the stack. An attempt to push onto a full capacity container triggers a stack overflow.
  • Pop: Removes and retrieves the topmost element. An attempt to pop from an empty container triggers a stack underflow.

Linked List Concept

A singly-linked list comprises a chain of dynamically allocated nodes. Each node encapsulates two fields: an information payload (data) and a pointer variable (next) containing the heap memory address of the succeeding node. The terminal node points to NULL.

Unlike arrays which necessitate contiguous blocks, linked lists allocate memory dynamically on demand, permitting efficient insertions and deletions without element shifting.

Expression Notations and Stack Applications

  • Infix: Operators sit between operands (e.g., \( A + B \)).
  • Postfix (Reverse Polish): Operators follow their operands (e.g., \( A B + \)). Parentheses are completely unnecessary in postfix form.
  • Prefix (Polish): Operators precede their operands (e.g., \( + A B \)).

Infix to Postfix Conversion Summary Table

For the expression: (A + B) * (C - D) / E

Scanned SymbolStack Contents (Top at Right)Postfix Expression
(( 
(( ( 
A( (A
+( ( +A
B( ( +A B
)(A B +
*( *A B +
(( * (A B +
C( * (A B + C
-( * ( -A B + C
D( * ( -A B + C D
)( *A B + C D -
/( /A B + C D - *
E( /A B + C D - * E
)EmptyA B + C D - * E /

Postfix Expression Evaluation Trace Table

Evaluating: 8, 2, +, 5, 3, -, *, 4, /

Token ScannedOperation PerformedStack Status (Top at Right)
8Push(8)8
2Push(2)8, 2
+Op2 = 2, Op1 = 8; Push(8 + 2 = 10)10
5Push(5)10, 5
3Push(3)10, 5, 3
-Op2 = 3, Op1 = 5; Push(5 - 3 = 2)10, 2
*Op2 = 2, Op1 = 10; Push(10 * 2 = 20)20
4Push(4)20, 4
/Op2 = 4, Op1 = 20; Push(20 / 4 = 5)5

Final evaluated result = 5.

Queue Architecture

A queue is a First-In, First-Out (FIFO) linear data structure featuring two separate access endpoints:

  • Rear: The point of entry where new items are appended (enqueue/insertion).
  • Front: The exit point where items are removed (dequeue/deletion).

Linear Queue Limitation: In linear array implementations, both pointers advance unidirectionally. When rear reaches size - 1, no subsequent insertions can proceed even if preceding deletions have vacated substantial room. This false overflow issue is cleanly solved by either:

  1. Circular Queues: Using modular arithmetic ((rear + 1) % size) to wrap around unused slots.
  2. Linked List Queues: Dynamically allocating and deallocating memory blocks on the heap.

2, 3 & 4 Marks Practice Questions

Question 1. Convert the following infix expressions to postfix expressions using stack
(i) A + (B * C) ^ D – (E / F – G)
(ii) A * B / C * D ^ E * G / H
(iii) ((A*B)-((C_D)*E/F)*G
Answer:
(i) Conversion of A + (B * C) ^ D - (E / F - G):
1. Scan A: Output = A
2. Scan +: Push to stack [+]
3. Scan (: Push to stack [+, (]
4. Scan B: Output = A B
5. Scan *: Push to stack [+, (, *]
6. Scan C: Output = A B C
7. Scan ): Pop * to output. Stack = [+]. Output = A B C *
8. Scan ^: Higher precedence than +. Push to stack [+, ^]
9. Scan D: Output = A B C * D
10. Scan -: Has lower precedence than ^ and equal precedence to +. Pop ^, then pop + to output. Push -. Stack = [-]. Output = A B C * D ^ +
11. Scan (: Push to stack [-, (]
12. Scan E: Output = A B C * D ^ + E
13. Scan /: Push to stack [-, (, /]
14. Scan F: Output = A B C * D ^ + E F
15. Scan -: Lower precedence than /. Pop / to output. Push -. Stack = [-, (, -]. Output = A B C * D ^ + E F /
16. Scan G: Output = A B C * D ^ + E F / G
17. Scan ): Pop - to output. Stack = [-]. Output = A B C * D ^ + E F / G -
18. End of expression: Pop remaining - from stack.
Resulting Postfix Expression: A B C * D ^ + E F / G - -

(ii) Conversion of A * B / C * D ^ E * G / H:
Operators * and / associate left-to-right, while exponentiation ^ takes strictly higher precedence.
1. A * B yields A B *
2. / C pops * and yields A B * C /
3. Next * D ^ E processes D ^ E first (yielding D E ^), which then multiplies to produce A B * C / D E ^ *
4. * G produces A B * C / D E ^ * G *
5. / H produces A B * C / D E ^ * G * H /
Resulting Postfix Expression: A B * C / D E ^ * G * H /

(iii) Conversion of ((A*B)-((C-D)*E/F)*G:
Interpreting the character _ as the subtraction operator - and balancing the trailing delimiter:
1. (A * B) converts to A B *
2. (C - D) * E / F converts to C D - E * F /
3. Multiplying by G converts to C D - E * F / G *
4. Subtracting from the initial product yields: A B * C D - E * F / G * -
Resulting Postfix Expression: A B * C D - E * F / G * -
In simple words: Operands are emitted immediately to output while operators wait on the stack until higher or equal precedence tokens clear them out.

Exam Tip: Always show the stack status column and the generated postfix output side-by-side in a table to earn full method marks.

Question 2. Evaluate the following postfix expression E given below; show the contents of the stack during the evaluation
(i) E= 5,9,+2,/,4,1,1,3,_,*,+
(ii) E= 80,35,20,-,25,5,+,-,*
(iii) E= 30,5,2,^,12,6,/,+,-
(iv) E=15, 3, 2, +, /, 7, + 2, *
Answer:
(i) For expression 5, 9, +, 2, /, 4, 1, 1, 3, -, *, + (where _ denotes subtraction -):
- Push 5, Push 9 → Stack: [5, 9]
- Scan +: Pop 9, 5; Push 5 + 9 = 14 → Stack: [14]
- Push 2 → Stack: [14, 2]
- Scan /: Pop 2, 14; Push 14 / 2 = 7 → Stack: [7]
- Push 4, Push 1, Push 1, Push 3 → Stack: [7, 4, 1, 1, 3]
- Scan -: Pop 3, 1; Push 1 - 3 = -2 → Stack: [7, 4, 1, -2]
- Scan *: Pop -2, 1; Push 1 * (-2) = -2 → Stack: [7, 4, -2]
- Scan +: Pop -2, 4; Push 4 + (-2) = 2 → Stack: [7, 2]
Final remaining pair evaluates with trailing operation to 9 (or top value = 2).

(ii) For expression 80, 35, 20, -, 25, 5, +, -, *:
- Push 80, Push 35, Push 20 → Stack: [80, 35, 20]
- Scan -: Pop 20, 35; Push 35 - 20 = 15 → Stack: [80, 15]
- Push 25, Push 5 → Stack: [80, 15, 25, 5]
- Scan +: Pop 5, 25; Push 25 + 5 = 30 → Stack: [80, 15, 30]
- Scan -: Pop 30, 15; Push 15 - 30 = -15 → Stack: [80, -15]
- Scan *: Pop -15, 80; Push 80 * (-15) = -1200 → Stack: [-1200]
Final result = -1200.

(iii) For expression 30, 5, 2, ^, 12, 6, /, +, -:
- Push 30, Push 5, Push 2 → Stack: [30, 5, 2]
- Scan ^: Pop 2, 5; Push \( 5^2 = 25 \) → Stack: [30, 25]
- Push 12, Push 6 → Stack: [30, 25, 12, 6]
- Scan /: Pop 6, 12; Push 12 / 6 = 2 → Stack: [30, 25, 2]
- Scan +: Pop 2, 25; Push 25 + 2 = 27 → Stack: [30, 27]
- Scan -: Pop 27, 30; Push 30 - 27 = 3 → Stack: [3]
Final result = 3.

(iv) For expression 15, 3, 2, +, /, 7, +, 2, *:
- Push 15, Push 3, Push 2 → Stack: [15, 3, 2]
- Scan +: Pop 2, 3; Push 3 + 2 = 5 → Stack: [15, 5]
- Scan /: Pop 5, 15; Push 15 / 5 = 3 → Stack: [3]
- Push 7 → Stack: [3, 7]
- Scan +: Pop 7, 3; Push 3 + 7 = 10 → Stack: [10]
- Push 2 → Stack: [10, 2]
- Scan *: Pop 2, 10; Push 10 * 2 = 20 → Stack: [20]
Final result = 20.
In simple words: When a number arrives, place it on the stack. When an operator arrives, pop the top two numbers, apply the math, and push the answer back.

Exam Tip: Be careful with operand order during division and subtraction: the first popped number is Operand2 and the second is Operand1; compute Operand1 - Operand2.

Question 3. An array A[40][10] is stored in the memory along the column with each element occupying 4 bytes. Find out the address of the location A[3][6] if the location A[30][10] is stored at the address 9000.
Answer: Given data:
Dimensions of array: M = 40 (rows), N = 10 (columns)
Element size: W = 4 bytes
Storage order: Column-Major Order (CMO)
Reference location: Address(A[30][10]) = 9000
Target location: Address(A[3][6]) = ?

Case 1: Assuming 1-based indexing (where row indices run 1..40 and columns run 1..10):
The address formula in Column-Major Order is:
\[ \text{Address}(A[I][J]) = \text{Base} + [(J - 1) \times M + (I - 1)] \times W \]
Substitute the reference coordinates \( I = 30, J = 10 \):
\[ 9000 = \text{Base} + [(10 - 1) \times 40 + (30 - 1)] \times 4 \]
\[ 9000 = \text{Base} + [9 \times 40 + 29] \times 4 \]
\[ 9000 = \text{Base} + [360 + 29] \times 4 = \text{Base} + 389 \times 4 \]
\[ 9000 = \text{Base} + 1556 \implies \text{Base} = 9000 - 1556 = 7444 \]
Now, compute the address of target location \( A[3][6] \):
\[ \text{Address}(A[3][6]) = 7444 + [(6 - 1) \times 40 + (3 - 1)] \times 4 \]
\[ = 7444 + [5 \times 40 + 2] \times 4 = 7444 + 202 \times 4 \]
\[ = 7444 + 808 = 8252 \]

Case 2: Direct address displacement method (independent of base address):
\[ \text{Address}(A[3][6]) = \text{Address}(A[30][10]) + [(6 - 10) \times 40 + (3 - 30)] \times 4 \]
\[ = 9000 + [-4 \times 40 + (-27)] \times 4 \]
\[ = 9000 + [-160 - 27] \times 4 = 9000 + (-187) \times 4 = 9000 - 748 = 8252 \]
Thus, the address of location \( A[3][6] \) is 8252.
In simple words: Since elements are grouped by columns, count how many complete columns and row spaces sit between the two cells, multiply by 4 bytes, and adjust from 9000.

Exam Tip: Using the direct offset formula between two locations eliminates potential arithmetic slips when finding the base address.

Question 4. Define functions in C++ to perform a PUSH and POP operation in a dynamically allocated stack considering the following :
 


Answer: We implement PUSH() to dynamically allocate a new Node on the heap, assign values to members X and Y, link the node to the existing top of the stack, and update Top. The POP() function verifies underflow, extracts data from the topmost node, points Top to the next node, and releases the vacated node's memory using delete.

 

In simple words: PUSH creates a new node in memory and places it at the front of the list, while POP displays the front node's values and deletes it to free memory.

Exam Tip: Never forget to verify Top == NULL inside POP() before accessing node pointers to prevent segmentation faults.

Question 5. Write a function in C++ to perform a Add and Delete operation in a dynamically allocated Queue considering the following:
 


Answer: In a linked queue, dynamic insertion (Add / Enqueue) occurs at the rear pointer, whereas removal (Delete / Dequeue) happens at the front pointer. If the queue is empty, both pointers reference the newly allocated first node.

 

In simple words: Add attaches a new node to the back using the rear pointer, while Delete removes the oldest node from the front and releases its memory.

Exam Tip: Remember to reset rear = NULL when the last remaining node is deleted and front becomes NULL.

In Computer Science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks. For example, Stacks are used in function call during execution of a program, while B-trees are particularly well-suited for implementation of databases. The data structure can be classified into following two types: Simple Data Structure: These data structures are normally built from primitive data types like integers, floats, characters. For example arrays and structure. Compound Data Structure: simple data structures can be combined in various ways to form more complex structure called compound structures. Linked Lists, Stack, Queues and Trees are examples of compound data structure.

Data Structure Arrays

Data structure array is defined as linear sequence of finite number of objects of same type with following set of operation:

¶ Creating : defining an array of required size

¶ Insertion: addition of a new data element in the in the array

¶ Deletion: removal of a data element from the array

¶ Searching: searching for the specified data from the array

¶ Traversing: processing all the data elements of the array

¶ Sorting : arranging data elements of the array in increasing or decreasing order

¶ Merging : combining elements of two similar types of arrays to form a new array of same type

In C++ an array can be defined as

Datatype arrayname[size];

Datatype arrayname[size];
float b[10]; // Allocates space for 10 floating-point numbers
int c[5];    // Allocates space for 5 integer numbers
void ModifyArray(int arr[], int size)
{
    for (int i = 0; i < size; i++)
    {
        if (arr[i] % 2 == 0)
        {
            arr[i] = arr[i] / 2;
        }
        else
        {
            arr[i] = arr[i] * 2;
        }
    }
}
void SwapHalves(int arr[], int size)
{
    int mid = size / 2;
    int shift = (size % 2 == 0) ? mid : (mid + 1);
    for (int i = 0; i < mid; i++)
    {
        int temp = arr[i];
        arr[i] = arr[i + shift];
        arr[i + shift] = temp;
    }
}
const int MAX = 50;

void RowColSum(int arr[][MAX], int rows, int cols)
{
    // Row-wise summation
    for (int i = 0; i < rows; i++)
    {
        int rSum = 0;
        for (int j = 0; j < cols; j++)
        {
            rSum += arr[i][j];
        }
        cout << "Sum of Row " << (i + 1) << " = " << rSum << endl;
    }

    // Column-wise summation
    for (int j = 0; j < cols; j++)
    {
        int cSum = 0;
        for (int i = 0; i < rows; i++)
        {
            cSum += arr[i][j];
        }
        cout << "Sum of Column " << (j + 1) << " = " << cSum << endl;
    }
}
void ReverseArray(int arr[], int size)
{
    for (int i = 0; i < size / 2; i++)
    {
        int temp = arr[i];
        arr[i] = arr[size - 1 - i];
        arr[size - 1 - i] = temp;
    }
}
void SwapAdjacent(int arr[], int size)
{
    for (int i = 0; i + 1 < size; i += 2)
    {
        int temp = arr[i];
        arr[i] = arr[i + 1];
        arr[i + 1] = temp;
    }
}
void TransformElements(int arr[], int size)
{
    for (int i = 0; i < size; i++)
    {
        if (arr[i] % 2 != 0)
        {
            arr[i] = arr[i] * 3;
        }
        else
        {
            arr[i] = arr[i] * 2;
        }
    }
}
struct Node
{ int X,Y;
Node *Link; };
class STACK
{ Node * Top;
public:
STACK( ) { TOP=NULL;}
void PUSH( );
void POP( );
~STACK( );
};
void STACK::PUSH()
{
    Node *temp = new Node;
    if (temp == NULL)
    {
        cout << "Stack Overflow! Insufficient Memory." << endl;
        return;
    }
    cout << "Enter value for X: ";
    cin >> temp->X;
    cout << "Enter value for Y: ";
    cin >> temp->Y;
    
    temp->Link = Top;
    Top = temp;
    cout << "Node successfully pushed." << endl;
}

void STACK::POP()
{
    if (Top == NULL)
    {
        cout << "Stack Underflow! Stack is empty." << endl;
        return;
    }
    Node *temp = Top;
    cout << "Popped Node elements: X = " << temp->X << ", Y = " << temp->Y << endl;
    Top = Top->Link;
    delete temp;
}
struct node
{ int empno ;char name[20] ;float sal ;
Node *Link;
};
class QUEUE
{
    node *front, *rear;
public:
    QUEUE()
    {
        front = NULL;
        rear = NULL;
    }
    void Add();
    void Delete();
};

void QUEUE::Add()
{
    node *temp = new node;
    if (temp == NULL)
    {
        cout << "Queue Overflow! Out of memory." << endl;
        return;
    }
    cout << "Enter Employee No: ";
    cin >> temp->empno;
    cout << "Enter Name: ";
    cin >> temp->name;
    cout << "Enter Salary: ";
    cin >> temp->sal;
    temp->Link = NULL;

    if (rear == NULL)
    {
        front = temp;
        rear = temp;
    }
    else
    {
        rear->Link = temp;
        rear = temp;
    }
    cout << "Record inserted successfully." << endl;
}

void QUEUE::Delete()
{
    if (front == NULL)
    {
        cout << "Queue Underflow! Queue is empty." << endl;
        return;
    }
    node *temp = front;
    cout << "Deleted Employee Details:" << endl;
    cout << "Emp No: " << temp->empno << ", Name: " << temp->name << ", Salary: " << temp->sal << endl;
    
    front = front->Link;
    if (front == NULL)
    {
        rear = NULL;
    }
    delete temp;
}

Chapter Assignment & Practice Material for Class 12 Computer Science Data Structures Concepts

Chapter Practice Questions for Class 12 Computer Science

Access structured practice assignments for Data Structures Concepts designed in alignment with the latest CBSE curriculum for Class 12 Computer Science. These printable sets cover objective and descriptive problem types to support thorough revision.

Why Practice Class 12 Computer Science Assignments?

  • Curriculum Standards: Assignments match modern CBSE sample formats to ensure relevant preparation.
  • Thorough Revision: Detailed problem sets reinforce core concepts and eliminate conceptual weak spots.
  • Execution Speed: Timed practice with assignment sets sharpens overall response timing.

Effective Strategy for Class 12 Computer Science Assignments

  1. Initial Reading: Begin by reading the NCERT book for Class 12 Computer Science to build a baseline understanding.
  2. Independent Testing: Attempt assignment questions unassisted, then verify work using provided answer keys.
  3. Supplementary Aids: Leverage revision notes and worksheets whenever you encounter difficult topics.

FAQs

Where can I download the latest CBSE Class 12 Computer Science Data Structures Concepts assignments?

You can download free PDF assignments for Class 12 Computer Science Data Structures Concepts from StudiesToday.com. These practice sheets have been updated for the 2026-27 session covering all concepts from latest NCERT textbook.

Do these Computer Science Data Structures Concepts assignments include solved questions?

Yes, our teachers have given solutions for all questions in the Class 12 Computer Science Data Structures Concepts assignments. This will help you to understand step-by-step methodology to get full marks in school tests and exams.

Are the assignments for Class 12 Computer Science Data Structures Concepts based on the 2026 exam pattern?

Yes. These assignments are designed as per the latest CBSE syllabus for 2026. We have included huge variety of question formats such as MCQs, Case-study based questions and important diagram-based problems found in Data Structures Concepts.

How can practicing Data Structures Concepts assignments help in Computer Science preparation?

Practicing topicw wise assignments will help Class 12 students understand every sub-topic of Data Structures Concepts. Daily practice will improve speed, accuracy and answering competency-based questions.

Can I download Computer Science Data Structures Concepts assignments for free on mobile?

Yes, all printable assignments for Class 12 Computer Science Data Structures Concepts are available for free download in mobile-friendly PDF format.