Articles on Trending Technologies

Technical articles with clear explanations and examples

Count Number of Lowercase Characters in a String in Python Program

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 2K+ Views

When you need to count the number of lowercase characters in a string, Python provides the islower() method which can be combined with a simple for loop to achieve this task. Using islower() Method with for Loop The islower() method returns True if the character is a lowercase letter, and False otherwise ? my_string = "Hi there how are you" print("The string is") print(my_string) my_counter = 0 for i in my_string: if(i.islower()): my_counter = my_counter + 1 print("The number of lowercase characters ...

Read More

Take in Two Strings and Display the Larger String without Using Built-in Functions in Python Program

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 905 Views

When it is required to take two strings and display the larger string without using any built-in function, a counter can be used to get the length of the strings, and if condition can be used to compare their lengths. Below is the demonstration of the same − Example string_1 = "Hi there" string_2 = "Hi how are ya" print("The first string is :") print(string_1) print("The second string is :") print(string_2) count_1 = 0 count_2 = 0 for i in string_1: count_1 = count_1 + 1 for j in ...

Read More

Python Program to Find All Connected Components using DFS in an Undirected Graph

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 2K+ Views

When working with undirected graphs, connected components are subsets of vertices where each vertex is reachable from every other vertex within the same component. We can find all connected components using Depth-First Search (DFS) traversal. Below is a demonstration of finding connected components using a graph class ? Graph Class Implementation First, let's create a graph class with methods for DFS traversal and finding connected components ? class Graph_struct: def __init__(self, V): self.V = V ...

Read More

Python Program to Calculate the Length of a String Without Using a Library Function

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 3K+ Views

When it is required to calculate the length of a string without using library methods, a counter is used to increment every time an element of the string is encountered. Below is the demonstration of the same ? Example my_string = "Hi Will" print("The string is :") print(my_string) my_counter = 0 for i in my_string: my_counter = my_counter + 1 print("The length of the string is") print(my_counter) Output The string is : Hi Will The length of the string is 7 Using While Loop ...

Read More

Python Program to Find the Sum of All Nodes in a Binary Tree

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 295 Views

When working with binary trees, finding the sum of all nodes is a common operation. We can implement this using a tree class that contains methods to build the tree and calculate the sum recursively. Each node stores data and maintains references to its children. Below is a demonstration of the same − Tree Class Implementation First, let's create a tree structure class with methods for adding nodes and calculating the sum ? class Tree_struct: def __init__(self, data=None): self.key = data ...

Read More

Python Program to solve Maximum Subarray Problem using Kadane's Algorithm

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 378 Views

The Maximum Subarray Problem finds the contiguous subarray within a one-dimensional array of numbers that has the largest sum. Kadane's Algorithm solves this problem efficiently in O(n) time complexity using dynamic programming principles. Understanding Kadane's Algorithm Kadane's algorithm maintains two variables: the maximum sum ending at the current position and the overall maximum sum seen so far. At each position, it decides whether to extend the existing subarray or start a new one. Basic Implementation Here's a simple version that returns only the maximum sum ? def kadane_simple(arr): max_ending_here = ...

Read More

Python Program to Find if Undirected Graph contains Cycle using BFS

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 521 Views

A cycle in an undirected graph occurs when you can start at a vertex and return to it by following edges without retracing the same edge. We can detect cycles using Breadth-First Search (BFS) by tracking parent nodes during traversal. How BFS Cycle Detection Works The algorithm uses a queue to traverse the graph level by level. For each visited vertex, we track its parent. If we encounter a visited vertex that is not the current vertex's parent, we've found a cycle. Implementation Helper Functions First, let's define a function to add edges to our ...

Read More

Python Program to Find All Connected Components using BFS in an Undirected Graph

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 778 Views

Connected components in an undirected graph are maximal sets of vertices where every vertex is reachable from every other vertex in the same component. This article demonstrates finding all connected components using BFS (Breadth-First Search) traversal. Understanding Connected Components A connected component is a subgraph where: Every vertex can reach every other vertex in the component No vertex in the component can reach vertices outside it The component cannot be extended by adding more vertices BFS Implementation for Connected Components Here's how to find all connected components using BFS traversal ? ...

Read More

Python Program to Display the Nodes of a Tree using BFS Traversal

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 975 Views

When it is required to display the nodes of a tree using the breadth first search traversal, a class is created, and it contains methods to set the root node, add elements to the tree, search for a specific element, perform BFS (breadth first search) and so on. An instance of the class can be created to access and use these methods. Below is a demonstration of the same ? Tree Structure Class First, let's create a simplified version that demonstrates the core BFS concept ? class Tree_struct: def __init__(self, data=None): ...

Read More

Python Program to Print only Nodes in Left SubTree

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 329 Views

When it is required to print the nodes in the left subtree, a binary tree class can be created with methods to perform operations like setting the root node, inserting elements, and traversing the tree. This program demonstrates how to build a binary tree and display only the nodes in the left subtree. A binary tree is a hierarchical data structure where each node has at most two children: a left child and a right child. The left subtree contains all nodes that are descendants of the left child of the root node. Binary Tree Implementation ...

Read More
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements