Sree Aad
Sree Aad
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
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[].
Correct
Marks for this submission: 1.00/1.00.
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
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
Given N nodes and E edges of a graph where ith element of the array U is connected to ith element of V.
Example :
Input :
5
1113
2345
Output :
12345
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 }
5 1 2 3 4 5 1 2 3 4 5
4
1 1 1 3
2 3 4 5
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
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
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:
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:
64 4 4
49 5 5
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...
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
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
Given N nodes and E edges of a graph where ith element of the array U is connected to ith element of V.
Example :
Input :
5
1113
2345
Output :
12354
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
5 1 2 3 5 4 1 2 3 5 4
4
1 1 1 3
2 3 4 5
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
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
Dijkstra's Algorithm
Input
5
03070
30420
04956
72504
00640
Output
00
13
27
35
49
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
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
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
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
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
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 }
Correct
Marks for this submission: 1.00/1.00.
Jump to...
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
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
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
Input
3
10 20 30
60 100 120
50
Output
220
3 220 220
10 20 30
60 100 120
50
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
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
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
1 5 5 5
34 23 12 56 78
78
2 2 -1 -1
67 89
90
Correct
Marks for this submission: 1.00/1.00.
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
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
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 :
Sorted array is
5 6 7 11 12 13
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
1 6 5 6 7 11 12 13 5 6 7 11 12 13
12 11 13 5 6 7
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
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
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:
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
4 .Q.. .Q..
...Q ...Q
Q... Q...
..Q. ..Q.
1 Q Q
Correct
Marks for this submission: 1.00/1.00.
◄ Removing Chocolates
Jump to...
https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=663929&cmid=6020 3/3
07/05/2023, 12:46 Removing Chocolates: Attempt review
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
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
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.
4 4 4
25 1389537 1389537
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
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
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
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 }
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
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
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
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
Input:
1
3 10 17 57
6 2 7 10 15 57 246
Output:
10 57
Input:
1
6123456
216
Output:
16
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
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
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
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
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
https://www.rajalakshmicolleges.net/moodle/mod/quiz/review.php?attempt=667146&cmid=6094 2/3
07/05/2023, 12:33 Quick Sort: Attempt review
1 6 5 6 7 11 12 13 5 6 7 11 12 13
12 11 13 5 6 7
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
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
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:
Example 2:
Input:
3
516
Output:
28
Explanation: The 8 subsets of [5,1,6] are:
Example 3:
Input:
6
345678
Output:
480
Explanation: The sum of all XOR totals for every subset is 480.
Constraints:
1 <= nums.length <= 12
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
2 6 6
1 3
3 28 28
5 1 6
6 480 480
3 4 5 6 7 8
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