Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions C-C++/(0-1)KnapSack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ int main()
int profit[100], weight[100], w_max, n, i, total;
cout << "Enter no of items: ";
cin >> n;

cout << "Enter profits respectively: ";
for(i = 0; i < n; i++)
cin >> profit[i];
printf("Enter the weights respectively: ");

cout << "Enter the weights respectively: ";
for(i = 0; i < n; i++)
cin >> weight[i];

cout << "Enter max capacity: ";
cin >> w_max;

total = knapsack(weight, profit, n, w_max);
cout << "\nTotal profit: " << total << endl;

return 0;
}
Binary file added C-C++/(0-1)KnapSack.exe
Binary file not shown.
Binary file added C-C++/(0-1)KnapSack.o
Binary file not shown.
Binary file added C-C++/Fibonacci_Search.exe
Binary file not shown.
Binary file added C-C++/Fibonacci_Search.o
Binary file not shown.
Binary file added C-C++/Longest_Palindromic_Subsequence.exe
Binary file not shown.
Binary file added C-C++/Longest_Palindromic_Subsequence.o
Binary file not shown.
20 changes: 11 additions & 9 deletions C-C++/activitySelection(DP).cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,36 @@ int activity_dp(activity a[], int i, int finish)
{
if(i == n)
return 0;

int x = 0, y = 0;

if(matrix[i][finish] != -1)
return matrix[i][finish];

x = activity_dp(a, i + 1, finish);

if(a[i].s >= finish)
y = activity_dp(a, i + 1, a[i].f) + 1;

return matrix[i][finish] = max(x, y);
}

int main()
{
cout<<"enter value of n";

cin>>n;
cout<<"Start time <space> Finish time"<<endl;

activity a[5];
for(int i = 0; i < n; i++)
{
cin>>a[i].s;
cin>>a[i].f;
}
memset(matrix, -1, sizeof(matrix));

cout << activity_dp(a, 0, 0);

return 0;
}
}
Binary file added C-C++/activitySelection(DP).exe
Binary file not shown.
Binary file added C-C++/activitySelection(DP).o
Binary file not shown.
7 changes: 4 additions & 3 deletions C-C++/binarySearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ int binarySearch(int a[], int x, int l, int r)
int main()
{
int n, x;
cout<<"enter number of elements :";
cin>>n;
int a[n];

cout<<"enter array elements \n";
for(int i = 0; i < n ; i++)
cin>>a[i];

cout<<"enter search element :";
cin>>x;

int flag = binarySearch(a, x, 0, n-1);
Expand All @@ -39,4 +40,4 @@ int main()
cout<<"Present at pos: "<<flag+1<<endl;

return 0;
}
}
Binary file added C-C++/binarySearch.exe
Binary file not shown.
Binary file added C-C++/binarySearch.o
Binary file not shown.
28 changes: 28 additions & 0 deletions C-C++/tower of hanoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* C program for Tower of Hanoi using Recursion
*/
#include <stdio.h>

void towers(int, char, char, char);

int main()
{
int num;

printf("Enter the number of disks : ");
scanf("%d", &num);
printf("The sequence of moves involved in the Tower of Hanoi are :\n");
towers(num, 'A', 'C', 'B');
return 0;
}
void towers(int num, char frompeg, char topeg, char auxpeg)
{
if (num == 1)
{
printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg);
return;
}
towers(num - 1, frompeg, auxpeg, topeg);
printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
towers(num - 1, auxpeg, topeg, frompeg);
}
Binary file added C-C++/tower of hanoi.exe
Binary file not shown.
Binary file added C-C++/tower of hanoi.o
Binary file not shown.