Skip to content

Commit d270222

Browse files
authored
Merge branch 'Py-Contributors:master' into master
2 parents 7d85939 + 7d8517d commit d270222

File tree

5 files changed

+182
-17
lines changed

5 files changed

+182
-17
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.util.*;
2+
3+
class KadanesAlgo
4+
{
5+
public static void main (String[] args) throws java.lang.Exception
6+
{
7+
8+
Scanner sc=new Scanner(System.in);
9+
System.out.print("Enter the number of elements you want to store: ");
10+
int n=sc.nextInt();
11+
int[] a = new int[100];
12+
System.out.println("Enter the elements of the array: ");
13+
for(int i=0; i<n; i++) {
14+
a[i]=sc.nextInt();
15+
}
16+
int local_max = 0;
17+
int global_max = Integer.MIN_VALUE;
18+
19+
for(int i=0;i<n;i++)
20+
{
21+
local_max = Math.max(a[i], a[i] + local_max);
22+
23+
if(local_max > global_max)
24+
{
25+
global_max = local_max;
26+
}
27+
28+
}
29+
System.out.println("Maximum Subarray sum: " +global_max);
30+
}
31+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import java.util.Scanner;
2+
3+
class LCSExample1 {
4+
public static String findLengthOfLCS(String str1, String str2, int p, int q) {
5+
int[][] tableForLCS = new int[p + 1][q + 1];
6+
for (int i = 0; i <= p; i++) {
7+
for (int j = 0; j <= q; j++) {
8+
if (i == 0 || j == 0)
9+
tableForLCS[i][j] = 0;
10+
else if (str1.charAt(i - 1) == str2.charAt(j - 1))
11+
tableForLCS[i][j] = tableForLCS[i - 1][j - 1] + 1;
12+
else
13+
tableForLCS[i][j] = Math.max(tableForLCS[i - 1][j], tableForLCS[i][j - 1]);
14+
}
15+
}
16+
int index = tableForLCS[p][q];
17+
int temp = index;
18+
char[] longestCommonSubsequence = new char[index + 1];
19+
longestCommonSubsequence[index] = '\0';
20+
int i = p, j = q;
21+
String lcs ="";
22+
while (i > 0 && j > 0) {
23+
if (str1.charAt(i - 1) == str2.charAt(j - 1)) {
24+
25+
longestCommonSubsequence[index - 1] = str1.charAt(i - 1);
26+
i--;
27+
j--;
28+
index--;
29+
}
30+
else if (tableForLCS[i - 1][j] > tableForLCS[i][j - 1])
31+
i--;
32+
else
33+
j--;
34+
}
35+
for (int k = 0; k <= temp; k++)
36+
lcs = lcs + longestCommonSubsequence[k];
37+
38+
return lcs;
39+
}
40+
public static void main(String[] args) {
41+
42+
String str1, str2, LCS;
43+
44+
Scanner sc= new Scanner(System.in);
45+
System.out.print("Enter first sequence: ");
46+
str1 = sc.nextLine();
47+
48+
System.out.print("Enter second sequence: ");
49+
str2 = sc.nextLine();
50+
51+
int p = str1.length();
52+
int q = str2.length();
53+
54+
LCS = findLengthOfLCS(str1, str2, p, q);
55+
56+
System.out.println("LCS: "+LCS);
57+
58+
}
59+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.util.*;
2+
3+
public class LIS {
4+
public static void main(String[] args){
5+
6+
Scanner sc=new Scanner(System.in);
7+
System.out.print("Enter the number of elements you want to store: ");
8+
int n=sc.nextInt();
9+
int[] nums= new int[100];
10+
System.out.println("Enter the elements of the array: ");
11+
for(int i=0; i<n; i++) {
12+
nums[i]=sc.nextInt();
13+
}
14+
printLIS(nums);
15+
}
16+
public static void printLIS(int[] nums){
17+
String[] paths = new String[nums.length];
18+
int[] sizes = new int[nums.length];
19+
20+
for(int i=0; i<nums.length; i++){
21+
sizes[i] = 1;
22+
paths[i] = nums[i] + " " ;
23+
}
24+
int maxLength = 1;
25+
26+
for(int i=1; i<nums.length; i++){
27+
for(int j=0; j<nums.length; j++){
28+
if(nums[i]>nums[j] && sizes[i] < sizes[j] + 1){;
29+
sizes[i] = sizes[j] + 1;
30+
paths[i] = paths[j] + nums[i] + " ";
31+
if(maxLength < sizes[i])
32+
maxLength = sizes[i];
33+
}
34+
}
35+
}
36+
for(int i=1; i<nums.length; i++){
37+
if(sizes[i] == maxLength)
38+
System.out.println("LIS: " + paths[i]);
39+
}
40+
}
41+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.util.*;
2+
3+
public class Subsequences {
4+
public static void main(String[] args) {
5+
Scanner sc=new Scanner(System.in);
6+
System.out.print("Enter the number of elements you want to store: ");
7+
int n=sc.nextInt();
8+
int[] arr= new int[100];
9+
System.out.println("Enter the elements of the array: ");
10+
for(int i=0; i<n; i++) {
11+
arr[i]=sc.nextInt();
12+
}
13+
System.out.print("Enter Sum: ");
14+
int X = sc.nextInt();
15+
System.out.println(countSubsequence(arr, n, X));
16+
}
17+
18+
public static int countSubsequence(int[] A, int N, int X) {
19+
int[][] dp = new int[N+1][X+1];
20+
for (int[] row : dp) {
21+
Arrays.fill(row, 0);
22+
}
23+
for (int i = 0; i <= N; i++) {
24+
for (int j = 0; j <= X; j++) {
25+
if (i == N) {
26+
dp[i][j] = 1;
27+
}
28+
}
29+
}
30+
31+
for (int i = N-1; i >= 0; i--) {
32+
for (int j = 1; j <= X; j++) {
33+
if (A[i] <= j) {
34+
dp[i][j] = dp[i+1][j] + dp[i+1][j-A[i]];
35+
} else {
36+
dp[i][j] = dp[i+1][j];
37+
}
38+
}
39+
}
40+
System.out.print("Number of Subsequences with sum less than or equal to given sum: ");
41+
return dp[0][X] - 1;
42+
}
43+
}

README.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<p align="center">
2-
<a href="http://codeperfectplus.herokuapp.com/"><img src="https://capsule-render.vercel.app/api?type=rect&color=666666&height=100&section=header&text=Algorithms%20And%20Data%20Structures&fontSize=55%&fontColor=ffffff&fontAlignY=65" alt="website title image"></a>
2+
<a href="http://codeperfectplus.com/"><img src="https://capsule-render.vercel.app/api?type=rect&color=666666&height=100&section=header&text=Algorithms%20And%20Data%20Structures&fontSize=55%&fontColor=ffffff&fontAlignY=65" alt="website title image"></a>
33
<h2 align="center">👉 A Collection of Algorithms And Data Structures in C++ and Python 👈</h2>
44
</p>
55

66
<p align="center">
7-
<a href="http://codeperfectplus.herokuapp.com/"><img src="https://capsule-render.vercel.app/api?type=rect&color=666444&height=40&section=header&text=Hacktoberfest%20Excluded&fontSize=35%&fontColor=ffffff&fontAlignY=65" alt="website title image"></a>
7+
<a href="http://codeperfectplus.com/"><img src="https://capsule-render.vercel.app/api?type=rect&color=666444&height=40&section=header&text=Hacktoberfest%20Excluded&fontSize=35%&fontColor=ffffff&fontAlignY=65" alt="website title image"></a>
88
</p>
99

1010
<p align="center">
@@ -31,25 +31,17 @@
3131
<a href="https://api.github.com/repos/codeperfectplus/AlgorithmsAndDataStructure/contributors"><img src="https://img.shields.io/github/contributors/codeperfectplus/AlgorithmsAndDataStructure?style=for-the-badge" alt="total contributors"></a>
3232
</p>
3333

34-
3534
- [Introduction](#introduction)
3635
- [Data Structures](#data-structures) <!-- Data Structure hyperlink in the readme doesn't link #925 issue solved. P.S. It was a typo -->
3736
- [Algorithms](#algorithms)
3837
- [Languages](#languages)
3938
- [Support](#support)
4039
- [Project Progress](#project-progress)
4140
- [Contributing](#contributing)
42-
- [Authors and acknowledgment](#authors-and-acknowledgment)
41+
- [Authors and acknowledgement](#authors-and-acknowledgement)
4342
- [License](#license)
4443
- [Maintainers](#maintainers)
4544

46-
47-
**Anyone Interested in managing the repository for the upcoming HacktoberFest2021, email us at `pycontributors@gmail.com`**
48-
49-
- Must be a student
50-
- Must have knowledge of Git Commands ex- branching, merging etc
51-
- Must have Python/C++ DS and Algo knowledge to review code.
52-
5345
## Introduction
5446

5547
Data structures & algorithms are an essential part of programming. They both fall under the fundamentals of computer science. Understanding these gives us the advantage of writing better and more efficient code in less time. They are key topics when it comes to acing software engineering interview questions, so as developers, we must have knowledge of data structures and algorithms.
@@ -58,7 +50,6 @@ Data structures & algorithms are an essential part of programming. They both fal
5850
:fork_and_knife:Fork it
5951
:handshake: Contribute to it!
6052

61-
6253
## Data Structures
6354

6455
In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification.
@@ -89,9 +80,9 @@ Check [Contribution](/CONTRIBUTING.md) Guide Before Contribution.
8980
- Create separate issues for Python and C++.
9081
- You can only work on issues that you have been assigned to.
9182
- Use Flake8 locally for linting Python Code. `pip install flake8`.
92-
(We have linting checks so if your code fails it we will not merge the PR.)
83+
(We have linting checks so if your code fails we will not merge the PR.)
9384

94-
## Authors and acknowledgment
85+
## Authors and acknowledgement
9586

9687
Show your appreciation to those who have contributed to the project.
9788

@@ -135,9 +126,9 @@ For open-source projects, Under [MIT License](/LICENSE).
135126

136127
## Must Read Articles
137128

138-
- [5 Tips for computer programming begineers](https://codeperfectplus.herokuapp.com/5-tips-for-computer-programming-beginners)
139-
- [What is HacktoberFest](https://codeperfectplus.herokuapp.com/what-is-hacktoberfest)
140-
- [What is Git and Github](https://codeperfectplus.herokuapp.com/what-is-git-and-gitHub)
129+
- [How to Solve Linear Equations with Matrix Inversion](https://codeperfectplus.com/how-to-solve-linear-equations-with-matrix-inversion)
130+
- [HackerRank Algorithms Solutions using Python and C++](https://codeperfectplus.com/hackerrank-algorithms-solutions-using-python-and-c-cpp)
131+
- [30 Days of Code - HackerRank](https://codeperfectplus.com/category/hackerank-30daysofcode/)
141132

142133
<p align="center">
143134
<a href="https://api.github.com/repos/py-contributors/AlgorithmsAndDataStructure/contributors"><img src="http://ForTheBadge.com/images/badges/built-by-developers.svg" alt="built by developers"></a>

0 commit comments

Comments
 (0)