You are on page 1of 15

01/02/2023, 08:40 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] M…

 Description  Submission view

Grade
Reviewed on Wednesday, 18 January 2023, 9:18 AM by Automatic grade

Grade: 20.00 / 20.00

Final reduction: 0 [2 / 3 -2] 

Assessment report  [-]

[+]Summary of tests

 Submitted on Wednesday, 18 January 2023, 9:17 AM ( Download)

Subarraysize.cpp
1 #include <iostream>
2 #include <bits/stdc++.h>
3 #include <stdlib.h>
4
5
6 using namespace std;
7
8
9 int df(int z[], int h, int r)
10 {
11
12 if (h < r)
13 {
14 cout << "Invalid";
15 return -1;
16 }
17
18 int d_f = 0;
19
20 int s;
21
22 for ( s = 0; s < r; s++)
23 d_f += z[s];
24
25 int rf = d_f;
26
27 for (int s = r; s < h; s++)
28 {
29 rf += z[s] - z[s - r];
30 d_f = max(d_f, rf);
31 }
32
33 return d_f;
34 }
35
36 int main()
37 {
38 int l;
39
40 int k;
41
42
43 cin>>l;
44
45 cin>>k;
46
47 int arr[l];
48
49 int g;
50
51 for( g=0; g<l; g++)
52 cin>>arr[g];
53 cout << df(arr, l, k);
54 return 0;
55 }

VPL

You are logged in as MOHAMMED MOHSIN JAWED 21BCT0226 (Log out)


Data retention summary
Get the mobile app

© VIT, Vellore.

Support Email ID: support.moovit@vit.ac.in. Please use your vit.ac.in or vitstudent.ac.in email IDs only to request support.

Powered by Moodle

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=48822&userid=98219 1/2
01/02/2023, 08:40 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] M…

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=48822&userid=98219 2/2
01/02/2023, 08:39 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] Ka…

 Description  Submission view

Grade
Reviewed on Sunday, 22 January 2023, 10:03 PM by Automatic grade

Grade: 20.00 / 20.00

Final reduction: 0 [1 / 3 -2] 

Assessment report  [-]

[+]Summary of tests

 Submitted on Sunday, 22 January 2023, 10:03 PM ( Download)

kfm.cpp
1 #include <stdio.h>
2 #include <math.h>
3 #include <iostream>
4 #include <math.h>
5 using namespace std;
6
7 int getSize(long num)
8 {
9 int count = 0;
10 while (num > 0)
11 {
12 count++;
13 num /= 10;
14 }
15 return count;
16 }
17
18 long long karatsuba(long long X,long long Y)
19 {
20 if (X < 10 && Y < 10)
21 return X * Y;
22 int size = fmax(getSize(X), getSize(Y));
23 int n = (int)ceil(size / 2.0);
24 long p = (long)pow(10, n);
25 cout<<"X:"<<X<<", "<<"Y:"<<Y<<endl;
26 long a = (long)floor(X / (double)p);
27 long b = X % p;
28 long c = (long)floor(Y / (double)p);
29 long d = Y % p;
30 cout<<"x1="<<a<<" "<<"x2="<<b<<" "<<"y1="<<c<<" "<<"y2="<<d<<endl<<endl;
31
32 long ac = karatsuba(a, c);
33 long bd = karatsuba(b, d);
34 long e = karatsuba(a + b, c + d) - ac - bd;
35 cout<<"a="<<ac<<" "<<"b="<<e<<" "<<"c="<<bd<<endl<<endl;
36 long long jk = (pow(10 * 1L, 2 * n) * ac + pow(10 * 1L, n) * e + bd);
37 cout<<"xy: "<<jk<<endl;
38 return (long long)(pow(10 * 1L, 2 * n) * ac + pow(10 * 1L, n) * e + bd);
39 }
40 int main()
41 {
42 long long a,b;
43 cin>>a>>b;
44 long long c=karatsuba(a, b);
45 cout<<a<<" * "<<b<<" = "<<c;
46 return 0;
47 }

VPL

You are logged in as MOHAMMED MOHSIN JAWED 21BCT0226 (Log out)


Data retention summary
Get the mobile app

