ru
Feedback
inactive

inactive

Закрытый канал
3 849
Подписчики
Нет данных24 часа
-297 дней
-12730 день
Архив постов
😍

🎉 Exciting News! 🎉 Get ready for the most fun-filled event of the year, *Comic Junction*, presented by *PENTAOMINA*, the st
🎉 Exciting News! 🎉 Get ready for the most fun-filled event of the year, *Comic Junction*, presented by *PENTAOMINA*, the student organization under the aegis of the Division of Youth Affairs and the Division of the Student Wing at LPU. 🌟 Date & Time: 20th October 2023, 5pm onwards 🏢 Venue: Shanti Devi Mittal Auditorium By purchasing just one ticket for 249 Rupees, you'll unlock a world of benefits worth 3K+ rewards: 🛍️ Voucher worth 500 from Trend Mall 📚 MOOC courses free on Coursera 💇‍♂️ 10% off on services at LIVN Salon in Unimall 🍔 10% off at Victuals: The Movable Restaurant 💰 Cashback benefits of up to Rs. 400 when you install the Rupeya app through our link Plus, there are tons of exciting goodies waiting for you! Hurry, there are limited tickets available! 🎫 Grab yours now at ticket counters 13, 28, and 33 blocks. Don't miss out on this epic event! 🚀 #ComicJunction #RupeyaApp #LPUEvents

Guyz show some support to him ✨

#include <iostream> using namespace std; struct TreeNode { int val; TreeNode* left; TreeNode* right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; TreeNode* insert(TreeNode* root, int val) { if (root == NULL) { return new TreeNode(val); } if (val < root->val) { root->left = insert(root->left, val); } else { root->right = insert(root->right, val); } return root; } int kthSmallest(TreeNode* root, int k) { TreeNode* current = root; int count = 0; int kthSmallest = -1; while (current != NULL) { if(current->left == NULL) { count++; if (count == k) { kthSmallest = current->val; } current = current->right; } else { TreeNode* predecessor = current->left; while (predecessor->right != NULL && predecessor->right != current) { predecessor = predecessor->right; } if (predecessor->right == NULL) { predecessor->right = current; current = current->left; } else { predecessor->right = NULL; count++; if (count == k) { kthSmallest = current->val; } current = current->right; } } } return kthSmallest; } int main() { TreeNode* root = NULL; int val; while (true) { cin >> val; if (val == -1) { break; } root = insert(root, val); } int k; cin >> k; int kthSmallestValue = kthSmallest(root, k); cout << "Smallest kth value " << kthSmallestValue << endl; //awasthi return 0; }

Kamal is developing a program that finds the Kth smallest element in a Binary Search Tree (BST). He plans to use the Morris Traversal technique to optimize the search process. Your task is to assist Kamal in verifying and testing his code. Implement a program that performs the following actions: Build a Binary Search Tree (BST) by adding integers to it one by one. Find and print the Kth smallest element in the BST. Input format : The first n lines of input consist of a series of positive integers (greater than zero) separated by space. The input ends when a value (-1) is entered. The last input of an integer represents the elements to be inserted into the binary search tree. Output format : After inserting all the elements into the binary search tree, the program should take an additional input k representing the k-th smallest element to be found in the BST. The output displays the k-th smallest element in the BST.

#include <iostream> using namespace std; struct Node { int data; Node* left; Node* right; }; Node* createNode(int value) { Node* newNode = new Node(); newNode->data = value; newNode->left = NULL; newNode->right = NULL; return newNode; } Node* insertNode(Node* root, int value) { if (root == NULL) { return createNode(value); } else if (value <= root->data) { root->left = insertNode(root->left, value); } else { root->right = insertNode(root->right, value); } return root; } bool searchKey(Node* root, int key) { if (root == NULL) { return false; } else if (key == root->data) { return true; } else if (key <= root->data) { return searchKey(root->left, key); } else { return searchKey(root->right, key); } } int main() { Node* root = NULL; int numNodes, value, key; cin >> numNodes; for (int i = 0; i < numNodes; i++) { cin >> value; root = insertNode(root, value); } cin >> key; bool found = searchKey(root, key); if (found) { cout << "The key " << key << " is found in the binary search tree" << endl; } else { cout << "The key " << key << " is not found in the binary search tree" << endl; } //awasthi return 0; }

Ragul wants to build a binary search tree (BST) and perform a key search operation on it. He needs your help to accomplish this. Write a program that helps Ragul create a BST and search for a specific key within it. Note: This kind of question will help in clearing Wipro recruitment. Input format : The first line of input consists of the number of nodes n. The second line of input consists of n unique values for nodes, separated by a space. The third line of input consists of the key to be searched. Output format : The output displays one of the following messages based on whether the key is found in the binary search tree or not in the following format: If the key is found in the binary search tree, print "The key <> is found in the binary search tree" If the key is not found in the binary search tree, print "The key <> is not found in the binary search tree"

