0% found this document useful (0 votes)
31 views65 pages

Sree Aad

The document describes an attempt to solve a coin denominations problem using a greedy algorithm. It provides sample input and output examples where the goal is to find the minimum number of coins needed to make change for a given value using Indian currency denominations. The submitted code implements a solution that uses a for loop to iterate through the denominations and a nested while loop to subtract the highest possible denomination from the value until it reaches zero, incrementing the count each time.

Uploaded by

kishore2412004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views65 pages

Sree Aad

The document describes an attempt to solve a coin denominations problem using a greedy algorithm. It provides sample input and output examples where the goal is to find the minimum number of coins needed to make change for a given value using Indian currency denominations. The submitted code implements a solution that uses a for loop to iterate through the denominations and a nested while loop to subtract the highest possible denomination from the value until it reaches zero, incrementing the count each time.

Uploaded by

kishore2412004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

07/05/2023, 12:30 Binary Search: Attempt review

Dashboard / My courses / CB19541-AAD-2021 / Divide and Conquer / Binary Search

Started on Wednesday, 12 April 2023, 10:06 PM


State Finished
Completed on Wednesday, 12 April 2023, 10:07 PM
Time taken 23 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663989&cmid=6092 1/2
07/05/2023, 12:30 Binary Search: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Given a sorted array arr[] of n elements, write a function to search a given element x in arr[] and return the index of x in the array. Consider
array is 0 base index.

Input: arr[] = {10, 20, 30, 50, 60, 80, 110, 130, 140, 170}, x = 110
Output: 6
Explanation: Element x is present at index 6.
Input: arr[] = {10, 20, 30, 40, 60, 110, 120, 130, 170}, x = 175
Output: -1
Explanation: Element x is not present in arr[].

Answer: (penalty regime: 0 %)


