CBSE Class 12 Computer Science HOTs Data Structures

Please refer to CBSE Class 12 Computer Science HOTs Data Structures. Download HOTS questions and answers for Class 12 Computer Science. Read CBSE Class 12 Computer Science HOTs for Data Structures below and download in pdf. High Order Thinking Skills questions come in exams for Computer Science in Class 12 and if prepared properly can help you to score more marks. You can refer to more chapter wise Class 12 Computer Science HOTS Questions with solutions and also get latest topic wise important study material as per NCERT book for Class 12 Computer Science and all other subjects for free on Studiestoday designed as per latest CBSE, NCERT and KVS syllabus and pattern for Class 12

Data Structures Class 12 Computer Science HOTS

Class 12 Computer Science students should refer to the following high order thinking skills questions with answers for Data Structures in Class 12. These HOTS questions with answers for Class 12 Computer Science will come in exams and help you to score good marks

HOTS Questions Data Structures Class 12 Computer Science with Answers

 

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.

class_12_computer%20science_hot_1

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

CBSE_ Class_12_Array_1

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

Ans.2. In this problem you have to take care of two situation.
1. Even number of elements in the array

CBSE_ Class_12_Array_2

 

In the above case x[0] and x[1] are replacing, x[2] and x[3] are replacing and x[4] and x[5] are replacing. Ie exact pair of elements are in the array.
2. Odd number of elements in the array

CBSE_ Class_12_Array_3

 

In the above case x[0] and x[1] are replacing, x[2] and x[3] are replacing and x[4] and x[5] are replacing and last one need not to be replaced because it has no pair. ie. in the case of odd number of elements the limit of the for loop is one
less than the loop for the even number of elements 
void ChangeOrder(int x[], int N) 
int i,j,temp,limit; 
if(N%2!=2) 
{
limit=N-1; 
else 
limit=N; 
for(i=0;i<limit;i+=2) 
temp=x[i]; 
x[i]=x[i+1]; 
x[i+1]=temp; 
for(i=0;i<N;i++) 
cout<<x[i]; 
}
}

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 

Ans.3. void ChangeValue(int x[],int N) 
{

 for(int i=0;i<N;i++) 

if(x[i]%2!=0) // Checking the element is Odd or not 
x[i]=x[i]*3; 
else
{
x[i]=x[i]*2;
}
}
cout<<endl;
for(i=0;i<N;i++)
{
cout<<x[i]<<" ";
}
}
Note: If the Question is to make element in the odd position to thrice its value and element in the even position to twice its value, then you have to make only one change in the above program to get the answer ie
If( (i+1)%2!=0) instead of if(x[i]%2 !=0)

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. 

Ans.4. If (x[i]%2==0) 
x[i]=x[i]/2; 
else 
x[i]=x[i]*2; 
}

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.

CBSE_ Class_12_Array_4

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

CBSE_ Class_12_Array_5

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

CBSE_ Class_12 Data_Structurel_1

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

CBSE_ Class_12_Data_Structurel_2

After swapping of the content of the array will be

CBSE_ Class_12_Data_Structurel_3

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

CBSE_ Class_12_Data_Structurel_5

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

CBSE_ Class_12_Data_Structurel_6

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;

}

}

HOTS for Data Structures Computer Science Class 12

Expert teachers of studiestoday have referred to NCERT book for Class 12 Computer Science to develop the Computer Science Class 12 HOTS. If you download HOTS with answers for the above chapter you will get higher and better marks in Class 12 test and exams in the current year as you will be able to have stronger understanding of all concepts. High Order Thinking Skills questions practice of Computer Science and its study material will help students to have stronger understanding of all concepts and also make them expert on all critical topics. You can easily download and save all HOTS for Class 12 Computer Science also from www.studiestoday.com without paying anything in Pdf format. After solving the questions given in the HOTS which have been developed as per latest course books also refer to the NCERT solutions for Class 12 Computer Science designed by our teachers. We have also provided lot of MCQ questions for Class 12 Computer Science in the HOTS so that you can solve questions relating to all topics given in each chapter. After solving these you should also refer to Class 12 Computer Science MCQ Test for the same chapter

Where can I download latest CBSE HOTS for Class 12 Computer Science Data Structures

You can download the CBSE HOTS for Class 12 Computer Science Data Structures for latest session from StudiesToday.com

Are the Class 12 Computer Science Data Structures HOTS available for the latest session

Yes, the HOTS issued by CBSE for Class 12 Computer Science Data Structures have been made available here for latest academic session

What does HOTS stand for in Class 12 Computer Science Data Structures

HOTS stands for "Higher Order Thinking Skills" in Data Structures Class 12 Computer Science. It refers to questions that require critical thinking, analysis, and application of knowledge

How can I improve my HOTS in Class 12 Computer Science Data Structures

Regular revision of HOTS given on studiestoday for Class 12 subject Computer Science Data Structures can help you to score better marks in exams

Are HOTS questions important for Data Structures Class 12 Computer Science exams

Yes, HOTS questions are important for Data Structures Class 12 Computer Science exams as it helps to assess your ability to think critically, apply concepts, and display understanding of the subject.