Category : recursion

I wrote a recursive solution for the longest increasing subsequence and it worked perfectly fine. But when I applied dp on the same code it gives different answers. Problem Link: https://practice.geeksforgeeks.org/problems/longest-increasing-subsequence-1587115620/1 Recursive code: int LIS(int arr[], int n, int currIndex, int maxVal) { if (currIndex == n) { return 0; } int included = 0, ..

Read more

I’m having trouble using Boost Serialization library with a recursive data structure. More precisely, I want to serialize a matrix which is represented by nodes containing a value, and where each node has access to its neighboors (top,bottom,left,right). In order to access a node, each entry point is stored in a vector (that is the ..

Read more

int hieght(BinaryTreeNode<int> *root) { if(root==NULL) { return 0; } int smallOutput1 = hieght(root->left); int smallOutput2 = hieght(root->right); if(smallOutput1>smallOutput2) { return smallOutput1+1; } else { return smallOutput2+1; } } int Diameter(BinaryTreeNode<int> *root) { if(root==NULL) { return 0; } int option1 = hieght(root->left) + hieght(root->right); int option2 = Diameter(root->left); int option3 = Diameter(root->right); return max(option1,max(option2,option3)); } According ..

Read more