1
2 #include <stdio.h>
3
4 int binarySearch(int arr[], int l, int r, int x)
5 ▼ {
6 ▼ if (r >= l) {
7 int mid = l + (r - l) / 2;
8 if (arr[mid] == x)
9 return mid;
10 if (arr[mid] > x)
11 return binarySearch(arr, l, mid - 1, x);
12 return binarySearch(arr, mid + 1, r, x);
13 }
14 return -1;
15 }
16
17 int main(void)
18 ▼ {
19 int n,x;
20 scanf("%d",&n);
21 int arr[n];
22 for (int i = 0 ; i < n ; i++)
23 scanf("%d",&arr[i]);
24 scanf("%d",&x);
25 int result = binarySearch(arr, 0, n - 1, x);
26 (result == -1)? printf("Element x is not present in arr[]."): printf("Element
27 return 0;
28 }
29

Test Input Expected Got

1 10 Element x is present at index 6. Element x is present at index 6.


10 20 30 50 60 80 110 130 140 170
110

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ How Many Apples Can You Put into the Basket

Jump to...

Merge Sort ►

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663989&cmid=6092 2/2
07/05/2023, 12:49 Breadth First Search: Attempt review

Started on Friday, 5 May 2023, 9:32 PM


State Finished
Completed on Friday, 5 May 2023, 9:32 PM
Time taken 15 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=683868&cmid=6025 1/3
07/05/2023, 12:49 Breadth First Search: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Given N nodes and E edges of a graph where ith element of the array U is connected to ith element of V.

Return the nodes while doing BFS starting from node 1.

Example :

Input :
5

1113
2345

Output :

12345

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 #define max 15
3 int n,e,front=-1,rear=-1;
4 int adj[max][max];
5 int queue[max];
6 int status[max];
7 int isempty()
8 ▼ {
9 if(front==-1)
10 return 1;
11 else
12 return 0;
13 }
14 void enqueue(int ele)
15 ▼ {
16 if(front==-1)
17 ▼ {
18 front++;
19 rear++;
20 queue[rear]=ele;
21 }
22 else
23 ▼ {
24 rear++;
25 queue[rear]=ele;
26 }
27 }
28 void dequeue()
29 ▼ {
30 printf("%d ",queue[front]);
31 if(front==rear)
32 ▼ {
33 front=-1;
34 rear=-1;
35 }
36 else
37 front++;
38 }
39 int getfront()
40 ▼ {
41 return queue[front];
42 }
43 void bfs(int node)
44 ▼ {
45 enqueue(node);
46 status[node]=1;
47 int x=node;
48 while(!isempty())
49 ▼ {
50 dequeue();
51 for(int i=1;i<=n;i++)
52 ▼ {
53 if(adj[x][i]==1 && status[i]==0)
54 ▼ {

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=683868&cmid=6025 2/3
07/05/2023, 12:49 Breadth First Search: Attempt review
55 enqueue(i);
56 status[i]=1;
57 }
58 }
59 x=getfront();
60 }
61 }
62 int main()
63 ▼ {
64 scanf("%d%d" ,&n,&e);
65 int edges1[e+1],edges2[e+1];
66 int i,j;
67 for(i=1;i<e+1;i++)
68 scanf("%d",&edges1[i]);
69 for(i=1;i<e+1;i++)
70 scanf("%d" ,&edges2[i]);
71 for(i=1;i<n+1;i++)
72 ▼ {
73 for(j=1;j<n+1;j++)
74 adj[i][j]=0;
75 }
76 for(i=1;i<e+1;i++)
77 ▼ {
78 adj[edges1[i]][edges2[i]]=1;
79 adj[edges2[i]][edges1[i]]=1;
80 }
81 for(i=1;i<e+1;i++)
82 status[i]=0;
83 bfs(1);
84 return 0;
85 }

Input Expected Got

5 1 2 3 4 5 1 2 3 4 5
4
1 1 1 3
2 3 4 5

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=683868&cmid=6025 3/3
07/05/2023, 12:28 Coin Denominations: Attempt review

Dashboard / My courses / CB19541-AAD-2021 / Greedy Algorithm / Coin Denominations

Started on Wednesday, 22 March 2023, 2:27 PM


State Finished
Completed on Wednesday, 22 March 2023, 2:34 PM
Time taken 7 mins 10 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=650706&cmid=5976 1/3
07/05/2023, 12:28 Coin Denominations: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Write a program to take value V and we want to make change for V Rs, and we have infinite supply of each of the denominations in Indian
currency, i.e., we have infinite supply of { 1, 2, 5, 10, 20, 50, 100, 500, 1000} valued coins/notes, what is the minimum number of coins and/or
notes needed to make the change.
Input Format:

Take an integer from stdin.


Output Format:

print the integer which is change of the number.


Example Input :

64
Output:

Explanaton:
We need a 50 Rs note and a 10 Rs note and two 2 rupee coins.

Example Input:
49

Output:
5

Explanation:

We need a two 20 Rs notes and a 5 Rs coins and two 2 rupee coins.

Answer: (penalty regime: 0 %)


1 #include <stdio.h>
2
3 ▼ int main() {
4 int denominations[] = {1000, 500, 100, 50, 20, 10, 5, 2, 1};
5 int num_denominations = 9;
6 int v, i, count = 0;
7
8 scanf("%d", &v);
9 ▼ for (i = 0; i < num_denominations; i++) {
10 ▼ while (v >= denominations[i]) {
11 v -= denominations[i];
12 count++;
13 }
14 }
15 printf("%d", count);
16 return 0;
17 }
18

Input Expected Got

64 4 4

49 5 5

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=650706&cmid=5976 2/3
07/05/2023, 12:28 Coin Denominations: Attempt review

◄ Linear Search

Jump to...

How Many Apples Can You Put into the Basket ►

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=650706&cmid=5976 3/3
07/05/2023, 12:51 Depth First Search: Attempt review

Started on Sunday, 7 May 2023, 9:45 AM


State Finished
Completed on Sunday, 7 May 2023, 10:10 AM
Time taken 25 mins 33 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684459&cmid=6026 1/3
07/05/2023, 12:51 Depth First Search: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Given N nodes and E edges of a graph where ith element of the array U is connected to ith element of V.

Return the nodes while doing DFS starting from node 1.

Example :

Input :
5

1113
2345

Output :

12354

Answer: (penalty regime: 0 %)


1 #include <stdio.h>
2 #define max 15
3 int n,e,top=-1;
4 int adj[max][max];
5 int status[max];
6 int status[max];
7 int stack[max];
8 void push(int e)
9 ▼ {
10 top++;
11 stack[top]=e;
12 }
13 int isempty()
14 ▼ {
15 if(top==-1)
16 return 1;
17 else
18 return 0;
19 }
20 int peek()
21 ▼ {
22 return(stack[top]);
23 }
24 void pop()
25 ▼ {
26 top--;
27 }
28 void dfs(int node)
29 ▼ {
30 int x,flag;
31 push(node);
32 while(!isempty())
33 ▼ {
34 flag=0;
35 x=peek();
36 if(status[x]==0)
37 ▼ {
38 printf("%d ",x);
39 status[x]=1;
40 }
41 for(int i=1;i<n+1;i++)
42 ▼ {
43 if(adj[x][i]==1 && status[i]==0)
44 ▼ {
45 push(i);
46 flag=1;
47 break;
48 }
49 }
50 if(flag==0)
51 pop();
52 }
53 }
54 int main()

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684459&cmid=6026 2/3
07/05/2023, 12:51 Depth First Search: Attempt review
55 ▼ {
56 scanf("%d",&n);
57 scanf("%d",&e);
58 int edges1[e+1], edges2[e+1];
59 for(int i=1;i<e+1;i++)
60 scanf("%d",&edges1[i]);
61 for(int i=1;i<e+1;i++)
62 scanf("%d",&edges2[i]);
63 for(int i=1;i<n+1;i++)
64 ▼ {
65 for( int j=1;j<n+1;j++)
66 ▼ {
67 adj[i][j]=0;
68 }
69 }
70 for(int i=1;i<e+1;i++)
71 ▼ {
72 adj[edges1[i]][edges2[i]]=1;
73 adj[edges2[i]][edges1[i]]=1;
74 }
75 for(int i=1;i<e+1;i++)
76 ▼ {
77 status [i]=0;
78 dfs(1);
79 return 0;
80 }
81 }
82
83
84

Input Expected Got

5 1 2 3 5 4 1 2 3 5 4
4
1 1 1 3
2 3 4 5

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684459&cmid=6026 3/3
07/05/2023, 12:51 Dijkstra's Algorithm: Attempt review

Started on Sunday, 7 May 2023, 10:34 AM


State Finished
Completed on Sunday, 7 May 2023, 10:59 AM
Time taken 25 mins 10 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684469&cmid=6027 1/3
07/05/2023, 12:51 Dijkstra's Algorithm: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Dijkstra's Algorithm

Input
5

03070
30420

04956

72504
00640

Output
00

13
27

35

49

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 #include<limits.h>
3 int main()
4 ▼ {
5 int n,min,min_vertex;
6 scanf("%d",&n);
7 int adj[n][n],status[n],cost[n];
8 for(int i=0; i<n;i++)
9 ▼ {
10 for(int j=0;j<n;j++)
11 ▼ {
12 scanf("%d", &adj[i][j]);
13 }
14 status[i]=0;
15 cost[i]=INT_MAX;
16 }
17 cost[0]=0;
18 for(int i=0;i<n;i++)
19 ▼ {
20 min = INT_MAX;
21 for(int v=0;v<n;v++)
22 ▼ {
23 if (status[v] == 0 && cost[v]<=min)
24 ▼ {
25 min = cost[v];
26 min_vertex =v;
27 }
28 }
29 status[min_vertex]=1;
30 for(int v=0; v<n;v++)
31 ▼ {
32 if (status[v]==0&&adj[min_vertex][v]&&cost[min_vertex]!=INT_MAX&&cost[min_
33 cost[v]=cost[min_vertex]+adj[min_vertex][v];
34
35 }
36 }
37 for(int i=0;i<n;i++)
38 printf("%d %d\n",i,cost[i]);
39 return 0;
40 }
41

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684469&cmid=6027 2/3
07/05/2023, 12:51 Dijkstra's Algorithm: Attempt review

Input Expected Got

5 0 0 0 0
0 3 0 7 0 1 3 1 3
3 0 4 2 0 2 7 2 7
0 4 9 5 6 3 5 3 5
7 2 5 0 4 4 9 4 9
0 0 6 4 0

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684469&cmid=6027 3/3
07/05/2023, 12:27 Find Duplicate in Array-Brute Force-Time: O(n^2), Space: O(1) : Attempt review

Started on Saturday, 4 March 2023, 9:24 AM


State Finished
Completed on Saturday, 4 March 2023, 9:24 AM
Time taken 49 mins 44 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C
https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667155&cmid=5966 1/3
Sree Vignesh C
Sree Vignesh C
07/05/2023, 12:48 Graph Coloring: Attempt review

Dashboard / My courses / CB19541-AAD-2021 / Backtracking / Graph Coloring

Started on Wednesday, 12 April 2023, 10:04 PM


State Finished
Completed on Wednesday, 12 April 2023, 10:04 PM
Time taken 14 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663985&cmid=6127 1/3
07/05/2023, 12:48 Graph Coloring: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Graph Coloring problem is to assign colors to certain elements of a graph subject to certain constraints.

Graph nodes with initialization as { { 0,1,0,1},{1,0,1,0},{0,1,0,1},{1,0,1,0}}.Consider the four nodes and find the chromatic number for it.

Sample Output:
Node 1 Assigned with color 0

Node 2 Assigned with color 1

Node 3 Assigned with color 0

Node 4 Assigned with color 1

Chromatic Number to color the four node is : 2

Answer: (penalty regime: 0 %)


1 #include <stdio.h>
2 #include <stdbool.h>
3 #define NODE 4
4 int graph[NODE][NODE] = {{0,1,0,1},{1,0,1,0},{0,1,0,1},{1,0,1,0}};
5
6 int maxim(int color[])
7 ▼ {
8 int m = color[0];
9 for(int i = 1;i<NODE;i++)
10 ▼ {
11 if(m<color[i])
12 m = color[i];
13 }
14 return m+1;
15 }
16
17 void graphcoloring()
18 ▼ {
19 int color[NODE];
20 bool colorused[NODE];
21 color[0]=0;
22 for(int i=1;i<NODE;i++)
23 color[i]=-1;
24 for(int i=0;i<NODE;i++)
25 colorused[i]=false;
26 for(int u=1;u<NODE;u++)
27 ▼ {
28 for(int v=0;v<NODE;v++)
29 ▼ {
30 if(graph[u][v])
31 ▼ {
32 if(color[v]!=-1)
33 colorused[color[v]] = true;
34 }
35 }
36 int col;
37 for(col=0;col<NODE;col++)
38 ▼ {
39 if(!colorused[col])
40 break;
41 }
42 color[u]=col;
43 for(int v=0;v<NODE;v++)
44 ▼ {
45 if(graph[u][v])
46 ▼ {
47 if(color[v]!=-1)
48 colorused[color[v]] = false;
49 }
50 }
51 }
52 for(int u=0;u<NODE;u++)
53 printf("Node %d Assigned with color %d\n",u+1,color[u]);
54 printf("Chromatic Number to color the four node is : %d",maxim(color));

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663985&cmid=6127 2/3
07/05/2023, 12:48 Graph Coloring: Attempt review
55 }
56
57 int main()
58 ▼ {
59 graphcoloring();
60 return 0;
61 }

Test Expected Got

1 Node 1 Assigned with color 0 Node 1 Assigned with color 0


Node 2 Assigned with color 1 Node 2 Assigned with color 1
Node 3 Assigned with color 0 Node 3 Assigned with color 0
Node 4 Assigned with color 1 Node 4 Assigned with color 1
Chromatic Number to color the four node is : 2 Chromatic Number to color the four node is : 2

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Sum of All Subset XOR Totals

Jump to...

Breadth First Search ►

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663985&cmid=6127 3/3
07/05/2023, 12:28 How Many Apples Can You Put into the Basket: Attempt review

Dashboard / My courses / CB19541-AAD-2021 / Greedy Algorithm / How Many Apples Can You Put into the Basket

Started on Wednesday, 22 March 2023, 2:27 PM


State Finished
Completed on Wednesday, 22 March 2023, 2:34 PM
Time taken 7 mins 10 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=650706&cmid=5976 1/3
07/05/2023, 12:34 Knapsack-Dynamic Programming: Attempt review

Started on Saturday, 18 March 2023, 8:44 AM


State Finished
Completed on Saturday, 18 March 2023, 9:24 AM
Time taken 40 mins 41 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=648573&cmid=5999 1/2
07/05/2023, 12:34 Knapsack-Dynamic Programming: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Input

3
10 20 30

60 100 120

50

Output
220

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 int max(int a, int b)
3 ▼ {
4 return (a>b)?a:b;
5 }
6 int knapsac(int W,int wt[],int val[], int n)
7 ▼ {
8 int i,w;
9 int k[n+1][W+1];
10 for(i=0;i<=n;i++)
11 ▼ {
12 for(w=0;w<=W;w++)
13 ▼ {
14 if(i==0||w==0)
15 k[i][w]=0;
16 else if (wt[i-1]<=w)
17 k[i][w]= max( val[i-1]+k[i-1][w-wt[i-1]] , k[i-1][w]);
18 else
19 k[i][w]=k[i-1][w];
20 }
21 }
22 return k[n][W];
23 }
24 int main()
25 ▼ {
26 int n,W;
27 scanf("%d",&n);
28 int val[n],wt[n];
29 for(int i=0;i<n;i++)
30 scanf("%d",&wt[i]);
31 for(int i=0;i<n;i++)
32 scanf("%d",&val[i]);
33 scanf("%d",&W);
34 printf("%d",knapsac(W,wt,val,n));
35 return 0;
36 }

Input Expected Got

3 220 220
10 20 30
60 100 120
50

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=648573&cmid=5999 2/2
07/05/2023, 12:28 Linear Search: Attempt review

Dashboard / My courses / CB19541-AAD-2021 / Arrays-Brute Force Approach / Linear Search

Started on Wednesday, 12 April 2023, 10:12 PM


State Finished
Completed on Wednesday, 12 April 2023, 10:12 PM
Time taken 15 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=664001&cmid=6081 1/2
07/05/2023, 12:28 Linear Search: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Search an element in an array.

First line of input represents Array size, second line Array elements and third line search element.
Output represents the position of the element.

Sample input
4

34 12 4 5

4
Sample output

Answer: (penalty regime: 0 %)


1 #include <stdio.h>
2 int ls(int x[],int l,int a)
3 ▼ {
4 for (int i=0;i<l;i++)
5 ▼ {
6 if (x[i] == a)
7 ▼ {
8 return (i+1);
9 }
10 }
11 return (-1);
12
13 }
14 int main()
15 ▼ {
16 int y,l,a;
17 scanf("%d",&l);
18 int x[l];
19 for (int i = 0; i < l ; i++)
20 ▼ {
21 scanf("%d",&x[i]);
22 }
23 scanf("%d",&a);
24 y = ls(x,l,a);
25 printf("%d",y);
26 return 0;
27 }

Test Input Expected Got

1 5 5 5
34 23 12 56 78
78

2 2 -1 -1
67 89
90

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Pair with Difference k-Brute Force-Time: O(n^2)

Jump to...

Coin Denominations ►

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=664001&cmid=6081 2/2
07/05/2023, 12:32 Merge Sort: Attempt review

Dashboard / My courses / CB19541-AAD-2021 / Divide and Conquer / Merge Sort

Started on Tuesday, 18 April 2023, 1:44 PM


State Finished
Completed on Tuesday, 18 April 2023, 1:48 PM
Time taken 3 mins 59 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667140&cmid=6093 1/3
07/05/2023, 12:32 Merge Sort: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Merge sort is a sorting algorithm that works by dividing an array into smaller subarrays, sorting each subarray, and then merging the sorted
subarrays back together to form the final sorted array.
Sample Input :

6----------- Size of the Array


12 11 13 5 6 7 ----------- Elements of Array
Sample Output:

Sorted array is
5 6 7 11 12 13

Answer: (penalty regime: 0 %)


1 #include <stdio.h>
2 #include <stdlib.h>
3 void merge(int arr[], int l, int m, int r)
4 ▼ {
5 int i, j, k;
6 int n1 = m - l + 1;
7 int n2 = r - m;
8 int L[n1], R[n2];
9 for (i = 0; i < n1; i++)
10 L[i] = arr[l + i];
11 for (j = 0; j < n2; j++)
12 R[j] = arr[m + 1 + j];
13 i = 0;
14 j = 0;
15 k = l;
16 ▼ while (i < n1 && j < n2) {
17 ▼ if (L[i] <= R[j]) {
18 arr[k] = L[i];
19 i++;
20 }
21 ▼ else {
22 arr[k] = R[j];
23 j++;
24 }
25 k++;
26 }
27 ▼ while (i < n1) {
28 arr[k] = L[i];
29 i++;
30 k++;
31 }
32 ▼ while (j < n2) {
33 arr[k] = R[j];
34 j++;
35 k++;
36 }
37 }
38 void mergeSort(int arr[], int l, int r)
39 ▼ {
40 ▼ if (l < r) {
41 int m = l + (r - l) / 2;
42 mergeSort(arr, l, m);
43 mergeSort(arr, m + 1, r);
44 merge(arr, l, m, r);
45 }
46 }
47 int main()
48 ▼ {
49 int size;
50 scanf("%d",&size);
51 size++;
52 int arr[size];
53 for(int i = 0 ; i < size ; i++)
54 scanf("%d",&arr[i]);
55 mergeSort(arr, 0,size - 1);
56 size--;
57 for (int i = 0; i < size; i++)

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667140&cmid=6093 2/3
07/05/2023, 12:32 Merge Sort: Attempt review
58 printf("%d ", arr[i]);
59 return 0;
60 }
61

Test Input Expected Got

1 6 5 6 7 11 12 13 5 6 7 11 12 13
12 11 13 5 6 7

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Binary Search

Jump to...

Quick Sort ►

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667140&cmid=6093 3/3
07/05/2023, 12:47 N-Queens: Attempt review

Dashboard / My courses / CB19541-AAD-2021 / Backtracking / N-Queens

Started on Wednesday, 12 April 2023, 9:39 PM


State Finished
Completed on Wednesday, 12 April 2023, 9:39 PM
Time taken 19 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663929&cmid=6020 1/3
07/05/2023, 12:47 N-Queens: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty
space, respectively.
Example 1:

Input:

4
Output:

.Q..
...Q

Q...
..Q.

Explanation: There exist two distinct solutions to the 4-queens puzzle as shown above

Example 2:
Input:

1
Output:

Answer: (penalty regime: 0 %)


1 #include <stdio.h>
2 int N;
3 int board[100][100];
4
5 int isattack(int i, int j)
6▼{
7 int k,l;
8 for (k=0;k<N;k++)
9▼ {
10 if(board[i][k] || board[k][j])
11 return 1;
12 }
13 for (k=0;k<N;k++)
14 ▼ {
15 for(l=0;l<N;l++)
16 ▼ {
17 if((k+l==i+j)||(k-l==i-j))
18 ▼ {
19 if(board[k][l])
20 return 1;
21 }
22 }
23 }
24 return 0;
https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663929&cmid=6020 2/3
07/05/2023, 12:47 N-Queens: Attempt review

25 }
26
27 int nqueen(int n)
28 ▼ {
29 int i,j;
30 if(n==0)
31 return 1;
32 for (i=0;i<N;i++)
33 ▼ {
34 for (j=0;j<N;j++)
35 ▼ {
36 if((!isattack(i,j)) && (board[i][j]!=1))
37 ▼ {
38 board[i][j] = 1;
39 if (nqueen(n-1))
40 return 1;
41 board[i][j] = 0;
42 }
43 }
44 }
45 return 0;
46 }
47
48 int main()
49 ▼ {
50 scanf("%d",&N);
51 int i,j;
52 for(i=0;i<N;i++)
53 ▼ {
54 for(j=0;j<N;j++)
55 board[i][j] = 0;
56 }
57 nqueen(N);
58 for(i=0;i<N;i++)
59 ▼ {
60 for(j=0;j<N;j++)
61 ▼ {
62 if(board[i][j])
63 printf("Q");
64 else
65 printf(".");
66 }
67 printf("\n");
68 }
69 return 0;
70 return 0;
71 }
72

Input Expected Got

4 .Q.. .Q..
...Q ...Q
Q... Q...
..Q. ..Q.

1 Q Q

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Removing Chocolates

Jump to...

Sum of All Subset XOR Totals ►

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663929&cmid=6020 3/3
07/05/2023, 12:46 Removing Chocolates: Attempt review

Started on Saturday, 18 March 2023, 8:21 AM


State Finished
Completed on Saturday, 18 March 2023, 8:35 AM
Time taken 14 mins 38 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C
https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=648554&cmid=6015 1/2
07/05/2023, 12:46 N-th Tribonacci Number: Attempt review

Started on Saturday, 18 March 2023, 8:21 AM


State Finished
Completed on Saturday, 18 March 2023, 8:35 AM
Time taken 14 mins 38 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=648554&cmid=6015 1/2
07/05/2023, 12:46 N-th Tribonacci Number: Attempt review

Started on Saturday, 18 March 2023, 8:21 AM


State Finished
Completed on Saturday, 18 March 2023, 8:35 AM
Time taken 14 mins 38 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=648554&cmid=6015 1/2
07/05/2023, 12:46 N-th Tribonacci Number: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

The Tribonacci sequence Tn is defined as follows:

T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.


Given n, return the value of Tn.

Example 1:
Input:

Output:
4

Explanation:
T_3 = 0 + 1 + 1 = 2

T_4 = 1 + 1 + 2 = 4
Example 2:

Input:

25
Output:

1389537

Constraints:
0 <= n <= 37

The answer is guaranteed to fit within a 32-bit integer, ie. answer <= 2^31 - 1.

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 int main()
3 ▼ {
4
5 int x,a=-1,b=1,c=0,d;
6 scanf("%d",&x);
7 for(int i=0 ; i <= x ; i++)
8 ▼ {
9 d = a+b+c;
10 a=b;
11 b=c;
12 c=d;
13 }
14 printf("%d",d);
15 }

Input Expected Got

4 4 4

25 1389537 1389537

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=648554&cmid=6015 2/2
07/05/2023, 12:53 Pair with Difference k-Brute Force-Time: O(n^2) : Attempt review

Started on Sunday, 7 May 2023, 11:01 AM


State Finished
Completed on Sunday, 7 May 2023, 11:35 AM
Time taken 34 mins
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C
https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684493&cmid=6028 1/3
07/05/2023, 12:53 Prim's Algorithm: Attempt review

Started on Sunday, 7 May 2023, 11:01 AM


State Finished
Completed on Sunday, 7 May 2023, 11:35 AM
Time taken 34 mins
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684493&cmid=6028 1/3
07/05/2023, 12:53 Prim's Algorithm: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Prim's Algorithm

Input:
6

030065
301004

010604

006085
600802

544520
Output:

0-1 3
1-2 1

1-5 4

5-4 2
5-3 5

Answer: (penalty regime: 0 %)


1 # include<stdio.h>
2 # include<limits.h>
3 int main ( )
4 ▼ {
5 int n,min,u,v;
6 scanf ("%d",&n) ;
7 int adj [n][n];
8 int status [n];
9 for (int i=0;i<n; i++)
10 ▼ {
11 for (int j=0 ; j<n; j++)
12 ▼ {
13 scanf("%d", &adj [i][j]) ;
14 if ( adj [i][j]==0)
15 ▼ {
16 adj [i][j]= INT_MAX;
17 }
18 }
19 status [i] =0;
20 }
21 status [0] = 1;
22 int e=0 ;
23 while (e<=n)
24 ▼ {
25 min = INT_MAX;
26 for (int i=0 ; i<n;i++)
27 ▼ {
28 for (int j=0 ; j<n;j++)
29 ▼ {
30 if (adj [i][j]<min)
31 ▼ {
32 if (status [i]==1)
33 ▼ {
34 min = adj[i][j];
35 u=i;
36 v=j;
37 }
38 }
39 }
40 }
41 if (status [v]==0)
42 printf ("%d-%d %d\n",u , v , min ) ;
43 status [v] =1;
44 adj [u][v] = adj [v][u] =INT_MAX ;
45 e++;
46 }

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684493&cmid=6028 2/3
07/05/2023, 12:53 Prim's Algorithm: Attempt review
47 return 0;
48 }

Input Expected Got

6 0-1 3 0-1 3
0 3 0 0 6 5 1-2 1 1-2 1
3 0 1 0 0 4 1-5 4 1-5 4
0 1 0 6 0 4 5-4 2 5-4 2
0 0 6 0 8 5 5-3 5 5-3 5
6 0 0 8 0 2
5 4 4 5 2 0

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=684493&cmid=6028 3/3
07/05/2023, 12:27 Print intersection of 2 Sorted Arrays-Brute Force-Time: O(m * n): Attempt review

Started on Tuesday, 18 April 2023, 2:02 PM


State Finished
Completed on Tuesday, 18 April 2023, 2:52 PM
Time taken 49 mins 44 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667155&cmid=5966 1/3
07/05/2023, 12:27 Print intersection of 2 Sorted Arrays-Brute Force-Time: O(m * n): Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Find the intersection of two sorted arrays.


OR in other words,

Given 2 sorted arrays, find all the elements which occur in both the arrays.

Input Format

· The first line contains T, the number of test cases. Following T lines contain:
1. Line 1 contains N1, followed by N1 integers of the first array

2. Line 2 contains N2, followed by N2 integers of the second array


Output Format

The intersection of the arrays in a single line


Example

Input:
1

3 10 17 57

6 2 7 10 15 57 246
Output:

10 57
Input:

1
6123456

216

Output:
16

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 int main()
3 ▼ {
4 int t;
5 scanf("%d",&t);
6 for(int x=0;x<t;x++)
7 ▼ {
8 int m,n;
9 scanf("%d",&m);
10 int marr[m];
11 for(int i=0;i<m;i++)
12 scanf("%d",&marr[i]);
13 scanf("%d",&n);
14 int narr[n];
15 for(int i=0;i<n;i++)
16 scanf("%d",&narr[i]);
17 for(int i=0;i<m;i++)
18 ▼ {
19 for(int j=0;j<n;j++)
20 ▼ {
21 if(marr[i]==narr[j])
22 printf("%d ",marr[i]);
23 }
24 }
25 }
26 return 0;
27 }
28

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667155&cmid=5966 2/3
07/05/2023, 12:27 Print intersection of 2 Sorted Arrays-Brute Force-Time: O(m * n): Attempt review

Input Expected Got

1 10 57 10 57
3 10 17 57
6 2 7 10 15 57 246

1 1 6 1 6
6 1 2 3 4 5 6
2 1 6

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667155&cmid=5966 3/3
07/05/2023, 12:33 Quick Sort: Attempt review

Dashboard / My courses / CB19541-AAD-2021 / Divide and Conquer / Quick Sort

Started on Tuesday, 18 April 2023, 1:48 PM


State Finished
Completed on Tuesday, 18 April 2023, 1:49 PM
Time taken 1 min 6 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667146&cmid=6094 1/3
07/05/2023, 12:33 Quick Sort: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

Quicksort is a sorting algorithm based on the divide and conquer approach where
1. An array is divided into subarrays by selecting a pivot element (element selected from the array).

While dividing the array, the pivot element should be positioned in such a way that elements less than pivot are kept on the left side
and elements greater than pivot are on the right side of the pivot.
2. The left and right subarrays are also divided using the same approach. This process continues until each subarray contains a single
element.
3. At this point, elements are already sorted. Finally, elements are combined to form a sorted array.

Sample Input

6
12 11 13 5 6 7
Sample Output

5 6 7 11 12 13

Answer: (penalty regime: 0 %)


1
2 #include <stdio.h>
3 void swap(int* a, int* b)
4 ▼ {
5 int temp = *a;
6 *a = *b;
7 *b = temp;
8 }
9 int partition(int arr[], int low, int high)
10 ▼ {
11 int pivot = arr[high];
12 int i = (low - 1);
13 int j;
14 ▼ for (j = low; j <= high - 1; j++) {
15 ▼ if (arr[j] <= pivot) {
16 i++;
17 swap(&arr[i], &arr[j]);
18 }
19 }
20 swap(&arr[i + 1], &arr[high]);
21 return (i + 1);
22 }
23 void quicksort(int Arr[], int low, int high)
24 ▼ {
25 ▼ if (low < high) {
26 // pi = Partition index
27 int pi = partition(Arr, low, high);
28 quicksort(Arr, low, pi - 1);
29 quicksort(Arr, pi + 1, high);
30 }
31 }
32
33 int main()
34 ▼ {
35 int size,i;
36 scanf("%d",&size);
37 size++;
38 int array[size];
39 ▼ for(i = 0; i < size; i++) {
40 scanf("%d",&array[i]);
41 }
42 quicksort(array, 0, size - 1);
43 size--;
44 ▼ for(i = 0; i < size; i++) {
45 printf("%d ",array[i]);
46 }
47 }

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667146&cmid=6094 2/3
07/05/2023, 12:33 Quick Sort: Attempt review

Test Input Expected Got

1 6 5 6 7 11 12 13 5 6 7 11 12 13
12 11 13 5 6 7

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ Merge Sort

Jump to...

Knapsack-Dynamic Programming ►

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667146&cmid=6094 3/3
07/05/2023, 12:46 Removing Chocolates: Attempt review

Started on Saturday, 18 March 2023, 8:21 AM


State Finished
Completed on Saturday, 18 March 2023, 8:35 AM
Time taken 14 mins 38 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C
https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=648554&cmid=6015 1/2
Sum of N numbers Using Recursive : Attempt review

Name Sree Vignesh C


07/05/2023, 12:47 Sum of All Subset XOR Totals: Attempt review

Dashboard / My courses / CB19541-AAD-2021 / Backtracking / Sum of All Subset XOR Totals

Started on Wednesday, 12 April 2023, 10:03 PM


State Finished
Completed on Wednesday, 12 April 2023, 10:03 PM
Time taken 21 secs
Marks 1.00/1.00
Grade 10.00 out of 10.00 (100%)
Name Sree Vignesh C

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663978&cmid=6022 1/3
07/05/2023, 12:47 Sum of All Subset XOR Totals: Attempt review

Question 1
Correct

Mark 1.00 out of 1.00

The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty.

For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1.
Given an array nums, return the sum of all XOR totals for every subset of nums.

Note: Subsets with the same elements should be counted multiple times.
An array a is a subset of an array b if a can be obtained from b by deleting some (possibly zero) elements of b.

Example 1:

Input:
2

13
Output:

6
Explanation: The 4 subsets of [1,3] are:

- The empty subset has an XOR total of 0.

- [1] has an XOR total of 1.


- [3] has an XOR total of 3.

- [1,3] has an XOR total of 1 XOR 3 = 2.


0+1+3+2=6

Example 2:
Input:

3
516

Output:

28
Explanation: The 8 subsets of [5,1,6] are:

- The empty subset has an XOR total of 0.


- [5] has an XOR total of 5.

- [1] has an XOR total of 1.


- [6] has an XOR total of 6.

- [5,1] has an XOR total of 5 XOR 1 = 4.

- [5,6] has an XOR total of 5 XOR 6 = 3.


- [1,6] has an XOR total of 1 XOR 6 = 7.

- [5,1,6] has an XOR total of 5 XOR 1 XOR 6 = 2.


0 + 5 + 1 + 6 + 4 + 3 + 7 + 2 = 28

Example 3:
Input:

6
345678

Output:

480
Explanation: The sum of all XOR totals for every subset is 480.

Constraints:
1 <= nums.length <= 12

1 <= nums[i] <= 20

Answer: (penalty regime: 0 %)

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663978&cmid=6022 2/3
07/05/2023, 12:47 Sum of All Subset XOR Totals: Attempt review
1 #include <stdio.h>
2
3 int power(int b , int e)
4▼ {
5 int i,r=1;
6 for(i=0;i<e;i++)
7 r*=b;
8 return r;
9 }
10
11 int main()
12 ▼ {
13 int n;
14 scanf("%d",&n);
15 int a[n],x=0;
16 for(int i = 0 ; i < n ; i++)
17 scanf("%d",&a[i]);
18 for(int i = 0 ; i < n ; i++)
19 x=x|a[i];
20 printf("%d",power(2,n-1)*x);
21 return 0;
22 }
23

Input Expected Got

2 6 6
1 3

3 28 28
5 1 6

6 480 480
3 4 5 6 7 8

Passed all tests!

Correct
Marks for this submission: 1.00/1.00.

◄ N-Queens

Jump to...

Graph Coloring ►

https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663978&cmid=6022 3/3
Name Sree Vignesh C
Name Sree Vignesh C

You might also like