© VIT, Vellore.

Support Email ID: support.moovit@vit.ac.in. Please use your vit.ac.in or vitstudent.ac.in email IDs only to request support.

Powered by Moodle

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=48823&userid=98219 1/2
01/02/2023, 08:39 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] Ka…

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=48823&userid=98219 2/2
01/02/2023, 08:38 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] M…

 Description  Submission view

Grade
Reviewed on Wednesday, 18 January 2023, 8:57 AM by Automatic grade

Grade: 20.00 / 20.00

Final reduction: 0 [2 / 3 -2] 

Assessment report  [-]

[+]Summary of tests

 Submitted on Wednesday, 18 January 2023, 8:57 AM ( Download)

Subarraysum.cpp
1 #include <iostream>
2 #include <bits/stdc++.h>
3 #include <stdlib.h>
4
5
6 using namespace std;
7
8
9 int S_m(int o[], int d, int fn) {
10 int rn = o[0];
11
12 int bg = 0;
13
14 int x;
15
16 for (x = 1; x <= d; x++) {
17
18
19 while (rn > fn && bg < x - 1) {
20
21 rn = rn - o[bg];
22
23 bg++;
24 }
25
26 if (rn == fn) {
27
28 cout << bg+1 << " " << x << endl;
29
30 return 1;
31 }
32
33 if (x < d){
34 rn = rn + o[x];
35 }
36
37 }
38
39 cout << "-1";
40
41 return 0;
42 }
43
44 int main()
45 {
46 int v;
47
48 int S_b_a;
49
50 cin >> v;
51
52 cin >> S_b_a;
53
54 int gh[ v ];
55
56 for(int i=0; i<v; i++)
57 cin>>gh[ i ];
58
59 int n = sizeof(gh) / sizeof(gh[0]);
60
61 S_m(gh, n, S_b_a);
62
63
64 return 0;
65 }

VPL

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=48821&userid=98219 1/2
01/02/2023, 08:38 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] M…

You are logged in as MOHAMMED MOHSIN JAWED 21BCT0226 (Log out)


Data retention summary
Get the mobile app

© VIT, Vellore.

Support Email ID: support.moovit@vit.ac.in. Please use your vit.ac.in or vitstudent.ac.in email IDs only to request support.

Powered by Moodle

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=48821&userid=98219 2/2
01/02/2023, 08:38 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] Fr…

 Description  Submission view

Grade
Reviewed on Wednesday, 18 January 2023, 8:04 AM by Automatic grade

Grade: 20.00 / 20.00

Final reduction: 0 [1 / 2 -2] 

Assessment report  [-]

[+]Summary of tests

 Submitted on Saturday, 14 January 2023, 7:24 PM ( Download)

fkp.cpp

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=47798&userid=98219 1/2
01/02/2023, 08:38 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] Fr…
1 #include<bits/stdc++.h>
2
3 using namespace std;
4
5 double ksack(int z,int jk[],int g[],int q)
6 {
7 double pw[z];
8
9 for(int i=0;i<z;i++){
10 pw[i]= double(g[i])/double(jk[i]);}
11
12
13 for(int i=0;i<z;i++){
14
15
16 for(int j=0;j<(z-1-i);j++){
17
18 if(pw[j]<pw[j+1])
19 {
20 double t;
21
22 t=jk[j];
23
24 jk[j]=jk[j+1];
25
26 jk[j+1]=t;
27
28
29 t=g[j];
30
31 g[j]=g[j+1];
32
33 g[j+1]=t;
34
35
36 t=pw[j];
37
38 pw[j]=pw[j+1];
39
40 pw[j+1]=t;
41
42
43 }}}
44 q;
45
46 double pt=0;
47
48 int i;
49
50 for(i=0;i<z;i++){
51
52
53 if(q>0 && jk[i]<=q)
54
55 {
56 cout<<jk[i]<<" "<<g[i]<<endl;
57
58
59 pt += g[i];
60
61 q -=jk[i];
62 }
63 else
64
65 break;
66 }
67
68 if(q>0 && i<z)
69
70 {
71
72 cout<<q<<" "<< double(pw[i])*double(q)<<endl; //Printing
73
74
75 pt += double(pw[i])*double(q);
76 }
77
78
79 cout<<"Total Profit:"; //Printing
80
81
82 return pt;
83
84 }
85
86 int main()
87 {
88
89 int f,e;
90
91
92 cin>>f; //Taking input
93
94
95 are logged
You int df[f],x[f];
in as MOHAMMED MOHSIN JAWED 21BCT0226 (Log out)
96
97 for(intsummary
Data retention i=0;i<f;i++){
98 cin>>df[i];}
Get
99 the mobile app

100
© VIT, Vellore.
101 for(int
i=0;i<f;i++){
102 cin>>x[i];}
Support Email ID: support.moovit@vit.ac.in. Please use your vit.ac.in or vitstudent.ac.in
103 email IDs only to request support.
104
105 cin>>e;
106
107
Poweredcout<<ksack(f,df,x,e);
by Moodle
108
109
110 }

