Sarika Singh has Published 189 Articles

Python Program for Binary Insertion Sort

Sarika Singh

Sarika Singh

Updated on 13-Jun-2025 18:17:34

1K+ Views

Binary Insertion SortBinary insertion sort is an improved version of the regular Insertion Sort algorithm. In a normal insertion sort, each element is compared linearly with the sorted portion of the list to find its correct position. This takes O(n) comparisons for each element. In Binary Insertion Sort, we use ... Read More

Python Program for Basic Euclidean algorithms

Sarika Singh

Sarika Singh

Updated on 13-Jun-2025 18:14:27

592 Views

Euclidean AlgorithmThe Euclidean Algorithm is used to find the Greatest Common Divisor (GCD) of two numbers. The GCD of two integers is the largest number that divides both of them without leaving a remainder. This algorithm is based on the principle that the GCD of two numbers also divides their ... Read More

Python Program for Activity Selection Problem

Sarika Singh

Sarika Singh

Updated on 13-Jun-2025 18:11:19

1K+ Views

The activity selection problem selects the maximum number of non-overlapping activities from a given set. Each activity has a start and finish time, and a single person can perform only one activity at a time. Problem Statement You are given n activities, each defined by a start time and a ... Read More

How to remove all leading whitespace in string in Python?

Sarika Singh

Sarika Singh

Updated on 11-Jun-2025 17:16:16

17K+ Views

Leading whitespace refers to any spaces, tabs, or other blank characters that appear at the start of a string. These characters come before the first visible text and can affect how the string is displayed. We can remove all leading whitespace from a string in Python using the lstrip() function. ... Read More

How to convert all uppercase letters in string to lowercase in Python?

Sarika Singh

Sarika Singh

Updated on 11-Jun-2025 17:08:38

4K+ Views

We can convert all uppercase letters in a string to lowercase in Python using the lower() function. You can also use a for loop or list comprehension to change each character to lowercase one by one. This is helpful when you want to compare strings without worrying about letter cases. ... Read More

How to replace all occurrences of a string with another string in Python?

Sarika Singh

Sarika Singh

Updated on 11-Jun-2025 16:49:42

2K+ Views

In Python, you can replace all occurrences of a substring within a string using the replace() method. This method returns a new string where every occurrence of the given old substring is replaced with a new substring. To match the string with case-insensitivity, you need to use regular expressions. ... Read More

How to check if text is “empty” (spaces, tabs, newlines) in Python?

Sarika Singh

Sarika Singh

Updated on 11-Jun-2025 15:38:27

4K+ Views

In this article, we are going to focus on how to check if the text is empty (spaces, tabs, newlines) in Python. Checking if text is Empty using isspace() method The isspace() method determines whether a string contains only spaces or contains any other characters. If the given string is only ... Read More

Python Program for 0-1 Knapsack Problem

Sarika Singh

Sarika Singh

Updated on 10-Jun-2025 11:59:57

5K+ Views

Knapsack is a classic problem that involves decision-making based on constraints. Suppose we have a knapsack with fixed capacity, and items with fixed values and sizes (it might be volume of the item or weight). We need to add items into the knapsack such that we pack the maximum value ... Read More

What are different data conversion methods in Python?

Sarika Singh

Sarika Singh

Updated on 09-Jun-2025 10:17:08

865 Views

Data conversion in Python refers to changing the data type of a value to another data type. Python supports two different types of data conversion, such as Implicit conversion and explicit conversion. Implicit Conversion is performed by the Python interpreter automatically. ... Read More

How to check if a string is alphanumeric in Python?

Sarika Singh

Sarika Singh

Updated on 09-Jun-2025 09:19:01

7K+ Views

In Python, strings can contain letters, numbers, or special characters. To check if a string is alphanumeric (contains only letters and numbers), we can use different methods. This article shows three simple ways to do that: Using the isalnum() function Using regular expressions Using the isalpha() and isdigit() functions ... Read More

Advertisements