Server Side Programming Articles

Page 586 of 2109

Python Program for Binary Insertion Sort

Sarika Singh
Sarika Singh
Updated on 25-Mar-2026 1K+ Views

Binary insertion sort is an improved version of the regular insertion sort algorithm. In normal insertion sort, each element is compared linearly with the sorted portion to find its correct position, taking O(n) comparisons per element. Binary insertion sort uses binary search to find the correct insertion position, reducing comparisons from O(n) to O(log n) per element. However, shifting elements still requires O(n) time in the worst case. How Binary Insertion Sort Works The algorithm combines binary search with insertion sort ? Start from the second element (index 1) ...

Read More

Python Program for array rotation

Pavitra
Pavitra
Updated on 25-Mar-2026 328 Views

In this article, we will learn how to rotate an array by a given number of positions. Array rotation is a fundamental operation where elements are shifted left or right, with elements that fall off one end being placed at the other end. Problem statement − Given an array and a number of positions, we need to rotate the array elements by the specified number of positions. Original Array: 1 2 3 ...

Read More

Python Program for Activity Selection Problem

Sarika Singh
Sarika Singh
Updated on 25-Mar-2026 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 finish time. The goal is to choose the maximum number of activities that a single person can perform without any overlap between the selected activities. Variable Notations Below are the variables used in the problem definition − N: Total number ...

Read More

Python Program for 0-1 Knapsack Problem

Sarika Singh
Sarika Singh
Updated on 25-Mar-2026 6K+ Views

The 0-1 Knapsack Problem is a classic optimization problem where you have a knapsack with limited capacity and items with specific weights and values. The goal is to select items that maximize value without exceeding the weight limit, where each item can only be taken once (0 or 1). Problem Types There are three main variants of the knapsack problem − 0-1 Knapsack: Each item can either be selected or not (0 or 1) Fractional Knapsack: Items can be broken into fractions Unbounded Knapsack: ...

Read More

To print all elements in sorted order from row and column wise sorted matrix in Python

Niharikaa Aitam
Niharikaa Aitam
Updated on 25-Mar-2026 394 Views

In Python, we may work with matrices that are sorted in a particular order. A common case is a matrix where each row and each column is sorted in increasing order, but the entire matrix is not necessarily sorted. In such cases, we need to extract all elements and print them in a fully sorted order. Understanding Row and Column-wise Sorted Matrix A row and column-wise sorted matrix means each row is sorted from left to right, and each column is sorted from top to bottom. For example, consider the following matrix − matrix ...

Read More

Python - Check if all elements in a List are same

Niharikaa Aitam
Niharikaa Aitam
Updated on 25-Mar-2026 29K+ Views

In Python, a list is a collection of ordered and mutable elements enclosed in square brackets []. Each element in a list has a unique position index, starting from 0. It can accept duplicate elements. In some cases, we may need to check if all the elements in a list are identical or not to detect a special condition in algorithms. Let's go through the different methods to check if all elements in a list are the same or not. Using set() Function The Python set() function (built-in) creates an unordered collection of unique elements. To check ...

Read More

Generate two output strings depending upon occurrence of character in input string in Python

Niharikaa Aitam
Niharikaa Aitam
Updated on 25-Mar-2026 207 Views

In Python, a string is a sequence of characters enclosed within single quotes '' or double quotes "". When processing strings, we often need to analyze character occurrence patterns to generate different outputs based on frequency. To generate two output strings based on character occurrence in Python, we follow these steps: Count the frequency of each character in the input string using a dictionary or collections.Counter Separate characters into two categories: ...

Read More

Find the version of the Pandas and its dependencies in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 293 Views

Pandas is a crucial package for data analysis in Python. Different versions may have compatibility issues, so it's important to check your Pandas version and its dependencies. Python provides several methods to retrieve this information. Finding Pandas Version The simplest way to check the Pandas version is using the __version__ attribute ? import pandas as pd print(pd.__version__) 2.1.4 Alternative Methods to Check Version Using pkg_resources import pkg_resources version = pkg_resources.get_distribution("pandas").version print(version) 2.1.4 Using importlib.metadata from importlib.metadata import version print(version('pandas')) ...

Read More

Anagram Substring Search using Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 469 Views

An anagram is a rearrangement of the characters of a word or a phrase to generate a new word, using all the original characters exactly once. For example, thing and night are anagrams of each other. An anagram substring search involves finding all substrings in a text that are anagrams of a given pattern. This means we need to find substrings that contain the same characters as the pattern, regardless of their order. Problem Statement Given two strings text and pattern, find all starting indices of substrings in the text that are anagrams of the pattern. ...

Read More

Adding a new column to existing DataFrame in Pandas in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 35K+ Views

In this tutorial, we are going to learn how to add a new column to an existing DataFrame in pandas. There are several methods to accomplish this task, each with its own advantages depending on your specific needs. Using Direct Assignment The simplest way to add a new column is by using direct assignment with a list. This method assigns the new column data to the DataFrame like a dictionary element − Example # importing pandas import pandas as pd # creating a DataFrame data = { 'Name': ['Hafeez', 'Aslan', ...

Read More
Showing 5851–5860 of 21,090 articles
« Prev 1 584 585 586 587 588 2109 Next »
Advertisements