#include <iostream> using namespace std; struct Node { char data; Node* left; Node* right; }; Node* insert(Node* root, char data) { if (root == NULL) { root = new Node(); root->data = data; root->left = root->right = NULL; } else if (data <= root->data) { root->left = insert(root->left, data); } else { root->right = insert(root->right, data); } return root; } Node* findMin(Node* root) { while (root->left != NULL) { root = root->left; } return root; } Node* deleteNode(Node* root, char data) { if (root == NULL) { return root; } else if (data < root->data) { root->left = deleteNode(root->left, data); } else if (data > root->data) { root->right = deleteNode(root->right, data); } else { // The node to be deleted is found if (root->left == NULL && root->right == NULL) { // Leaf node delete root; root = NULL; } else if (root->left == NULL) { // Node with one child (right child) Node* temp = root->right; delete root; root = temp; } else if (root->right == NULL) { // Node with one child (left child) Node* temp = root->left; delete root; root = temp; } else { // Node with two children // Find the inorder successor of the node to be deleted Node* successor = findMin(root->right); // Copy the value of the inorder successor to the node to be deleted root->data = successor->data; // Delete the inorder successor root->right = deleteNode(root->right, successor->data); } } return root; } void inOrderTraversal(Node* root) { if (root == NULL) { return; } inOrderTraversal(root->left); cout << root->data << " "; inOrderTraversal(root->right); } int main() { int n; cin >> n; char arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } Node* root = NULL; for (int i = 0; i < n; i++) { root = insert(root, arr[i]); } char dataToDelete; cin >> dataToDelete; root = deleteNode(root, dataToDelete); inOrderTraversal(root); cout << endl; //awasthi return 0; }

Preethi is fascinated by trees, especially binary search trees. She wants to create a binary search tree (BST) of characters and perform deletion operations on it. She wants you to help her write a program. Preethi needs a program that allows her to: Create a binary search tree by inserting a series of characters. Delete a specific character from the binary search tree. Print the characters in the BST in an in-order traversal. Note Each character inserted into the binary search tree is a number, special character, lowercase letter, or uppercase letter. The characters are inserted based on their respective ASCII value. All inserted characters into the binary search tree will be unique. Input format : The first line of input consists of the number of characters N. The second line of input consists of N unique characters separated by a space. The third line of input consists of the character M to be deleted. Output format : The output displays the in-order traversal of the given inputs after deleting the character M.

#include <iostream> #include <cstring> using namespace std; const int MAX_NODES = 100; struct TreeNode { int val; TreeNode* left; TreeNode* right; TreeNode() : val(0), left(nullptr), right(nullptr) {} TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {} }; int ans[MAX_NODES]; int idx = 0; void postorder(TreeNode* root) { if (root == nullptr) return; postorder(root->left); postorder(root->right); ans[idx++] = root->val; } void fillArray(TreeNode* root) { postorder(root); } int* postorderTraversal(TreeNode* root) { fillArray(root); return ans; } TreeNode* createTree(int arr[], int i, int n) { TreeNode* newNode = nullptr; if (i < n) { newNode = new TreeNode(arr[i]); newNode->left = createTree(arr, 2 * i + 1, n); newNode->right = createTree(arr, 2 * i + 2, n); } return newNode; } //awasthi int main() { int n; cin >> n; int arr[MAX_NODES]; for (int i = 0; i < n; ++i) { cin >> arr[i]; } TreeNode* root = createTree(arr, 0, n); int* postorderResult = postorderTraversal(root); for (int i = 0; i < n; ++i) { cout << postorderResult[i] << " "; } return 0; }

Dharshan is working on a program that involves binary trees. He needs to implement a program that calculates the post-order traversal of a binary tree. Specifically, he needs to create a function that, given the root of a binary tree, returns an array containing the post-order traversal of the tree. Note: The binary tree can have a maximum of 100 nodes. All node values in the binary tree are unique. For a node at index i in the input array, Its left child is at index 2 * i + 1, and its right child is at index 2 * i + 2. The array represents the binary tree's structure, with each index corresponding to a node and its value. Input format : The first line contains an integer n, representing the number of elements in the array. The second line contains n space-separated integers, arr [i], representing the values of the nodes in the binary tree. The elements are given in the order of a binary tree, where the i-th element is the value of the i-th node. Output format : The output displays a single line containing n space-separated integers, which represent the postorder traversal of the binary tree constructed from the input array.

