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
Articles by Pavitra
Page 4 of 13
Python Program for Stooge Sort
In this article, we will learn about the Stooge Sort algorithm and implement it in Python. Stooge Sort is a recursive sorting algorithm that divides the array into overlapping parts and sorts them multiple times to ensure correctness. Problem statement − We are given an array, we need to sort it using stooge sort. Algorithm The Stooge Sort algorithm follows these steps ? 1. Check if value at index 0 is greater than value at last index, then swap them. 2. Sort the initial 2/3rd of the array. 3. Sort the last 2/3rd of the ...
Read MorePython Program for Sieve of Eratosthenes
The Sieve of Eratosthenes is an ancient algorithm for finding all prime numbers up to a given limit. It works by iteratively marking the multiples of each prime as composite, leaving only the prime numbers unmarked. Problem statement − We are given a number n, we need to print all primes smaller than or equal to n. Constraint: n is a small number. Algorithm Overview The algorithm follows these steps: Create a boolean array of size n+1, initially all True Mark 0 and 1 as False (not prime) For each number p from 2 to √n, ...
Read MorePython Program for Recursive Insertion Sort
In this article, we will learn about implementing insertion sort using recursion. Recursive insertion sort breaks down the sorting problem into smaller subproblems by recursively sorting the first n-1 elements and then inserting the last element in its correct position. Problem statement − We are given an array, we need to sort it using the concept of recursive insertion sort. Insertion sort works by building a sorted portion of the array one element at a time. In the recursive approach, we sort the first n-1 elements recursively, then insert the nth element into its correct position. Algorithm ...
Read MorePython Program for QuickSort
QuickSort is a divide-and-conquer sorting algorithm that works by selecting a pivot element and partitioning the array around it. Elements smaller than the pivot go to the left, and larger elements go to the right. How QuickSort Works The algorithm follows these steps ? Step 1: Choose Pivot 5 2 8 3 7 (Pivot: 7) ...
Read MorePython Program for array rotation
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 MoreTwitter Sentiment Analysis using Python Program
Twitter sentiment analysis allows us to analyze public opinions and emotions from tweets using Python. We'll use the Twitter API to fetch tweets and TextBlob library to analyze their sentiment polarity. Twitter API Python Script TextBlob ...
Read MorePython program to print odd numbers in a list
In this article, we will learn different approaches to find and print odd numbers from a list. An odd number is any integer that is not divisible by 2, meaning when divided by 2, it leaves a remainder of 1. Problem Statement Given a list of integers as input, we need to display all odd numbers present in the list. We will explore three different approaches to solve this problem efficiently. Using For Loop The most straightforward approach is to iterate through each number and check if it's odd using the modulo operator ? ...
Read MorePython Program to Print Numbers in an Interval
In this article, we will learn how to print all numbers within a given interval using Python. We'll explore different approaches including printing all numbers, only even numbers, only odd numbers, and prime numbers in a range. Problem Statement Given a starting and ending range of an interval, we need to print all the numbers (or specific types of numbers) within that interval. Method 1: Print All Numbers in an Interval The simplest approach is to use a for loop with range() function to iterate through all numbers ? start = 5 end = ...
Read MorePython program to find the most occurring character and its count
In this article, we will learn how to find the most occurring character in a string and count its occurrences using Python's Counter class. Problem Statement Given an input string, we need to find the character that appears most frequently and return both the character and its count. Approach Create a dictionary using Counter method having characters as keys and their frequencies as values. Find the maximum occurrence count and get the corresponding character. Using Counter from collections The Counter class provides an easy way to count character frequencies ? ...
Read MorePython program to find the highest 3 values in a dictionary
In this article, we will learn how to find the highest 3 values in a dictionary using different Python approaches. Problem Statement Given a dictionary, we need to find the three highest values and display them along with their corresponding keys. Using collections.Counter The Counter class provides a most_common() method that returns the n most common elements and their counts ? from collections import Counter # Initial Dictionary my_dict = {'a': 3, 'b': 4, 'c': 6, 'd': 5, 'e': 21} counter = Counter(my_dict) # Finding 3 highest values highest = counter.most_common(3) ...
Read More