Sarika Singh has Published 174 Articles

Sarika Singh
990 Views
A cycle occurs when a path starts and ends at the same vertex, following the direction of the edges. In directed graphs, cycles can cause problems like infinite loops or dependency errors, so detecting them is important in areas like task scheduling and deadlock detection. We can use Depth-First Search ...

Sarika Singh
839 Views
Rod Cutting ProblemThe Rod Cutting problem is a classic example of dynamic programming. The goal is to cut a rod into pieces to maximize the total value. Each piece has a specific length and value, and we must choose the cuts in such a way that the total value is ...

Sarika Singh
358 Views
What is Cocktail Sort? Cocktail sort is a variation of bubble sort that sorts the array in both directions on each pass. It is also known as Bidirectional Bubble Sort or Shaker Sort. The algorithm works by traversing the list forward and backward, alternatively, pushing the largest and smallest elements ...

Sarika Singh
244 Views
BogoSort, also known as Permutation Sort or Stupid Sort, is a sorting algorithm based on generating random permutations of the list until it gets sorted. BogoSort continues to shuffle the array randomly until the list becomes sorted. The expected time complexity is unbounded, and its average performance is extremely poor. ...

Sarika Singh
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 ...

Sarika Singh
536 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 ...

Sarika Singh
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 ...

Sarika Singh
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. ...

Sarika Singh
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. ...

Sarika Singh
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. ...