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
Data Structure Articles
Found 1,635 articles
Python Program for Convert characters of a string to opposite case
In this problem, we will toggle the case of each string character. The easiest way to toggle the case of each string character is using the swapcase() built-in method. Also, we can use the ASCII values of the characters to swap their case. Python also contains isupper() and islower() methods to check the character's case and the lower() and upper() methods to change the case. Problem statement − We have given a string. We need to toggle the case of string characters. It means converting uppercase characters to lowercase and lowercase characters to uppercase. Sample Examples ...
Read MorePython3 Program to Find Maximum number of 0s placed consecutively at the start and end in any rotation of a Binary String
In this problem, we need to find the maximum sum of consecutive zeros at the start and end of any rotation of a binary string. We can solve this using two approaches: generating all rotations or using an optimized observation-based method. Problem Statement − Find the total number of maximum consecutive zeros at the start and end of any rotation of the given binary string. Examples Example 1 binary_str = "00100100" print(f"Input: {binary_str}") Input: 00100100 Output: 4 Explanation − Let's examine all rotations: 00100100 − Starting zeros: 2, ...
Read MoreReplace two Substrings (of a String) with Each Other
Replacing two substrings with each other requires careful handling of overlapping matches. Python provides several approaches to solve this problem efficiently using string methods and regular expressions. Problem Understanding Given a string S and two substrings A and B, we need to replace every occurrence of A with B and every occurrence of B with A. When both substrings are found at the same position, we prioritize the leftmost match. Example S = "aab" A = "aa" B = "bb" # Expected output: "bbb" print(f"Input: S='{S}', A='{A}', B='{B}'") Input: S='aab', A='aa', ...
Read MoreMinimum number of given Operations Required to Convert a String to Another String
You are given two strings A and B, the task is to convert string A to string B using only one operation: taking any character from A and inserting it at the front. We need to find the minimum number of such operations required for transformation. Problem Understanding The key insight is that we can only move characters from their current position to the front of the string. This means we need to work backwards and check which characters are already in the correct relative order. Example 1 For strings A = "ABD" and B = ...
Read MoreFind the Order of Execution of given N Processes in Round Robin Scheduling
In this article, you will learn how to find the order of execution for given N processes using the Round Robin Scheduling algorithm. Round Robin is a preemptive CPU scheduling algorithm that allocates CPU time fairly among processes using fixed time slices. What is Round Robin Scheduling? Round Robin Scheduling is a preemptive scheduling algorithm where each process receives a fixed time slice (quantum) to execute. The CPU scheduler allocates time to processes in a circular order. Once a process uses its time slice, it's preempted and moved to the end of the ready queue. The time ...
Read MoreSort the string as per the ASCII values of the characters
ASCII (American Standard Code for Information Interchange) assigns unique numeric values to characters. In Python, we can sort strings based on these ASCII values to arrange characters in ascending order. Problem Statement Given a string, we need to sort its characters according to their ASCII values in increasing order. Let's understand this with examples ? Example 1 Input: "$%7wjk()" Output: "$%()7jkw" The ASCII values are ? $ → 36 % → 37 ( → 40 ) → 41 7 → 55 j → 106 k → 107 w → 119 Example ...
Read MorePython Program To Write Your Own atoi()
We are given a string that may represent a number and need to convert it into an integer using Python. The atoi() function is used in C programming to convert a string parameter into an integer value if the string is a valid integer, otherwise it shows undefined behavior. Sample Examples Input 1 string S = "9834" Output 9834 Explanation: The string represents a valid number, so we get the same output as an integer. Input 2 string S = "09 uy56" Output ...
Read MoreOn Disk Data Structures
On-disk data structures are specialized data organization methods designed for persistent storage on physical media like hard drives and SSDs. Unlike in-memory structures, they are optimized for the unique characteristics of disk storage — slower access times, block-based I/O, and persistence across system restarts. These structures form the foundation of file systems, databases, and other storage-intensive applications. What are On-Disk Data Structures? On-disk data structures define how data is physically organized and accessed on storage devices. They differ from memory-based structures in several key ways: Block-oriented access — Data is read/written in blocks rather than individual ...
Read MoreHash Functions and Hash Tables
Hashing is the process of generating a value from a text or a list of numbers using a mathematical function known as a hash function. Hash functions convert input data of arbitrary size into fixed-size hash values, which are used as indices in hash tables for efficient data storage and retrieval. Hash Functions Hash functions are algorithms that map data to fixed-size hash values. Here are the most commonly used hash functions − Division Method This is the simplest method to create a hash function. The hash function can be described as − h(k) ...
Read MoreBakery Algorithm in Process Synchronization
It is a prerequisite to understand the terms "process synchronization", "critical section", and "inter-process communication" before we proceed to discuss the Bakery Algorithm in Process Synchronization. What is Process Synchronization? In a multiprocessing system, process synchronization is a method of coordinating execution of multiple processes so it is ensured that all processes access shared resources in a controlled and predictable manner. The primary goal of process synchronization is to avoid the problem of race conditions in the system. It also resolves many other issues related to synchronization in a concurrent system. Therefore, process synchronization ensures that multiple ...
Read More