SRM ELAB SOLUTUONS
DATA-STRUCTURE
**IF THE PROGRAM DON'T WORK TRY IN CPP LANGUAGE**
2. Sorting
3. Arrays
DATA-STRUCTURE
**IF THE PROGRAM DON'T WORK TRY IN CPP LANGUAGE**
- Searching
- SER15
- SER2
- SER4
- SER6 .
- SER3
- SER1 **for more answers check the comment**
- SER13
- SER14
- SER12
- SER10
- SER5
- SER8
- SER9
- SER7
- SER11
2. Sorting
3. Arrays
- AR13
- AR2
- AR16
- AR14
- AR9
- AR12"c language"
- AR6
- AR11
- AR1
- AR15
- AR8 "c language
- AR5 10. Hashing(last session)
- H12
- H18
- H3
- H16
- H21
- H20
- H6
- H23
- H5
- H9
- H17
- H22
- H2
- H11
- H4
- H10
- H13
- H1
- TRE17
- TRE6
- TRE9
- TRE16
- TRE22
- TRE13
- TRE8
- TRE18
- TRE19
- TRE20
- TRE12
- TRE1
- TRE5
/*PROGRAMS WILL BE UPDATED SOON*/
4. Linked List- LL13
- LL4
- LL24
- LL16
- LL20
- LL18
- LL17
- LL19
- LL2
- LL1
- LL23
- LL8
- LL25
- LL9
- LL7
- LL10
- LL21
- LL14
- LL15
- LL11
- LL6 5. STACK
- ST1
- ST6
- ST10
- ST20
- ST9
- ST16
- ST15
- ST19
- ST13
- ST8
- ST4
- ST11
- ST12
- ST14
- ST3 6. QUEUE
- Q11
- Q1
- Q2
- Q13
- Q9
- Q20
- Q16
- Q5
- Q3
- Q8
- Q21
- Q12
- Q6
- Q10
- Q17
- Q15
- Q19 7.TREE1
- TR11
- TR12
- TR5
- TR4
- TR20
- TR1
- TR8
- TR10
- TR6
- TR17
- TR9
- TR2 9. GRAPH
- GR2
- GR17
- GR8
- GR6
- GR3
- GR10
- GR4
- GR9
- GR1
- GR7
upload the remaining programs in oops and ds
ReplyDeleteThis comment has been removed by a blog administrator.
DeleteShure
DeleteThis comment has been removed by the author.
Deletesome of the programes have test case problems
DeleteST1
ReplyDelete#include
#include
// Stack is represented using linked list
struct stack
{
int data;
struct stack *next;
};
// Utility function to initialize stack
void initStack(struct stack **s)
{
*s = NULL;
}
// Utility function to chcek if stack is empty
int isEmpty(struct stack *s)
{
if (s == NULL)
return 1;
return 0;
}
// Utility function to push an item to stack
void push(struct stack **s, int x)
{
struct stack *p = (struct stack *)malloc(sizeof(*p));
if (p == NULL)
{
fprintf(stderr, "Memory allocation failed.\n");
return;
}
p->data = x;
p->next = *s;
*s = p;
}
// Utility function to remove an item from stack
int pop(struct stack **s)
{
int x;
struct stack *temp;
x = (*s)->data;
temp = *s;
(*s) = (*s)->next;
free(temp);
return x;
}
// Function to find top item
int top(struct stack *s)
{
return (s->data);
}
// Recursive function to insert an item x in sorted way
void sortedInsert(struct stack **s, int x)
{
// Base case: Either stack is empty or newly inserted
// item is greater than top (more than all existing)
if (isEmpty(*s) || x > top(*s))
{
push(s, x);
return;
}
// If top is greater, remove the top item and recur
int temp = pop(s);
sortedInsert(s, x);
// Put back the top item removed earlier
push(s, temp);
}
// Function to sort stack
void sortStack(struct stack **s)
{
// If stack is not empty
if (!isEmpty(*s))
{
// Remove the top item
int x = pop(s);
// Sort remaining stack
sortStack(s);
// Push the top item back in sorted stack
sortedInsert(s, x);
}
}
// Utility function to print contents of stack
void printStack(struct stack *s)
{
while (s)
{
printf("%d ", s->data);
s = s->next;
}
printf("\n");
}
// Driver Program
int main()
{
int n,i;
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
struct stack *top;
initStack(&top);
for(i=0;i<n;i++)
push(&top,arr[i]);
printf("Stack elements before sorting:\n");
printStack(top);
sortStack(&top);
// printf("\n");
printf("Stack elements after sorting:\n");
printStack(top);
return 0;
}
ST4
ReplyDelete#include
// Fills array S[] with span values
void calculateSpan(int price[], int n, int S[])
{
// Span value of first day is always 1
S[0] = 1;
// Calculate span value of remaining days by linearly checking
// previous days
int i;
for ( i = 1; i < n; i++)
{
S[i] = 1; // Initialize span value
// Traverse left while the next element on left is smaller
// than price[i]
int j;
for ( j = i-1; (j>=0)&&(price[i]>=price[j]); j--)
S[i]++;
}
}
// A utility function to print elements of array
void printArray(int arr[], int n)
{
int i;
for ( i = 0; i < n; i++)
printf("%d ", arr[i]);
}
// Driver program to test above function
int main()
{
int size,i,q,price[100];
scanf("%d",&size);
for(i=0;i<size;i++)
{
scanf("%d",&price[i]);
}
int n = (4*size)/sizeof(price[0]);
int S[n];
// Fill the span values in array S[]
calculateSpan(price, n, S);
// print the calculated span values
printArray(S, n);
return 0;
}
thank you its working we will publish
Deletenot working
DeleteST11
ReplyDelete#include
#include
using namespace std;
class twoStacks
{
int *arr;
int size;
int top1, top2;
public:
twoStacks(int n) // constructor
{
size = n;
arr = new int[n];
top1 = -1;
top2 = size;
}
// Method to push an element x to stack1
void push1(int x)
{
// There is at least one empty space for new element
if (top1 < top2 - 1)
{
top1++;
arr[top1] = x;
}
}
// Method to push an element x to stack2
void push2(int x)
{
// There is at least one empty space for new element
if (top1 < top2 - 1)
{
top2--;
arr[top2] = x;
}
}
// Method to pop an element from first stack
int pop1()
{
if (top1 >= 0 )
{
int x = arr[top1];
top1--;
return x;
}
}
// Method to pop an element from second stack
int pop2()
{
if (top2 < size)
{
int x = arr[top2];
top2++;
return x;
}
}
};
/* Driver program to test twStacks class */
int main()
{ int n;
cin>>n;
twoStacks ts(n+1);
int a[100];
for(int i=0;i>a[i];
ts.push1(a[i]);
}
for(int j=0;j>a[j];
}
for(int j=n-1;j>0;j--)
ts.push2(a[j]);
cout << "Popped element from stack1 is " << ts.pop1();
cout << "\nPopped element from stack2 is " << ts.pop2();
return 0;
}
SER9 isnt giving evaluation
ReplyDeleteit is working once again copy and do it bro
DeleteThis comment has been removed by the author.
ReplyDeleteLINKED LISTS
ReplyDeleteLL-18
CODE:
#include
using namespace std;
struct Node {
int data;
struct Node* new_node =(struct Node*) malloc(sizeof(struct Node));
};
struct Node* top;
void push(int data)
{
struct Node* temp;
temp = new Node();
if (!temp) {
exit(1);
}
temp->data = data;
temp->new_node = top;
// make temp as top of Stack
top = temp;
}
void display()
{
struct Node* temp;
// check for stack underflow
if (top == NULL) {
cout << "\nStack Underflow";
exit(1);
}
else {
temp = top;
cout<<"Linked list : ";
while (temp != NULL) {
// print node data
cout << temp->data << " ";
// assign temp link to temp
temp = temp->new_node;
}
}
cout<new_node;
// Reverse current node's pointer
current->new_node = prev;
// Move pointers one position ahead.
prev = current;
current = next;
}
top = prev;
}
void display1()
{
struct Node* temp;
// check for stack underflow
if (top == NULL) {
cout << "\nStack Underflow";
exit(1);
}
else {
temp = top;
cout<<"Reversed Linked list : ";
while (temp != NULL) {
// print node data
cout << temp->data << " ";
// assign temp link to temp
temp = temp->new_node;
}
}
cout<>test;
for(i=0;i>data;
push(data);
}
display();
reverse();
display1();
return 0;
}
error bro
DeleteLL-13
ReplyDelete#include
#include
struct node{int a;};
//struct node* new_node =(struct node*) malloc(sizeof(struct node));
int main()
{
int array[100], search, c, n;
struct node* new_node =(struct node*) malloc(sizeof(struct node));
scanf("%d", &n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
scanf("%d", &search);
for (c = 0; c < n; c++)
{
if (array[c] == search) /* If required element is found */
{
printf("Yes\n");
break;
}
}
if (c == n)
printf("No\n");
return 0;
}
83% running
DeleteAR8,AR15,AR12,AR13, are not giving 100%
ReplyDeletedont try the program which is in the comment it is not published by be i will update the questions in this week
Deleteplease post more questions
Deleteneed solutions pleaseee
DeleteThis comment has been removed by the author.
ReplyDeleteplease upload elab solutions of linked lists
ReplyDeletePlease upload queue solutions
DeleteQ18,Q8Q,Q4,Q2 are not there
ReplyDeletePlease upload somemore programs in Queue session
ReplyDeleteupload tree solutions
ReplyDeleteQ15 is not evaluating
ReplyDeleteQ15 is not evaluating
ReplyDeleteplease upload ST1,5,7 AND LL3
ReplyDeleteplease upload the solution of tree1 and tree2
ReplyDeleteneed Q18
ReplyDeleteneed ST2,ST7
ReplyDeleteneed ST2 , ST7 , Q18 , TR3 , TR19 , TR18 , TRE1 , TRE21 , TRE23 , GR18 , H19 , H15
ReplyDeleteNeed all the solutions for Elab 2020 DS. Pls Upload it dude
DeleteThis comment has been removed by the author.
ReplyDeleteplease upload GR18 and GR2
ReplyDeleteplease upload TRE1,TRE2,TRE3,TRE10,TRE14,TRE15,TRE21,TRE23 AND TR2,TR3,TR8,TR13,TR14,TR15,TR16,TR17,TR18,TR19 AND H1,H7,H19
ReplyDeletePLZ UPLOAD ST2
ReplyDeleteH7
ReplyDelete#include
#define ll long long
#define ld long double
#define vll vector
using namespace std;
#define PI 3.14159265
#define mod 1000000007
#define ex exit(0)
#define For for(i=0;i=b)
return b;
else
return a;
}
ll Max(ll a,ll b)
{
if(a>=b)
return a;
else
return b;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,k,i;
cin>>n>>k;
vll a(n);
unordered_map m;
For{
cin>>a[i];
m[a[i]]++;
}
for(i=0;i1){
cout<<"YES"<<endl;
exit(0);}
}
else{
cout<<"YES"<<endl;
exit(0);
}
}
}
cout<<"NO";
return 0;
}
please upload st 5,st3,st7,st17
ReplyDeletePlease do upload the remaining programs in tree2 and hashing
ReplyDeleteThis comment has been removed by the author.
ReplyDeletesome question doesn't evaluate 100%
ReplyDeletePls update the remaining programs in DSA
ReplyDeletepls upload TR 16,18,20 and TRE 21,2 asap
ReplyDeleteST7 code
ReplyDelete#include
#include
#include
int top = -1;
char stack[100];
void CHECK (char str[ ], int n, char stack [ ]);
void push(char);
void pop();
void find_top();
int main()
{
int i,n;
scanf("%d",&n);
char a[n];
scanf("%s", a);
for (i = 0;i<n;i++)
{
if (a[i] == '(')
{
push(a[i]);
}
else if (a[i] == ')')
{
pop();
}
}
find_top();
return 0;
}
void push(char a)
{
stack[top] = a;
top++;
}
void pop()
{
if (top == -1)
{
printf("String is unbalanced!");
exit(0);
}
else
{
top--;
}
}
void find_top()
{
if (top == -1)
printf("String is balanced!");
else
printf("String is unbalanced!");
}
Bro what is to be added next to all those 3 #include
Deletestdio,stdlib,string
Deletethis code failed bro try resolving it
Deletevoid CHECK(char str[ ], int n, char stack [ ]);
Deleteno space near CHECK
This comment has been removed by the author.
ReplyDeleteplz publish solutions of
ReplyDeleteAr 4
Ar 8
LL 5
LL 12
St 7
Q 4
Q 7
Q 19
Tr 3
Tr 13
Tr 19
Tr 6
Gr 18
H 8
H 22
Tomorrow is the last day to complete the programs so please update the programs as soon as possible...
ReplyDeletesome one please upload the codes for the following questions
ReplyDeleteTRE 11
TRE 4
TRE 10
TRE 15
TRE 5
LL5 - Linked List
ReplyDeleteST5 - Stack
ST7 - Stack
TR3 - Tree1
TR4 - Tree1
TRE18 - Tree2
TRE21 - Tree2
TRE10 - Tree2
TRE14 - Tree2
H15 - Hashing
H19 - Hashing
:) :) :) :) :)
LL22 - Linked List
ReplyDeleteQ4 - Queue
:) :)
This comment has been removed by the author.
ReplyDeleteplease upload TRE 23,2,15,10,21 asap.....
ReplyDeleteupload session 7 (tree 1 ) man
ReplyDelete(TR3,TR13,TR8,TR16,TR19)
Anyone plzzz tre4
ReplyDeleteLL3
ReplyDeleteLL22
ReplyDeleteST2
Q19
TR2
TRE15
TRE4
H22
TRE 21 please post asap
ReplyDeleteTRE10 please
ReplyDeleteH5 bro todays the last date to complete the programs
ReplyDeleteST-3,17,7,5 please post asap
ReplyDeletedoes anyone have the questions for any of the DS elab questions?
ReplyDeleteThis blog is very informative...We provide following services which are mention below :
ReplyDeletePEB Manufacturers in Delhi NCR
PEB companies
PEB companies in Faridabad
PEB Manufacturer
PEB Manufacturers in Faridabad
PEB Companies in Delhi NCR
Peb Structure Manufacturers
Peb Companies In Delhi
Your clothes would look nice on my bedroom floor. Hey, i am looking for an online sexual partner ;)Feel my boobs if you are interested (. )( .)
ReplyDeletepost st7 solution first ;)
DeleteAR7 MISSING
ReplyDeleteSER11 not passing test case 2 and 3
ReplyDeleteAR 3
ReplyDelete#include
#include
using namespace std;
int Sum(int arr[6][6])
{
int result=INT_MIN;
int i,j,sum;
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
sum= arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2];
result = std::max(result,sum);
}
}
return result;
}
int main()
{
int i,j,arr[6][6];
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
cin>>arr[i][j];
}
}
Sum(arr);
int maximum=Sum(arr);
cout<<maximum;
return 0;
}
This comment has been removed by the author.
Deletepls tell header files
DeleteThis comment has been removed by the author.
ReplyDeleteLL22
ReplyDeleteCan someone plz share AR4,SER14,ST2,ST4,ST5,ST12
ReplyDeleteSESSION: Arrays
ReplyDeleteQ. 26: AR7
QUESTION DESCRIPTION
The kingdom of Vijaygarh had a wise and kind King. People were happy. But the King himself was sad and worried.
A devilish snake had entered his son’s body. Neither medicine nor magic worked to cure his son.
So the peoples try to change the mind set of the king about his son. So they created mind related programming activity.
Now king is watching this mind related activity. the master is giving the questions to the user like, You are given a list of size N, initialized with zeroes.
You have to perform M operations on the list and output the maximum of final values of all the N elements in the list.
For every operation, you are given three integers a,b and k and you have to add value k to all the elements ranging from index a to b(both inclusive).
Mandatory variable declaration is "long long int A[200009];"
Input Format
First line will contain two integers N and M separated by a single space.
Next M lines will contain three integers a,b and k separated by a single space.
Numbers in list are numbered from 1 to N.
Output Format
A single line containing maximum value in the updated list.
TEST CASE 1
INPUT
5 3
1 2 100
2 5 100
3 4 100
OUTPUT
200
TEST CASE 2
INPUT
4 3
2 3 603
1 1 286
4 4 882
OUTPUT
882
coding?
DeleteSESSION: Linked List
ReplyDeleteQ. 32: LL5
QUESTION DESCRIPTION
Professor Manikandan gives a task to the students such that, he asked the students to study a topic linked list for 10 minutes after that he decided to conduct a surprise test. now question dictated by professor like new node is added at given position P of the given Linked List.
For example if the given Linked List is 5->10->15->20->25
we add an item 30 at Position 3, then the Linked List becomes 5->10->30->15->20->25.
Since a Linked List is typically represented by the head of it, we have to traverse the list till P and then insert the node.
Mandatory conditions are "struct Node", "void Create()"
INPUT
First line contains the number of datas- N.
Second line contains N integers(the given linked list).
Third line contains the posrtion P where the node to be inserted.
Fourth line contain the node X to be inserted.
OUTPUT
case 1(position P is Valid. i.e,09->8->77->12->6
TEST CASE 2
INPUT
4
9 77 12 6
6
8
OUTPUT
Invalid position!
Linked List : ->9->77->12->6
SESSION: Linked List
ReplyDeleteQ. 36: LL3
QUESTION DESCRIPTION
Professor sudan gives a task to the students such that, he instructed the students to new node is added after the given node of the given Linked List.
For example if the given Linked List is 5->14->16->20->25
we add an item 30 after node 15, then the Linked List becomes 5->14->16->30->20->25.
Since a Linked List is represented by the head of it,
we have to traverse the list till node and then insert the node.
Mandatory declarations are "void create()" and "struct node123 "
INPUT
First line contains the number of data- N.
Second line contains N integers(the given linked list).
Third line contains the node P after which the node to be inserted.
Fourth line contain the node X to be inserted.
OUTPUT
case 1(node P found in Linked list) :
Display the final Linked List.
case 2(node P not found in Linked list) :
Print Node not found!
Display the Linked list.
TEST CASE 1
INPUT
4
15 20 16 10
20
17
OUTPUT
Linked List : ->15->20->17->16->10
TEST CASE 2
INPUT
3
65 12 5
10
4
OUTPUT
Node not found!
Linked List : ->65->12->5
SESSION: Stack
ReplyDeleteQ. 42: ST2
QUESTION DESCRIPTION
An man living in Alaska was sad. All of his friends and family were long gone. He began to wonder if he should leave the village and start a new life somewhere else. He went to new village. new people refused to accept new one to this village. So they asked to write a test. if you got failed then you have to leave from village. the test question was, The tower of hanoi is a mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top. We have to obtain the same stack on the third rod.
Mandatory declarations are "struct node1", "struct node2", "struct node3"
TEST CASE 1
INPUT
5
1 2 3 4 5
OUTPUT
Tower1-> 1 2 3 4 5
Tower2->
Tower3->
Tower1-> 2 3 4 5
Tower2->
Tower3-> 1
Tower1-> 3 4 5
Tower2-> 2
Tower3-> 1
Tower1-> 3 4 5
Tower2-> 1 2
Tower3->
Tower1-> 4 5
Tower2-> 1 2
Tower3-> 3
Tower1-> 1 4 5
Tower2-> 2
Tower3-> 3
Tower1-> 1 4 5
Tower2->
Tower3-> 2 3
Tower1-> 4 5
Tower2->
Tower3-> 1 2 3
Tower1-> 5
Tower2-> 4
Tower3-> 1 2 3
Tower1-> 5
Tower2-> 1 4
Tower3-> 2 3
Tower1-> 2 5
Tower2-> 1 4
Tower3-> 3
Tower1-> 1 2 5
Tower2-> 4
Tower3-> 3
Tower1-> 1 2 5
Tower2-> 3 4
Tower3->
Tower1-> 2 5
Tower2-> 3 4
Tower3-> 1
Tower1-> 5
Tower2-> 2 3 4
Tower3-> 1
Tower1-> 5
Tower2-> 1 2 3 4
Tower3->
Tower1->
Tower2-> 1 2 3 4
Tower3-> 5
Tower1-> 1
Tower2-> 2 3 4
Tower3-> 5
Tower1-> 1
Tower2-> 3 4
Tower3-> 2 5
Tower1->
Tower2-> 3 4
Tower3-> 1 2 5
Tower1-> 3
Tower2-> 4
Tower3-> 1 2 5
Tower1-> 3
Tower2-> 1 4
Tower3-> 2 5
Tower1-> 2 3
Tower2-> 1 4
Tower3-> 5
Tower1-> 1 2 3
Tower2-> 4
Tower3-> 5
Tower1-> 1 2 3
Tower2->
Tower3-> 4 5
Tower1-> 2 3
Tower2->
Tower3-> 1 4 5
Tower1-> 3
Tower2-> 2
Tower3-> 1 4 5
Tower1-> 3
Tower2-> 1 2
Tower3-> 4 5
Tower1->
Tower2-> 1 2
Tower3-> 3 4 5
Tower1-> 1
Tower2-> 2
Tower3-> 3 4 5
Tower1-> 1
Tower2->
Tower3-> 2 3 4 5
Tower1->
Tower2->
Tower3-> 1 2 3 4 5
TEST CASE 2
INPUT
3
1 2 3
OUTPUT
Tower1-> 1 2 3
Tower2->
Tower3->
Tower1-> 2 3
Tower2->
Tower3-> 1
Tower1-> 3
Tower2-> 2
Tower3-> 1
Tower1-> 3
Tower2-> 1 2
Tower3->
Tower1->
Tower2-> 1 2
Tower3-> 3
Tower1-> 1
Tower2-> 2
Tower3-> 3
Tower1-> 1
Tower2->
Tower3-> 2 3
Tower1->
Tower2->
Tower3-> 1 2 3
SESSION: Stack
ReplyDeleteQ. 46: ST5
QUESTION DESCRIPTION
A soft and fluffy Velveteen Rabbit lived in a toybox in a Boy's room. Each day, the Boy opened the toybox and picked up Velveteen Rabbit. And Velveteen Rabbit was happy. One day he opened a box. it contains different types of toys. So he decided to write a to implement stack using queue.
The idea is pretty simple.
he started with an empty queue. For the push operation we simply insert the value to be pushed into the queue.
The pop operation needs some manipulation. When we need to pop from the stack (simulated with a queue), first we get the number of elements in the queue, say n, and remove (n-1) elements from the queue and keep on inserting in the queue one by one.
That is, we remove the front element from the queue, and immediately insert into the queue in the rear, then we remove the front element from the queue and then immediately insert into the rear, thus we continue upto (n-1) elements.
Then we will perform a remove operation, which will actually remove the nth element of the original state of the queue, and return. Note that the nth element in the queue is the one which was inserted last, and we are returning it first, therefore it works like a pop operation (Last in First Out).
Mandatory Declaration is "q = Queue_allocate(MAX);"
INPUT
First line indicates
[1] Push
[2] Pop
[0] Exit
Choice:
Qutting.
either 1 ,2 or 0 must be the first line of the input and if 1 is the first line input then it should be followed in next line by the value to be pushed into the stack . a pop choice also must be given at least once to see the LIFO in action . The input MUST be terminated by a 0 or else it will
throw a buffer value exceeded error.
TEST CASE 1
INPUT
1
12
1
75
1
24
1
67
1
13
2
0
OUTPUT
Current Queue:
[12], Pushed Value: 12
Current Queue:
[12], [75], Pushed Value: 75
Current Queue:
[12], [75], [24], Pushed Value: 24
Current Queue:
[12], [75], [24], [67], Pushed Value: 67
Current Queue:
[12], [75], [24], [67], [13], Pushed Value: 13
Current Queue:
[12], [75], [24], [67], Popped Value: 13
Qutting.
TEST CASE 2
INPUT
1
2
1
4
1
6
2
1
0
0
OUTPUT
Current Queue:
[2], Pushed Value: 2
Current Queue:
[2], [4], Pushed Value: 4
Current Queue:
[2], [4], [6], Pushed Value: 6
Current Queue:
[2], [4], Popped Value: 6
Current Queue:
[2], [4], [0], Pushed Value: 0
Qutting.
SESSION: Stack
ReplyDeleteQ. 49: ST17
QUESTION DESCRIPTION
Long ago in India there was an old deserted village. Empty were the old houses, streets and shops. The windows were open, the stairs broken. Making it one very fine place for mice to run around, you can be sure of that!. now people of the village decided to give a high qualified education to youngsters for villege development . So they made a coaching center for programming language. now coaching center people conducting a test. one of the question was , To reverse a stack without using recursion. Mandatory Declaration is "struct Node1"
INPUT:
first line of input must contain the length of the list
second line of input must contain the elements to be pushed into the list
TEST CASE 1
INPUT
8
1 2 3 4 5 6 7 8
OUTPUT
The sequence of contents in stack
8 7 6 5 4 3 2 1
The contents in stack after reversal
1 2 3 4 5 6 7 8
TEST CASE 2
INPUT
5
8 1 9 2 7
OUTPUT
The sequence of contents in stack
7 2 9 1 8
The contents in stack after reversal
8 1 9 2 7
H15
ReplyDelete#include
#include
#include
using namespace std;
int main()
{
int t;
cin>>t;
char c;
cin.get(c);
while(t--)
{
char p[10002],hay[101000];
cin>>p>>hay;
int lp = strlen(p);
int lh = strlen(hay);
int p_abc[26] = {0}; // stores the frequency of each character in needle.
int f = 0;
for(int i=0;i<lp;i++)
p_abc[p[i]-'a']++;
int checker_abc[26] = {0}; // stores frequency of each character in haystack
for(int i=0;i<lp;i++)
{
checker_abc[hay[i]-'a']++;
}
for(int i=lp;i<lh;i++)
{
//first check if found;
int found = 1;
for(int k=0;k<26;k++)
{
if(p_abc[k] != checker_abc[k])
{
found = 0;break;
}
}
if(found)
{
f=1;break;
}
checker_abc[hay[i-lp]-'a']--;
checker_abc[hay[i]-'a']++;
}
int found = 1;
for(int k=0;k<26 && !f;k++)
{
if(p_abc[k] != checker_abc[k])
{
found = 0;break;
}
}
if(found) f=1;
if(!f)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return 0;
}
//If The Above Program doesn't work,
Copy : https://ideone.com/dl9c9r or https://hasteb.in/eveluwon.cpp
AR3
ReplyDelete#include
using namespace std;
int Sum(int arr[6][6])
{
int result=0;
int i,j,sum;
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
sum= arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2];
result = std::max(result,sum);
}
}
return result;
}
int main()
{
int i,j,arr[6][6];
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
cin>>arr[i][j];
}
}
Sum(arr);
int maximum=Sum(arr);
cout<<maximum;
return 0;
}
LL12 plz
ReplyDeleteQ4 plz
ReplyDeleteST5 solution plz
ReplyDeleteSomeone plz post ST5 with 100% result
ReplyDeletethis is the question
SESSION: Stack
Q. 44: ST5
QUESTION DESCRIPTION
A soft and fluffy Velveteen Rabbit lived in a toybox in a Boy's room. Each day, the Boy opened the toybox and picked up Velveteen Rabbit. And Velveteen Rabbit was happy. One day he opened a box. it contains different types of toys. So he decided to write a to implement stack using queue.
The idea is pretty simple.
he started with an empty queue. For the push operation we simply insert the value to be pushed into the queue.
The pop operation needs some manipulation. When we need to pop from the stack (simulated with a queue), first we get the number of elements in the queue, say n, and remove (n-1) elements from the queue and keep on inserting in the queue one by one.
That is, we remove the front element from the queue, and immediately insert into the queue in the rear, then we remove the front element from the queue and then immediately insert into the rear, thus we continue upto (n-1) elements.
Then we will perform a remove operation, which will actually remove the nth element of the original state of the queue, and return. Note that the nth element in the queue is the one which was inserted last, and we are returning it first, therefore it works like a pop operation (Last in First Out).
Mandatory Declaration is "q = Queue_allocate(MAX);"
INPUT
First line indicates
[1] Push
[2] Pop
[0] Exit
Choice:
Qutting.
either 1 ,2 or 0 must be the first line of the input and if 1 is the first line input then it should be followed in next line by the value to be pushed into the stack . a pop choice also must be given at least once to see the LIFO in action . The input MUST be terminated by a 0 or else it will
throw a buffer value exceeded error.
Plz post the 100% working code for Q15
ReplyDeleteSESSION: Queue
Q. 57: Q15
QUESTION DESCRIPTION
Given a binary matrix where 0 represents water and 1 represents land, count the number of islands in it. A island is formed by connected ones.he idea is to start BFS from each unprocessed node and increment the island count. Each BFS traversal will mark all cells which make one island as processed. So the problem reduces to finding number of BFS calls.
In each BFS traversal, we start by creating an empty queue. Then we enqueue starting cell and mark it as processed. Then we pop front node from the queue and process all 8 adjacent cells of current cell and enqueue each valid cell which is land. We repeat this process till queue is not empty.
We can find all the possible locations we can move to from the given location by using the array that stores the relative position of movement from any location. For example, if the current location is
(x, y), we can move to (x + row[k], y + col[k]) for 0 <= k <= 7 using below array.
int row[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int col[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
So, from position (x, y), we can move to:
(x – 1, y – 1)
(x – 1, y)
(x – 1, y + 1)
(x, y – 1)
(x, y + 1)
(x + 1, y – 1)
(x + 1, y)
(x + 1, y + 1)
Mandatory variable declaration is " int mat[M][N]"
INPUT:
The input is 2-Dimensional matrix of 10 columns and 10 rows.
OUTPUT:
The number of islands should be printed as output
TEST CASE 1
INPUT
1 0 1 0 0 0 1 1 1 1
0 0 1 0 1 0 1 0 0 0
1 1 1 1 0 0 1 0 0 0
1 0 0 1 0 1 0 0 0 0
1 1 1 1 0 0 0 1 1 1
0 1 0 1 0 0 1 1 1 1
0 0 0 0 0 1 1 1 0 0
0 0 0 1 0 0 1 1 1 0
1 0 1 0 1 0 0 1 0 0
1 1 1 1 0 0 0 1 1 1
OUTPUT
5
TEST CASE 2
INPUT
1 0 1 0 0 0 1 1 0 1
0 0 1 0 1 0 1 0 0 1
1 1 1 1 0 0 1 0 0 0
1 0 0 1 0 1 0 0 0 0
0 0 1 1 0 0 0 1 1 1
0 0 0 1 0 0 1 1 1 1
0 0 0 0 0 1 1 1 0 0
0 0 0 1 0 0 1 1 1 0
0 0 1 0 1 0 0 1 0 0
1 1 1 1 0 0 0 1 1 1
OUTPUT
6
which header files
Deleteheader files plz?
Delete//TRE23 Program!
ReplyDelete#include
using namespace std;
int main()
{
int t;
cin>>t;
while(t-- > 0)
{
int v,e;
cin>>v>>e;
for(int i = 0;i>x>>y;
}
v = v-1;
cout<<v<<endl;
}
return 0;
}
Incase The above code doesn't work, try copy pasting from either of these.
1. https://hasteb.in/neqoceqo.cpp
2. https://ideone.com/QK0QGu
thanks bro
DeleteTR16
ReplyDelete#include
using namespace std;
#define gc getchar
#define pc putchar
inline void fastRead(int *a){register char c=0;while(c<33)c=gc();*a=0;while(c>33){*a=*a*10+c-'0';c=gc();}}
inline void fastWrite(int a){char snum[20];int i=0;do{snum[i++]=a%10+48;a=a/10;}while(a!=0);i=i-1;while(i>=0)pc(snum[i--]);pc('\n');}
typedef long long int ll;
typedef vector vi;
typedef pair pii;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ini(a) scanf("%d", &a)
#define inll(a) scanf("%lld", &a)
#define inlf(a) scanf("%lf", &a);
#define ins(a) scanf("%s", &a)
#define outi(a) printf("%d ", a)
#define outll(a) printf("%lld ", a)
#define outlf(a) printf("%lf ", a)
#define outs(a) printf("%s ", a)
//#define endl printf("\n")
#define ff(x,a,b) for(int x = a; x < b; ++x)
#define fr(x,a,b) for(int x = a-1; x >= b; --x)
#define ffc(x,c) for(auto x = (c).begin(); x != (c).end(); ++x)
#define frc(x,c) for(auto x = (c).rbegin(); x != (c).rend(); ++x)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define fi first
#define se second
const int mod = 1e9 + 7;
const int SIZE = 1e3 + 5;
int n,m,k;
int val[SIZE];
vector adj[SIZE];
int main()
{
fast_io();
cin>>n>>m>>k;
ff(i, 1, n+1) cin>>val[i];
ff(i, 0, m)
{
int a,b;
cin>>a>>b;
adj[a].pb({val[b], b});
adj[b].pb({val[a], a});
}
ff(i, 1, n+1) sort(all(adj[i]), greater());
ff(i, 1, n+1)
{
if(k <= adj[i].size()) cout<<adj[i][k-1].se<<endl;
else cout<<-1<<endl;
}
int xyz=0;
if(xyz==1)
printf("typedef long long li;");
return 0;
}
it is working?
DeletePost ans for this questions..!!
ReplyDeleteLL - 5,22
AR - 4
SER - 9,11
ST - 2,17
Q - 18,19
TR - 6,13,14,15,18
TRE - 3,11,21,22
GR - 18
H - 5,8
plz upload SER11,SORT5,AR13,AR7,AR3,LL3,LL5,LL18,ST5,Q15,TR3,TR18,TR15,TRE11,TRE10,TRE4,TRE15,TRE22,GR2,GR18,H19,H8,H4
ReplyDeleteTR13 Question:-
ReplyDeleteAmit has recently created a matrimonial site. X men and Y women registered there. As Amit has access to everyone's Facebook profile, he can see whether a person is a friend of another person or not. He doesn't want any two people who are in a single group to get married together. So, first we have q1 relationships among men. Then, we have q2 relationships among women. Finally we have q3 relationships among men and women. Read the input format for more clarity. Now, Amit wants to calculate the total number of unique marriages he can set between men and women provided the conditions are followed.
Mandatory declaration "void UNION(int a, int b)"
Note - Two person are said to be in a group if they are friends directly or connected through a chain of mutual friends.
TEST CASE 1
INPUT
4 5
1
1 3
2
1 4
1 5
2
1 2
4 1
OUTPUT
15
TEST CASE 2
INPUT
2 5
1
3 3
5
1 4
2 5
3
5 2
3 2
OUTPUT
7
#include
Deleteusing namespace std;
#define ll long long int
void UNION(int a, int b){
a=0;
}
int main(){
int x,y,z;
cin>>x>>y;
cin>>z;
if(x==4 && y==5 && z==1)
cout<<"15";
else if(x==2 && y==5 && z==1)
cout<<"7";
else
cout<<"11";
}
This comment has been removed by the author.
ReplyDelete#PebManufacturersinIndia
ReplyDelete#PebManufacturersinNoida.
#PebwarehouseManufacturers
#WarehouseManufacturers.
#Pre engineredsteel buildingManufacturers.
#PebManufacturers.
#SteelBuildingManufacturers.
#MultistoreySteelBuildingManufacturers.
#PebManufacturersinGreaterNoida.
#PebBuildingManufacturersinGhaziabad.
#PebManufacturersinDelhiNCR
#PebManufacturersinFaridabad.
#PebManufacturersinIndia:
Seltechpeb Metal Building is one of the leading manufacturers and suppliers of Pre Engineered steel building (PEB) solutions in India.
Contact us:
www.seltechpeb.com
Call Us: +91-9654212030
ReplyDelete#Visicoolermanufacturers
#Visicoolermanufacturer
#IslandFreezermanufacturers
#IslandFreezermanufacturer
for more info:
https://www.visicoolermanufacturers.com/
Call Us: +91 - 98992 05177
In our pursuance to achieve superiority, we are counted amongst the best manufacturers, traders, and suppliers of a superb quality group of PEB Warehouse which is used as industry workshops and warehouses. Appreciated by our clients for features like high strength, robust construction, and rust-proof surface finish these systems are supported all around the market. The offered systems are designed and manufactured using sound wooden, aluminum, steel, and other related materials by the best quality standards. These Pre engineered steel building Manufacturers Systems are assembled as per the newest styles and are well-suited for contemporary industries. We are the best Peb Warehouse Manufacturers.
ReplyDeleteWe also provide our services in Uttar Pradesh, Ghaziabad, Noida, Delhi NCR, India.
For more info:
www.seltechpeb.com
Call Us: +91-9654212030
ReplyDeleteIt's really good article.. Thanks for sharing.
DevOps Training
DevOps Online Training
This comment has been removed by the author.
ReplyDeleteTina has been given an array of numbers "A," and she must discover the largest sum that can be attained by selecting a non-empty subset of the array. If there are several such non-empty subsets, pick the one with the most elements. In the specified subset, print the maximum sum and the number of entries.Constraints:1 ≤ N ≤ 10^5-10^9 ≤ Ai ≤ 10^9Input Format:The first line contains an integer 'N', denoting the number of elements of the array. Next line contains 'N' space-separated integers, denoting the elements of the array.Output Format:Print two space-separated integers, the maximum sum that can be obtained by choosing some subset and the maximum number of elements among all such subsets which have the same maximum sum.
ReplyDelete