#include <stdio.h> #include <stdlib.h> struct node { int data; struct node* left; struct node* right; }; struct node* root = NULL; void append(int d) { struct node* new_node = (struct node*)malloc(sizeof(struct node)); new_node->data = d; new_node->left = NULL; new_node->right = NULL; if (root == NULL) { root = new_node; } else { struct node* current = root; struct node* parent = NULL; while (1) { parent = current; if (d < current->data) { current = current->left; if (current == NULL) { parent->left = new_node; return; } } else { current = current->right; if (current == NULL) { parent->right = new_node; return; } } } } } void postorder(struct node* root) { if (root == NULL) { return; } postorder(root->left); postorder(root->right); printf("%d ", root->data); } //awasthi int main() { int d; do { scanf("%d", &d); if (d > 0) { append(d); } } while (d != -1); //awasthi printf("Post order Traversal:\n"); postorder(root); printf("\n"); return 0; }

Madhu is responsible for developing a program to manage a task scheduler. Each task is identified by a unique task ID, which is a positive integer. Your task is to implement a program that reads task IDs as input until a sentinel value (-1) is entered, constructs a binary search tree with the task IDs, and then performs post-order traversal to display the tasks in the scheduler. Input format : The input consists of a series of positive integers representing the product IDs of items added to the shopping cart. The input ends when a negative integer (-1) is entered. Output format : The post-order traversal of the binary search tree displays the product IDs of items in the shopping cart.

#include <iostream> using namespace std; struct Node { int data; Node* left; Node* right; Node(int d) : data(d), left(nullptr), right(nullptr) {} }; Node* insert(Node* root, int data) { if (root == nullptr) { return new Node(data); } else { Node* cur; if (data <= root->data) { cur = insert(root->left, data); root->left = cur; } else { cur = insert(root->right, data); root->right = cur; } return root; } } void postOrderTraversal(Node* root) { if (root == nullptr) { return; } postOrderTraversal(root->left); postOrderTraversal(root->right); cout << root->data << " "; } int maxHeight(Node* root) { if (root == nullptr) { return -1; } int leftHeight = maxHeight(root->left); int rightHeight = maxHeight(root->right); return max(leftHeight, rightHeight) + 1; } int main() { int n; cin >> n; Node* root = nullptr; for (int i = 0; i < n; ++i) { int data; cin >> data; root = insert(root, data); } //awasthi cout << "Post-order traversal: "; postOrderTraversal(root); cout << endl; //awasthi cout << "Height of the tree: " << maxHeight(root) << endl; return 0; }

Rithish is studying data structures and algorithms, and he's currently learning about binary search trees (BSTs). He wants to practice his skills by performing operations on a BST. Help him by designing a program that allows him to insert elements into a BST and perform two operations: post-order traversal and calculating the height of the tree. Note: The height of the tree is computed by finding the maximum height between the left and right subtrees of the root node and then adding 1 to that maximum height. Input format : The first line of input is an integer n, representing the number of elements to be inserted into the BST. The second line of input is an integer, where the i-th integer represents the value to be inserted into the BST. Output format : The output displays the following format: First, it should print "Post-order traversal: " followed by the post-order traversal of the BST. Then, it should print "Height of the tree: " followed by the height of the BST.

#include <stdio.h> #define MAX_NODES 50 struct Node { int data; int leftIndex; int rightIndex; }; //awasthi struct Node tree[MAX_NODES]; int currentIndex = 0; int createNode(int data) { tree[currentIndex].data = data; tree[currentIndex].leftIndex = -1; tree[currentIndex].rightIndex = -1; return currentIndex++; } int insertNode(int rootIndex, int data) { if (rootIndex == -1) { return createNode(data); } if (data < tree[rootIndex].data) { tree[rootIndex].leftIndex = insertNode(tree[rootIndex].leftIndex, data); } else { tree[rootIndex].rightIndex = insertNode(tree[rootIndex].rightIndex, data); } return rootIndex; } int calculateTotalValue(int rootIndex) { if (rootIndex == -1) { return 0; } int leftValue = calculateTotalValue(tree[rootIndex].leftIndex); int rightValue = calculateTotalValue(tree[rootIndex].rightIndex); return tree[rootIndex].data + leftValue + rightValue; } int main() { int n; scanf("%d", &n); int rootIndex = -1; for (int i = 0; i < n; i++) { int data; scanf("%d", &data); rootIndex = insertNode(rootIndex, data); } int totalValue = calculateTotalValue(rootIndex); printf("%d\n",totalValue); //awasthi return 0; }

You are working on a financial application that deals with investment portfolios represented as a binary tree. Each node in the binary tree represents a specific investment and holds a numerical value indicating the investment's worth. Your task is to implement an algorithm in your financial application, which will allow you to accurately calculate the total value of the investment portfolio represented by the binary tree, facilitating better decision-making and analysis for your clients. The algorithm performs a preorder traversal of the binary tree, where the value of the current node is added to the sum before visiting its children. By visiting each node in a prearranged manner, we ensure that every element in the tree is accounted for in the sum calculation. Input format : The first line of input consists of a single integer N, representing the number of nodes in the binary tree. The second line consists of N space-separated integers, representing the values of the nodes in the binary tree. Output format : The output prints the sum of all elements in the binary tree.