Pavitra

Pavitra

123 Articles Published

Articles by Pavitra

Page 12 of 13

Python Program for Gnome Sort

Pavitra
Pavitra
Updated on 11-Mar-2026 397 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an array, we need to sort it using gnome sort.Algorithm1. Firstly we traverse the array from left to right. 2. Now, if the current element is larger or equal to the previous element then we traverse one step ahead 3. otherwise, if the current element is smaller than the previous element then swap these two elements and traverse one step back. 4. Repeat steps given above till we reach the end of the arrayNow let’s observe the solution in the ...

Read More

Python Program for Heap Sort

Pavitra
Pavitra
Updated on 11-Mar-2026 2K+ Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an array, we need to sort it using the concept of heapsort.Here we place the maximum element at the end. This is repeated until the array is sorted.Now let’s observe the solution in the implementation below−Example# heapify def heapify(arr, n, i):    largest = i # largest value    l = 2 * i + 1 # left    r = 2 * i + 2 # right    # if left child exists    if l < n and arr[i] ...

Read More

Python Program for Maximum height when coins are arranged in a triangle

Pavitra
Pavitra
Updated on 11-Mar-2026 271 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given N coins where we need to arrange them in form of a triangle, i.e. in the first row will have 1 coin, the second row will have 2 coins and so on, we need to display the maximum height that can be achieved by the help N coins.Now let’s observe the solution in the implementation below −Example# squareroot def squareRoot(n):    # initial approximation    x = n    y = 1    e = 0.000001 # allowed error   ...

Read More

Python Program for Min Cost Path

Pavitra
Pavitra
Updated on 11-Mar-2026 851 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a cost matrix and a position (m, n), we need to find the cost of minimum cost path to reach (m, n) from (0, 0). Each cell represents a cost to traverse from one cell to another.Now let’s observe the solution in the implementation below −Example# dynamic approach R = 3 C = 3 def minCost(cost, m, n):    # initialization    tc = [[0 for x in range(C)] for x in range(R)]    # base case    tc[0][0] = ...

Read More

Python Program for Number of stopping station problem

Pavitra
Pavitra
Updated on 11-Mar-2026 369 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given that there are 13 intermediate stations between two places A and B. We need to find the number of ways in which a train can be stopped at 2 intermediate stations, such that there are no consecutive stations?Now let’s observe the solution in the implementation below −Example# stop station def stopping_station( p, n):    num = 1    dem = 1    s = p    # selecting specified position    while p != 1:       dem *= ...

Read More

Python Program for Tower of Hanoi

Pavitra
Pavitra
Updated on 11-Mar-2026 3K+ Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given n disks and a series of rods, we need to transfer all the disks to the final rod under the given constraints−We can move only one disk at a time.Only the uppermost disk from the rod can be moved.Any bigger disk cannot be placed on the smaller diskNow let’s observe the solution in the implementation below −Example# tower of hanoi def TowerOfHanoi(n , from_rod, to_rod, aux_rod):    if n == 1:       print ("Move disk 1 from rod", from_rod, ...

Read More

Mathematical Functions in Python - Special Functions and Constants

Pavitra
Pavitra
Updated on 03-Jul-2020 404 Views

In this article, we will learn about special functions and constants available in the math module in the Python Standard Library.Here we will discuss some constants like −pieinfNantauAnd some functions likeGammaIsinfIsnanisfinite()erf()Let's discuss constants and their respective values −pi3.141592…..e2.718281…...inf6.283185…...nantauNow let’s discuss some special functions and their implementation −Gamma − return the value of gamma(n)Isinf − checks whether the value of the function is infinity or not.Isnan − check whether the return value is a number or not.Isfinite − return True if the value is neither an infinity or a nan false otherwiseErf − returns the error function of x.Now let;’s take ...

Read More

List Methods in Python - in, not in, len(), min(), max()

Pavitra
Pavitra
Updated on 01-Jul-2020 27K+ Views

In this article, we will learn about various types of list methods available to us in Python 3.x. Or earlier. These operators allow us to perform the basic operations on the list content.In & Not in operators“in” operator  − This operator is used to check whether an element is present in the passed list or not. Returns true if the element is present in the list otherwise returns false.“not in” operator  − This operator is used to check whether an element is not present in the passed list or not. Returns true if the element is not present in the ...

Read More

Iterate over a dictionary in Python

Pavitra
Pavitra
Updated on 01-Jul-2020 395 Views

In this article, we will learn about iteration/traversal of a dictionary in Python 3.x. Or earlier.A dictionary is an unordered sequence of key-value pairs. Indices can be of any immutable type and are called keys. This is also specified within curly braces.Method 1 − Using iterables directlyExampledict_inp = {'t':'u', 't':'o', 'r':'i', 'a':'l', 's':'p', 'o':'i', 'n':'t'} # Iterate over the string for value in dict_inp:    print(value, end='')OutputtrasonMethod 2 − Using iterables for values of the dictionaryExampledict_inp = {'t':'u', 't':'o', 'r':'i', 'a':'l', 's':'p', 'o':'i', 'n':'t'} # Iterate over the string for value in dict_inp.values():    print(value, end='')OutputoilpitMethod 3 − ...

Read More

Contingency Table in Python

Pavitra
Pavitra
Updated on 30-Dec-2019 2K+ Views

A contingency table is a table showing the distribution of one variable in rows and another variable in columns. It is used to study the correlation between the two variables. It is a multiway table which describes a dataset in which each observation belongs to one category for each of several variables. Also It is basically a tally of counts between two or more categorical variables. Contingency tables are also called crosstabs or two-way tables, used in statistics to summarize the relationship between several categorical variables.The contingency coefficient is a coefficient of association which tells whether two variables or datasets ...

Read More
Showing 111–120 of 123 articles
« Prev 1 9 10 11 12 13 Next »
Advertisements