Refer to CBSE Class 12 Computer Science HOTs Data Structures. We have provided exhaustive High Order Thinking Skills (HOTS) questions and answers for Class 12 Computer Science Data Structures. Designed for the 2025-26 exam session, these expert-curated analytical questions help students master important concepts and stay aligned with the latest CBSE, NCERT, and KVS curriculum.
Data Structures Class 12 Computer Science HOTS with Solutions
Practicing Class 12 Computer Science HOTS Questions is important for scoring high in Computer Science. Use the detailed answers provided below to improve your problem-solving speed and Class 12 exam readiness.
HOTS Questions and Answers for Class 12 Computer Science Data Structures
ARRAYS
4 Marks Questions
An array is a simple data structure which can be used to store more than one
values of same data type. Memory allocation for array is continuous.
When ever we have to solve the single dimensional array problem we have to
draw the diagram of the array with any name say x, as shown below.
Based on the above diagram we can easily identify the position of each item in the array and can be able to make necessary logic as per the question given.
Q.1 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
Ans.Reversing means swap first element and last element, second first element and
second last element and so on.
void ReverseArray(int x[], int N)
{
int i,j,temp;
/* i for taking the elements from the beginning onwards, so initialize it with 0
and increment its value(i++). j for taking the elements from the end, so initialize
it with N-1 and decrement its value each time (j--) */
for(i=0,j=N-1;i<N/2;i++,j--)
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
cout<<"After reversing the Array elements are"<<endl;
for(i=0;i<N;i++)
{
cout<<x[i]<<" ";
}
}
Q.2 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
Q.3 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
for(int i=0;i<N;i++)
Q.4 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.
Q.5 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.
Ans.5. The exchanging is happening between the elements indicated by the line.
i.e. first element with next element from the middle point, second element with second element from the middle point etc.
If i for representing the first element and j for representing the element after the middle point then initially i=0 and j=N/2 and both will increment in each
step(i++ and j++).
void ChangeValue(int x[],int N)
{
int temp;
for(int i =0,j=N/2;i<N/2;i++,j++)
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
cout<<endl;
for(i=0;i<N;i++)
{
cout<<x[i]<<" ";
}
}
Q.6 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.
Ans 6
Actually we have to find the Sum of the elements in each row and sum of the elements in each column. Since in the above two dimensional array, three rows are there, so three sum will get and each sum will store in the array RS in the places RS[0], RS[1] and RS[2] respectively. Since column also contains three, three column sum will get and each will store in the array CS in the position CS[0], CS[1] and CS[2] respectively.
void FindRowColSum(int x[n][n],int R,int C)
{
int temp,CSum=0,RSum=0;
int CS[10],RS[10]; //for getting the Column sum and row sum
/* Whenever we process a 2D array, we need two for loop. Outer for loop for
processing row and inner for loop for processing the column */.
//********* Finding the Row Sum ************
for(i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
RSum=RSum+x[i][j]; // Adding the elements in
the same Rows. i denote the
row and its value is not
changing throughout this loop.
}
RS[i]=RSum; // Assining the Row sum to the array RS
RSum=0; //Making RSum Zero to assign the sum of the
// elements in the next row ;
}
cout<<" Printing the Row sum"<<endl ;
for(i=0;i<R;i++)
{
cout<<RS[i]<<" ";
}
cout<<endl;
// ************* Finding the Column sun ****************
/* Small changes are needed in the above code to find the column sum. They
are underlined */
for(i=0;i<C;i++)
{
for(int j=0;j<R;j++)
{
CSum=CSum+x[j][i]; // Adding the elements in the
// same Columns.
}
CS[i]=CSum; // Assigning the Column sum to the array CS
CSum=0; //Making CSum Zero to assign the sum of
//elements in the next column ;
}
cout<<"Printing the column sum"<<endl;
for(i=0;i<C;i++)
{
cout<<CS[i]<<" ";
}
Q.7 Write function SORTPOINTS() in c++ to sort an array of structure Game in descending order of points using Bubble Sort Note: Assume the following definition of structure Game
struct Game
{
long PNo; // Player Number
char PName[20];
long points;
};
Ans.7. You know bubble sort, in which we are using simple array. Here you are asked to sort structure array base on the element points. If in the normal array say x[10] , you are using x[i], here in the structure array say gm[10], you have to use gm[i].points because you are sorting based on the variable points in the structure Game
void SORTPOINTS()
{
Game gm[10];
Game temp;
Cout<<”Enter the details of 10 games”<<endl;
For(int i=0;i<10;i++)
{
Cin>>gm[i].PNo;
Gets(gm[i].PName);
Cin>>gm[i].points;
}
// Use the logic for bubble sort.
/*Points to note in bubble sort
1. Compare with the adjacent elements ie j and j+1
2. Bigger element goes to the top because the elements in the descending
order.
3. Each iteration the smaller elements comes in the bottom.*/
for(i=0;i<n;i++)
{
for(j=0;j<(n-1)-i;j++) // j< (N-1)-i , subtracting i to avoid the
// last elements which are in the correct order
// after each loop execution.
{
If(gm[j] .points <gm[j+].points)
{
temp=gm[j];
gm[j]=gm[j+1];
gm[j+1]=temp;
}
}
}
Q.8 Write a c++ function to shift all the negative numbers to left and positive number in the right side.
Ans.8 1.Take each element of the array from the beginning. say x[n]
2. Check x[n] is -ve or not. If it is negative number do the following steps
2. Check elements from the left side of x[n] and shift the left side element to
next right position if it is +ve number..
3. Repeat step 2 till you gets a negative number or till reach the left end of the
array.
4. Insert x[n].
void arrangeNegPosNumbers(int x[], int N)
{
for(i=0;i<5;i++)
{
temp=x[i]; // Taking each element in the array to
//check +ve or -ve
if(x[i]<0) // Checking it is -ve
{
j=i-1;
while(j>=0)
{
if(x[j]<0)
{
break;
}
else
{
x[j+1]=x[j]; // Shift +ve number
// to right
j--;
}
}
x[j+1]=temp; // Inserting the –ve number
}
}
}
Q.9 Define a function SWPCOL() in C++ to swap ( interchange) the first column elements with the last column elements, for a two dimensional array passed as the argument of the function.
Example : if the two dimensional array contains
Ans.9. void SWAPCOL(int x[n][n],int R,int C)
{
for(i=0;i<R;i++) // for each row
{
Int temp;
for(int j=0,k=C-1;j<C/2;j++,k--)
/* j for taking the elements from the first columns and k for taking the
elements from the last columns. So the initially j=0 and k=C-1 and j will
increase (j++) and k will decrease (k--) * in each step/
{
temp=x[i][j]; //Swap elements in the first and last
// columns
x[i][j]=x[i][k];
x[i][k]=temp;
}
}
for(i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
cout<<x[i][j]<<" ";
}
cout<<endl;
}
}
Q.10 Define a function SWPROW() in C++ to swap ( interchange) the first row elements with the last row elements, for a two dimensional array passed as the argument of the function.
Example : if the two dimensional array contains
After swapping of the content of the array will be
Ans.10. Only small changes have to make compare to the previous question , which are underlined and blackened.
void SWAPROW(int x[n][n], int R,intC)
{
int temp;
for(i=0;i<C;i++)
{
for(int j=0,k=R-1;j<R/2;j++,k--)
{
temp=x[j][i];
x[j][i]=x[k][i];
x[k][i]=temp;
}
}
for(i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
cout<<x[i][j]<<" ";
}
cout<<endl;
}
}
Q.11 Write a function in C++ to print the product of each column of a 2D integer array passed as the argument of the function
Example : if the two dimensional array contains
Then the output should appears as
Product of Column1 = 70
Product Column2 = 48
Product of column3= 168
Product of Column4=378
Ans.11. void FindColProd(int x[n][n],int R,int C)
{
int Cprod;
for(i=0;i<C;i++)
{
CProd=1;
for(int j=0;j<R;j++)
{
CProd= CProd * x[j][i];
}
cout<<"Product of the Column "<<i+1<<" is"<<CProd<<endl;
}
}
Q.12 Write a function in C++ to print the product of each row of a 2D integer array passed as the argument of the function Example : if the two dimensional array contains
Then the output should appears as
Product of Row1 = 72
Product Row2 = 147
Product of Row3= 720
Product of Row4=28
Ans.12. void FindRowProd(int x[n][n],int R,int C)
{
int Rprod;
for(i=0;i<R;i++)
{
RProd=1;
for(int j=0;j<C;j++)
{
RProd= RProd * x[i][j];
}
cout<<"Product of the Row "<<i+1<<" is"<<RProd<<endl;
}
}
Q.13. Write a function which accept 2D array of integers and its size as arguments and displays the sum of elements which lie on diagonals.
[Assuming the 2D array to be a square matrix with odd dimension ie 3 x 3 ,
4 x 4 etc ]
Example of the array content is
5 4 3
6 7 8
1 2 9
Output through the function should be
Diagonal One Sum : 21
Diagonal Two: 11
Ans.13. In first diagonal elements both row index and column index is same.
In second diagonal element row index is increasing and column index is decreasing.
void findDiagonalSum(int x[n][n],int R,int C)
{
// Find the sum of the First diagonal numbers
for(i=0;i<R;i++)
{
Sum1=Sum1+x[i][i]; // Row and Column are represented
// by i itself
}
// Find the sum of the Second diagonal elements
int j=C-1;
for(i=0;i<R;i++)
{
Sum2= Sum2+x[i][j];
j--;
}
cout<<endl;
cout<<Sum1<<endl;
cout<<Sum2;
}
Q.14. Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays the elements of middle row and the elements of middle column.
[Assuming the 2D array to be a square matrix with odd dimension ie 3 x 3 ,
5 x 5, 7 x 7 etc ]
Example of the array content is
5 4 3
6 7 8
1 2 9
Output through the function should be
Middle row: 6 7 9
Middle Column 4 7 2
Ans.14. The row number and Column number is odd numbers and both are same
The index of the middle row / column element is Row/2 or Column/2 void FindMiddle(int x[n][n], int size) // size represent No of rows and
//columns, since both are same.
{
// Find the element in the middle row
int j=size/2;
// Middle Row
for(i=0;i<size;i++)
{
cout<<x[j][i]<<” “;
}
// Middle Column
for(i=0;i<size;i++)
{
cout<<x[i][j]<<” “;
}
}
Note If the question is to find the sum of the middle row and sum of the middle
column, then the program should write as given below
void FindMiddleSum(int x[n][n], int size)
{
int Sum1=0,Sum2=0;
int j=size/2;
for(i=0;i<size;i++)
{
Sum1=Sum1+x[j][i];
Sum2=Sum2+x[i][j];
}
cout<<endl;
cout<<Sum1<<" "<<Sum2;
}
Q.15. Write a function in C++ which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format If the array is 1,2,3,4,5,6 if the array is 1,2,3
The resultant 2D array is The resultant 2D array is
1 2 3 4 5 6 1 2 3
1 2 3 4 5 0 1 2 0
1 2 3 4 0 0 1 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0
Ans.15. We are provided with 1D array and to make 2D array with the values provided in the ID array. By analyzing the 2D array(output) we will get the logic that for the position (i+j)< size of the 2D array, elements are taken from the ID array
and all other position value is zero. So the program is as below void Change2Darray(int x[],int size)
for(i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(i+j <size)
{
y[i][j]=x[j];
}
else
{
y[i][j]=0;
}
}
}
for(i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
cout<<y[i][j]<<" ";
}
cout<<endl;
}
}
Q.16. Write a function in C++ which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format If the array is 1,2,3,4,5,6 if the array is 1,2,3 The resultant 2D array is The resultant 2D array is
1 2 3 4 5 6 1 2 3
0 1 2 3 4 5 0 1 2
0 0 1 2 3 4 0 0 1
0 0 0 1 2 3
0 0 0 0 1 2
0 0 0 0 0 1
Ans.16. Condition for putting the value is the position (i<=j) of 2D array otherwise put zero
void Change2Darray(int x[],int size)
{
for(i=0;i<size;i++)
{
int k=0;
for(int j=0;j< size;j++)
{
if(i<=j)
{
y[i][j]=x[k];
k++;
}
else
{
y[i][j]=0;
}
}
}
for(i=0;i< size;i++)
{
for(int j=0;j< size;j++)
{
cout<<y[i][j]<<" ";
}
cout<<endl;
}
}
Q.17. Write a function in C++ which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format If the array is 1,2,3,4,5,6 if the array is 1,2,3
The resultant 2D array is The resultant 2D array is
1 0 0 0 0 0 1 0 0
1 2 0 0 0 0 1 2 0
1 2 3 0 0 0 1 2 3
1 2 3 4 0 0
1 2 3 4 5 0
1 2 3 4 5 6
Ans.17. Condition for putting the value is the position (i>=j) of 2D array otherwise put zero
void Change2Darray(int x[],int size)
{
for(i=0;i<size;i++)
{
for(int j=0;j< size;j++)
{
if(i>=j)
{
y[i][j]=x[j];
}
else
{
y[i][j]=0;
}
}
}
for(i=0;i< size;i++)
{
for(int j=0;j< size;j++)
{
cout<<y[i][j]<<" ";
}
cout<<endl;
}
}
Note All the above three cases only the condition is changing, which is darken and underlined.
18. Write a user defined function named upperhalf() which takes a 2D array A, with size n rows and n cols as arguments and print the upper half of the matrix. Example
1 2 3 1 2 3
6 7 8 7 8
2 3 4 4
Ans.18. void upperhalf(int x[n][n],int R,int C)
{
for(i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
if(i<=j)
{
cout<<x[i][j];
}
else
{
cout<<" ";
}
}
cout<<endl;
}
Q.19. Write a user defined function lowerhalf() which takes a 2D array, with size n rows and n cols as argument and prints the lower half of the matrix
Eg:-
1 2 3 1
5 6 7 5 6
9 1 2 9 1 2
Ans.19. void lowerhalf(int x[n]][n], int R,int C)
for(i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
if(i>=j)
{
cout<<x[i][j];
}
else
{
cout<<" ";
}
}
cout<<endl;
}
Q.20 Write the function to find the largest and second largest number from a two dimensional array. The function should accept the array and its size as argument.
Ans.20. void findLargestSecondLargest(int x[n][n], int R,int C)
{
int mx,s_,max;
max=x[0][0]; // Assuming x[0][0] as the largest element
s_max=x[0][0]; // Assuming x[0][0] as the Second largest element
for(i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
if(max<x[i][j]) // if element in the array (x[i][j]) is
// greater than content in the
//variable max
{
s_max=max; // content of the max will
// become the second largest element
max=x[i][j]; // x[i][j] becomes the largest element
}
else if(max>x[i][j] && s_max<x[i][j])
//if the element in the array is less than content of max but greater than s_mx
s_max=x[i][j]; // x[i][j] becomes the second largest
// element
}
}
}
cout<<endl;
cout<<"Maximun Number"<<max<<endl;
cout<<"Second Max Number"<<s_max<<endl;
}
Q.21 Write a function in C++ to merge the contents of two sorted arrays A & B into third array C. Assuming array A is sorted in ascending order, B is sorted in descending order, the resultant array is required to be in ascending order.
21. void AddNSave(int A[],int B[],int C[],int N,int M, int &K)
{
int I=0,J=M-1;
K=0;
while (I<N && J>=0)
{
if (A[I]<B[J])
C[K++]=A[I++];
else
if (A[I]>B[J])
C[K++]=B[J--];
else
{
C[K++]=A[I++];
J--;
}
}
for (int T=I;T<N;T++)
C[K++]=A[T];
for (T=J;T>=0;T--)
C[K++]=B[T];
}
Linked List, Stack, Queue
4 Mark Questions
Q.1 Write a function in C++ to perform a PUSH operation in a dynamically allocated stack considering the following:
struct node
{ int x,y;
Node *Link;
};
Ans.1. Insert at the beginning
void PUSH()
{
Node *newptr=new Node;
cin>>newptr->x;
cin>>newptr->y;
if(top==NULL) // Stack is empty
{
Top=newptr;
}
else
{
newptr->Link=start; // new node will point to the first node;
top=newptr; // New node becomes to the first node
}
}
Q.2 Write a function in C++ to perform a DELETE operation in a dynamically allocated queue considering the following description:
struct Node
{ float U,V;
Node *Link;
};
class QUEUE
{
Node *Rear, *Front;
public:
QUEUE( ) { Rear =NULL; Front= NULL;}
void INSERT ( );
void DELETE ( );
~QUEUE ( );
};
Ans.2. Hint : delete node from the beginning
void DELETE()
{
Node *temp;
if(front==NULL) // No element in the queue
{
cout<<”UNDERFLOW………………..”;
}
else
{ temp=front;
front=front->Link; // Making the second node as the first one
delete temp; // deleting the previous first node.
}
}
Q.3 Write a function in C++ to perform a PUSH 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( );
};
Ans.3. Insert new node as the first element
void PUSH()
{
Node *newptr=new Node;
cout<<”Enter the informations”<<endl;
cin>>newptr->X;
cin>>newptr->Y;
if(top==NULL) // Linked list is empty
{
Top=newptr // New node is the first node
}
else
{
newptr->Link=Top;
Top=newptr;
}
}
Q.4 Define function stackpush( ) to insert nodes and stackpop( ) to delete nodes, for a linked list implemented stack having the following structure for each node:
struct Node
{
char name[20];
int age;
Node *Link;
};
class STACK
{
Node * Top;
public:
STACK( ) { TOP=NULL;}
void stackpush( );
void stackpop( );
~STACK( );
};
Ans.4. Stackpush( ) is already done // Write yourself
void stackpop( ) // Pop from the beginning
{ Node *temp;
if(top==NULL)
{
cout<<”UNDERFLOW……………….”;
}
else
{
temp=Top;
Top=Top->Link;
delete temp;
}
}
| CBSE Class 12 Computer Science 1 Marks HOTs |
| CBSE Class 12 Computer Science HOTs Boolean Algebra |
| CBSE Class 12 Computer Science HOTs Communication and Network |
| CBSE Class 12 Computer Science HOTs Communication and Networking |
| CBSE Class 12 Computer Science HOTs Data Structures |
| CBSE Class 12 Computer Science HOTs Data Structures Set A |
| CBSE Class 12 Computer Science HOTs Database and SQL |
| CBSE Class 12 Computer Science HOTs Database and SQL |
Important Practice Resources for Class 12 Computer Science
HOTS for Data Structures Computer Science Class 12
Students can now practice Higher Order Thinking Skills (HOTS) questions for Data Structures to prepare for their upcoming school exams. This study material follows the latest syllabus for Class 12 Computer Science released by CBSE. These solved questions will help you to understand about each topic and also answer difficult questions in your Computer Science test.
NCERT Based Analytical Questions for Data Structures
Our expert teachers have created these Computer Science HOTS by referring to the official NCERT book for Class 12. These solved exercises are great for students who want to become experts in all important topics of the chapter. After attempting these challenging questions should also check their work with our teacher prepared solutions. For a complete understanding, you can also refer to our NCERT solutions for Class 12 Computer Science available on our website.
Master Computer Science for Better Marks
Regular practice of Class 12 HOTS will give you a stronger understanding of all concepts and also help you get more marks in your exams. We have also provided a variety of MCQ questions within these sets to help you easily cover all parts of the chapter. After solving these you should try our online Computer Science MCQ Test to check your speed. All the study resources on studiestoday.com are free and updated for the current academic year.
You can download the teacher-verified PDF for CBSE Class 12 Computer Science HOTs Data Structures from StudiesToday.com. These questions have been prepared for Class 12 Computer Science to help students learn high-level application and analytical skills required for the 2025-26 exams.
In the 2026 pattern, 50% of the marks are for competency-based questions. Our CBSE Class 12 Computer Science HOTs Data Structures are to apply basic theory to real-world to help Class 12 students to solve case studies and assertion-reasoning questions in Computer Science.
Unlike direct questions that test memory, CBSE Class 12 Computer Science HOTs Data Structures require out-of-the-box thinking as Class 12 Computer Science HOTS questions focus on understanding data and identifying logical errors.
After reading all conceots in Computer Science, practice CBSE Class 12 Computer Science HOTs Data Structures by breaking down the problem into smaller logical steps.
Yes, we provide detailed, step-by-step solutions for CBSE Class 12 Computer Science HOTs Data Structures. These solutions highlight the analytical reasoning and logical steps to help students prepare as per CBSE marking scheme.