VPL

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=47798&userid=98219 2/2
01/02/2023, 08:37 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] Hu…

 Description  Submission view

 Submitted on Saturday, 14 January 2023, 7:58 PM ( Download)

Automatic evaluation  [-]

Proposed grade: 0 / 20

Final reduction: 0 [2 / 2 -2]

Comments  [-]

[+]Failed tests

[+]Test 1: 1

[+]Test 2: 2

[+]Summary of tests

he.cpp

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=47797&userid=98219 1/3
01/02/2023, 08:37 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] Hu…
1 #include <iostream>
2 #include <vector>
3 #include <queue>
4 #include <string>
5
6 using namespace std;
7
8 class Huffman_Codes
9 {
10 struct New_Node
11 {
12 char data;
13 size_t freq;
14 New_Node* left;
15 New_Node* right;
16 New_Node(char data, size_t freq) : data(data),
17 freq(freq),
18 left(NULL),
19 right(NULL)
20 {}
21 ~New_Node()
22 {
23 delete left;
24 delete right;
25 }
26 };
27
28 struct compare
29 {
30 bool operator()(New_Node* l, New_Node* r)
31 {
32 return (l->freq > r->freq);
33 }
34 };
35
36 New_Node* top;
37
38 void print_Code(New_Node* root, string str)
39 {
40 if(root == NULL)
41 return;
42
43 if(root->data == '$')
44 {
45 print_Code(root->left, str + "0");
46 print_Code(root->right, str + "1");
47 }
48
49 if(root->data != '$')
50 {
51 cout << root->data <<" : " << str << "\n";
52 print_Code(root->left, str + "0");
53 print_Code(root->right, str + "1");
54 }
55 }
56
57 public:
58 Huffman_Codes() {};
59 ~Huffman_Codes()
60 {
61 delete top;
62 }
63 void Generate_Huffman_tree(vector<char>& data, vector<size_t>& freq, size_t size)
64 {
65 New_Node* left;
66 New_Node* right;
67 priority_queue<New_Node*, vector<New_Node*>, compare > minHeap;
68
69 for(size_t i = 0; i < size; ++i)
70 {
71 minHeap.push(new New_Node(data[i], freq[i]));
72 }
73
74 while(minHeap.size() != 1)
75 {
76 left = minHeap.top();
77 minHeap.pop();
78
79 right = minHeap.top();
80 minHeap.pop();
81
82 top = new New_Node('$', left->freq + right->freq);
83 top->left = left;
84 top->right = right;
85 minHeap.push(top);
86 }
87 print_Code(minHeap.top(), "");
88 }
89 };
90
91 int main()
92 {
93 int n, f;
94 char ch;
95 Huffman_Codes set1;
96 vector<char> data;
97 vector<size_t> freq;
98
99 cin>>n;
100
101 for (int i=0;i<n;i++)
102
You are{ logged in as MOHAMMED MOHSIN JAWED 21BCT0226 (Log out)
103 cin>>ch;
104
Data data.insert(data.end(),
retention summary ch);
105 }
Get the mobile app

106
107 for (int i=0;i<n;i++)
© VIT, Vellore.
108 {

109 cin>>f;
Support Email ID: support.moovit@vit.ac.in.
110 freq.insert(freq.end(), f); Please use your vit.ac.in or vitstudent.ac.in email IDs only to request support.
111 }
112
113 size_t size = data.size();
114
Poweredset1.Generate_Huffman_tree(data,
by Moodle freq, size);
115
116 return 0;
117 }

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=47797&userid=98219 2/3
01/02/2023, 08:37 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] Hu…

