diff --git a/2D_Array/readme.md b/2D_Array/readme.md index c87880446..407883c5b 100644 --- a/2D_Array/readme.md +++ b/2D_Array/readme.md @@ -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. diff --git a/Code/Insertion at start.c b/Code/Insertion at start.c new file mode 100644 index 000000000..d434b3cd7 --- /dev/null +++ b/Code/Insertion at start.c @@ -0,0 +1,34 @@ +#include + +#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]); + } +} \ No newline at end of file diff --git a/Longest Bitonic Subsequence.py b/Longest Bitonic Subsequence.py new file mode 100644 index 000000000..183659c97 --- /dev/null +++ b/Longest Bitonic Subsequence.py @@ -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)) \ No newline at end of file diff --git a/README.md b/README.md index bb452cd42..0db4f09e4 100644 --- a/README.md +++ b/README.md @@ -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)