Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 535 of 2109
Construct a DataFrame in Pandas using string data in Python
Pandas DataFrames can be constructed from various data sources including CSV files. You can also create DataFrames directly from string data by using StringIO to simulate file-like input. The StringIO wrapper from the io module allows us to treat string data as if it were being read from a file, making it compatible with pandas' CSV reading functions. Example Let us see how to construct a DataFrame using semicolon-separated string data − import pandas as pd from io import StringIO str_data = StringIO("""Id;Subject;Course_Fee 10;DBMS;3000 11;Basic Maths;2000 ...
Read MoreConstruct a Binary Tree from Postorder and Inorder in Python
Building a binary tree from inorder and postorder traversals is a classic tree reconstruction problem. Given these two traversal sequences, we can uniquely reconstruct the original binary tree by leveraging the properties of each traversal type. 3 9 20 15 7 ...
Read MoreConstruct a Binary Search Tree from given postorder in Python
A Binary Search Tree (BST) can be constructed from its postorder traversal sequence. Since a BST's inorder traversal is always sorted, we can derive the inorder sequence and use both traversals to rebuild the tree. .node-circle { fill: #e8f4fd; stroke: #2196F3; stroke-width: 2; } .node-text { font-family: Arial, sans-serif; font-size: 14px; text-anchor: middle; } .edge-line { stroke: #666; stroke-width: 2; } 3 ...
Read MoreHeap in C++ STL - make_heap(), push_heap(), pop_heap(), sort_heap(), is_heap, is_heap_until()
A heap is a complete binary tree data structure where parent nodes are either greater than (max heap) or less than (min heap) their children. C++ STL provides several heap operations through the header that work with containers like vectors. Basic Heap Operations make_heap() and front() The make_heap() function converts a range in a container to a heap structure. Use front() to access the largest element in a max heap ? #include using namespace std; int main() { vector heap = {33, 43, 53, 38, 28}; make_heap(heap.begin(), heap.end()); cout
Read MoreCheck if a number is an Achilles number or not in Python
An Achilles number is a number that is powerful but not a perfect power. A powerful number means that for every prime factor p, p² also divides the number. A perfect power is a number that can be expressed as a^b where a and b are positive integers and b > 1. Some examples of Achilles numbers are: 72, 108, 200, 288, 392, 432, 500, 648, 675, 800, 864, 968, 972, 1125. Understanding Achilles Numbers For example, 108 is an Achilles number because: 108 = 2² × 3³ (powerful: both 2² and 3² divide 108) ...
Read MoreCheck if a number is a Trojan Numbers in Python
A Trojan Number is a special type of number that meets two criteria: it must be a strong number but not a perfect power. A strong number is one where every prime factor appears at least twice (squared or higher). For example, 72 = 2³ × 3² is strong because both prime factors (2 and 3) appear at least twice, and it's not a perfect power like 8 = 2³. Understanding Strong Numbers A number is strong when every prime factor appears with an exponent of 2 or more ? from math import sqrt def ...
Read MoreCheck if a king can move a valid move or not when N nights are there in a modified chessboard in Python
Suppose we have an infinite chessboard with the same rules as chess. Given N knights and a king's position, we need to check whether the king is in checkmate or not. The coordinate system is bounded by large values like (-10^9
Read MoreCheck if a key is present in every segment of size k in an array in Python
Suppose we have an array A with N elements, we have another value p and a segment size k, we have to check whether key p is present in every segment of size k in A. So, if the input is like A = [4, 6, 3, 5, 10, 4, 2, 8, 4, 12, 13, 4], p = 4 and k = 3, then the output will be True because: Segment 1: [4, 6, 3] contains 4 ✓ Segment 2: [5, 10, 4] contains 4 ✓ Segment 3: [2, 8, 4] contains 4 ✓ Remaining elements: [12, ...
Read MoreCheck if a given Binary Tree is Heap in Python
A binary heap is a special binary tree with two key properties: it must be a complete tree (all levels filled except possibly the last, which fills left to right), and it must satisfy the heap property (each parent node is greater than or equal to its children for a max-heap). In this article, we'll implement a solution to check if a given binary tree satisfies both heap properties. Understanding Heap Properties A binary tree is a valid max-heap if: Complete Tree Property: All levels are completely filled except possibly the ...
Read MoreCheck if a given Binary Tree is height balanced like a Red-Black Tree in Python
A Red-Black Tree is a balanced binary search tree where the height difference is controlled. In such trees, the longest path from any node to a leaf is at most twice the length of the shortest path. This property ensures the tree remains balanced and provides efficient operations. We need to check if a given binary tree satisfies this height-balanced property where for every node, the longest leaf-to-node path is not more than double the shortest path from node to leaf. Problem Understanding Given a binary tree like this: ...
Read More