VPL

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=47797&userid=98219 3/3
01/02/2023, 08:37 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] N …

 Description  Submission view

 Submitted on Monday, 19 December 2022, 9:49 PM ( Download)

Automatic evaluation  [-]

Proposed grade: 20 / 20

Final reduction: 0 [1 / 2 -2]

Comments  [-]

[+]Summary of tests

nsel.cpp
1 #include <bits/stdc++.h>
2 #include <stdlib.h>
3 using namespace std;
4 struct Act
5 {
6 int p,q;
7 };
8 bool S_act(Act s0, Act s1)
9 {
10 return (s0.q< s1.q);
11 }
12 void print_Maxim_Act(Act arr[ ], int a)
13 {
14 sort(arr, arr+a, S_act);
15 int i = 0;
16 cout<< arr[i].p<<" " <<arr[i].q<<"\n";
17 for (int j = 1; j < a; j++)
18 {
19 if (arr[j].p>= arr[i].q)
20 {
21 cout<< arr[j].p<<" "<<arr[j].q<<"\n";
22 i = j;
23 }
24 }
25 }
26
27 int main()
28 {
29 int a;
30 cin>>a;
31
32 Act arr[a];
33 for(int i=0; i<=a-1; i++)
34 {
35 cin>>arr[i].p;
36 }
37 for(int j=0; j<=a-1; j++)
38 {
39 cin>>arr[j].q;
40 }
41
42 print_Maxim_Act(arr, a);
43 return 0;
44 }

VPL

You are logged in as MOHAMMED MOHSIN JAWED 21BCT0226 (Log out)


Data retention summary
Get the mobile app

© VIT, Vellore.

Support Email ID: support.moovit@vit.ac.in. Please use your vit.ac.in or vitstudent.ac.in email IDs only to request support.

Powered by Moodle

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=47796&userid=98219 1/2
01/02/2023, 08:37 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] N …

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=47796&userid=98219 2/2
01/02/2023, 08:30 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] Ac…

 Description  Submission view

Grade
Reviewed on Wednesday, 21 December 2022, 8:17 AM by Automatic grade

Grade: 18.00 / 20.00

Final reduction: 2 [3 / 2 -2] 

Assessment report  [-]

[+]Summary of tests

 Submitted on Monday, 19 December 2022, 10:10 PM ( Download)

asp.cpp
1 #include <bits/stdc++.h>
2 #include <stdlib.h>
3 using namespace std;
4
5 void print_Maxim_Act(int k[], int l[], int m)
6 {
7 int w, z;
8
9 w=0;
10
11 cout<< w << " ";
12
13 for(z = 1; z < m; z++)
14 {
15
16 if(k[z] >= l[w])
17 {
18 cout << z << " ";
19 w = z;
20 }
21 }
22 }
23
24 int main()
25 {
26 int m;
27 cin >> m;
28 int k[m],l[m];
29 for(int i=0; i<m; i++)
30 {
31 cin >> k[i];
32 }
33 for(int i=0; i<m; i++)
34 {
35 cin >> l[i];
36 }
37
38 print_Maxim_Act(k, l, m);
39
40 return 0;
41 }

VPL

You are logged in as MOHAMMED MOHSIN JAWED 21BCT0226 (Log out)


Data retention summary
Get the mobile app

© VIT, Vellore.

Support Email ID: support.moovit@vit.ac.in. Please use your vit.ac.in or vitstudent.ac.in email IDs only to request support.

Powered by Moodle

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=47795&userid=98219 1/2
01/02/2023, 08:30 BCSE204P Design and Analysis of Algorithms Lab (Lab) Winter 2022-23 (L13+L14) [VL2022230504119] Ac…

https://moovit.vit.ac.in/mod/vpl/forms/submissionview.php?id=47795&userid=98219 2/2

You might also like