Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Longest Bitonic Subsequence #1960 #1975

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions 2D_Array/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

However, 2D arrays are created to implement a relational database look alike data structure. It provides ease of holding bulk of data at once which can be passed to any number of functions wherever required.

## How to declare a 2D array?
The syntax of declaring two dimensional array is very much similar to that of a one dimensional array, given as follows:-
int arr[max_rows][max_columns];

## How do we access data in a 2D array
Due to the fact that the elements of 2D arrays can be random accessed. Similar to one dimensional arrays, we can access the individual cells in a 2D array by using the indices of the cells. There are two indices attached to a particular cell, one is its row number while the other is its column number.

Expand Down
34 changes: 34 additions & 0 deletions Code/Insertion at start.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdio.h>

#define MAX 5

void main() {
int array[MAX] = {2, 3, 4, 5};
int N = 4;
int i = 0;
int value = 1;

printf("Printing array before insertion −\n");

for(i = 0; i < N; i++) {
printf("array[%d] = %d \n", i, array[i]);
}


for(i = N; i >= 0; i--) {
array[i+1] = array[i];
}


array[0] = value;


N++;


printf("Printing array after insertion −\n");

for(i = 0; i < N; i++) {
printf("array[%d] = %d\n", i, array[i]);
}
}
37 changes: 37 additions & 0 deletions Longest Bitonic Subsequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def calculateLBS(A):


I = [0] * len(A)


D = [0] * len(A)

n = len(A) - 1

I[0] = 1
for i in range(1, n + 1):
for j in range(i):
if A[j] < A[i] and I[j] > I[i]:
I[i] = I[j]
I[i] = I[i] + 1

D[n] = 1
for i in reversed(range(n)):
for j in range(n, i, -1):
if A[j] < A[i] and D[j] > D[i]:
D[i] = D[j]
D[i] = D[i] + 1


lbs = 1
for i in range(n + 1):
lbs = max(lbs, I[i] + D[i] - 1)

return lbs


if __name__ == '__main__':

A = [4, 2, 4, 9, 7, 6, 14, 3, 3]

print("The length of the longest bitonic subsequence is", calculateLBS(A))
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[![Stars](https://img.shields.io/github/stars/Algo-Phantoms/Algo-Tree?style=social)](https://github.com/Algo-Phantoms/Algo-Tree)
[![Watchers](https://img.shields.io/github/watchers/Algo-Phantoms/Algo-Tree?style=social)](https://github.com/Algo-Phantoms/Algo-Tree)

**Algo-Tree** is a collection of Algorithms and data structures which are fundamentals to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. It contains solutions in various languages such as ``C++``, ``Python`` and ``Java``.
**Algo-Tree** is a collection of Algorithms and data structures which are fundamentals to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. It contains solutions in various languages such as ``C``, ``C++``, ``Python`` and ``Java``.

# Code Structure
* [Array](/Array)
Expand Down