Python Program for Number of Stopping Station Problem

Pavitra
Updated on 20-Dec-2019 06:39:26

327 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 Live Demo# 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 Minimum Cost Path

Pavitra
Updated on 20-Dec-2019 06:36:28

803 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 Live Demo# 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 Merge Sort

Pavitra
Updated on 20-Dec-2019 06:33:27

757 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 merge sortHere 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#merge function def merge(arr, l, m, r):    n1 = m - l + 1    n2 = r- m    # create arrays    L = [0] * (n1)    R = [0] * (n2)    # Copy data to arrays   ... Read More

Maximum Height of Coins Arranged in a Triangle

Pavitra
Updated on 20-Dec-2019 06:30:11

226 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 Live Demo# squareroot def squareRoot(n):    # initial approximation    x = n    y = 1    e = 0.000001 # allowed error ... Read More

Iterative Quick Sort in Python

Pavitra
Updated on 20-Dec-2019 06:27:27

607 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 quick sort using iterative wayHere we first partition the array and sort the separate partition to get the sorted array.Now let’s observe the solution in the implementation below−Example Live Demo# iterative way def partition(arr, l, h):    i = ( l - 1 )    x = arr[h]    for j in range(l , h):       if arr[j] = 0:       # Pop       h ... Read More

How MySQL Works with PHP Programming Language

Giri Raju
Updated on 20-Dec-2019 06:25:34

723 Views

MySQL works very well in combination with various programming languages like PERL, C, C++, JAVA, and PHP. Out of these languages, PHP is the most popular one because of its web application development capabilities.PHP provides various functions to access the MySQL database and to manipulate the data records inside the MySQL database. You would require calling the PHP functions in the same way you call any other PHP function.The PHP functions for use with MySQL have the following general format –mysql_function(value, value, ...);The second part of the function name is specific to the function, usually a word that describes what ... Read More

Python Program for Iterative Merge Sort

Pavitra
Updated on 20-Dec-2019 06:23:49

654 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 merge sort by iteration.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# iterative way def mergeSort(a):    current_size = 1    # traversing subarrays    while current_size < len(a) - 1:       left = 0       # subarray being sorted       while left < len(a)-1:     ... Read More

Get POST Values from serializeArray in PHP

Ricky Barnes
Updated on 20-Dec-2019 06:20:34

3K+ Views

To get the POST values from serializeArray in PHP, use the serializeArray() method. The serializeArray( ) method serializes all forms and form elements like the .serialize() method but returns a JSON data structure for you to work with.Let’s say we have the PHP content in serialize.php file:ExampleThe following is an example showing the usage of this method:Live Demo           The jQuery Example                              $(document).ready(function() {                         $("#driver").click(function(event){     ... Read More

Python Program for Heap Sort

Pavitra
Updated on 20-Dec-2019 06:17:43

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 Live Demo# 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 ... Read More

Python Program for Gnome Sort

Pavitra
Updated on 20-Dec-2019 06:13:54

346 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

Advertisements