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
Programming Articles
Page 99 of 2547
Insertion Sort in Python Program
In this article, we will learn about the implementation of Insertion Sort in Python. Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a time, similar to how you might sort playing cards in your hands. Algorithm Iterate over the input elements by growing the sorted array at each iteration. Compare the current element with the largest value available in the sorted array. If the current element is greater, then it leaves the element in its place and moves on to the next element else it finds its correct position ...
Read MoreFinding the vertex, focus and directrix of a parabola in Python Program
In this article, we will learn about finding the vertex, focus and directrix of a parabola using Python. A parabola is a U-shaped curve that can be represented by the standard form equation y = ax² + bx + c. Understanding Parabola Components ...
Read MorePython Program for Find sum of Series with the n-th term as n^2 – (n-1)^2
In this article, we will learn how to find the sum of a series where the n-th term is defined as n² - (n-1)². We'll explore the mathematical pattern and implement an efficient solution. Problem Statement We are given an integer input n and we need to find the sum of all n terms where the n-th term in the series is expressed as − Tn = n² - (n-1)² Understanding the Pattern Let's first understand what this series looks like by calculating the first few terms − # Calculate first ...
Read MorePython Program for Find sum of odd factors of a number
In this article, we will learn how to find the sum of odd factors of a number. We need to identify all factors that are odd and calculate their sum. Problem Statement Given a number n, find the sum of all its odd factors. For example, if n = 12, the factors are [1, 2, 3, 4, 6, 12], and the odd factors are [1, 3], so the sum is 4. Approach To find odd factors efficiently, we first eliminate all even factors by dividing the number by 2 repeatedly. Then we find all remaining odd ...
Read MorePython Program for Find reminder of array multiplication divided by n
In this article, we will learn about finding the remainder when the product of all array elements is divided by a given number n. This approach uses modular arithmetic properties to avoid overflow issues. Problem Statement Given an array of numbers and a divisor n, we need to find the remainder after multiplying all array elements and dividing by n. Approach We use the distributive property of modular arithmetic to compute the result efficiently − First, compute the remainder of each element like arr[i] % n. Then multiply this remainder ...
Read MorePython Program for Find minimum sum of factors of number
In this article, we will learn how to find the minimum sum of factors of a given number. The key insight is that the minimum sum is achieved by using the sum of prime factors of the number. Problem Statement Given a number, find the minimum sum of factors that can multiply to give the original number. For example, the number 12 can be expressed as: 12 = 12 (sum = 12) 12 = 6 × 2 (sum = 8) 12 = 4 × 3 (sum = 7) 12 = 3 × 2 × 2 (sum ...
Read MorePython Program for Fibonacci numbers
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. In this article, we will learn different approaches to compute the nth Fibonacci number in Python. Problem statement − Our task is to compute the nth Fibonacci number. The sequence Fn of Fibonacci numbers is given by the recurrence relation: Fn = Fn-1 + Fn-2 with seed values: F0 = 0 and F1 = 1 We have two main approaches to solve this problem: Recursive approach Dynamic programming approach Using Recursive ...
Read MorePython Program for Difference between sums of odd and even digits
In this article, we will learn how to find the difference between the sum of odd digits and sum of even digits in a number, and check if this difference equals zero. Problem Statement − Given an integer, we need to calculate if the difference between the sum of odd digits and sum of even digits is 0 or not. Method 1: Brute Force Approach The straightforward approach calculates the sum of all even and odd digits separately, then finds their difference ? def difference_odd_even_digits(n): n = abs(n) # Handle ...
Read MorePython Program for cube sum of first n natural numbers
In this article, we will learn how to calculate the cube sum of first n natural numbers using two different approaches. The cube sum series is: 1³ + 2³ + 3³ + 4³ + ... + n³. Problem statement − Given an input n, we need to print the sum of series 1³ + 2³ + 3³ + 4³ + ... + n³ till n-th term. Here we will discuss two approaches to solve this problem ? Brute-force approach using loops Mathematical solution using the sum formula Using Loop (Iterative Approach) This approach ...
Read MorePython Program for compound interest
In this article, we will learn how to calculate compound interest using Python. Compound interest is the interest calculated on both the initial principal and the accumulated interest from previous periods. Problem statement − We are given three input values: principal amount, interest rate, and time period. We need to compute the compound interest. Formula The formula for calculating compound interest is: Compound Interest = P × (1 + R/100)^T Where: P is the principal amount (initial investment) R is the annual interest rate (in percentage) T is the time period (in ...
Read More