## Maximum number of similar groups of a given size that can be made from a given array

I am given an array of numbers, not necessarily unique, and the size of a group. Let the array be denoted by $$B$$ and the size of the group be $$A$$.

I need to find the maximum number of groups with the exact same contents and of size $$A$$ that can be made from the elements of $$B$$. Once an element is used in a group it is exhausted. A group can have more than one element with the same value as long as the element is still available in $$B$$.

Example:

1. If the input array is $$\{1, 2, 3, 1, 2, 3, 4\}$$, and the group size is $$3$$ the maximum number of groups that can be made is $$2$$, which are $$\{1, 2, 3\}$$ and $$\{1, 2, 3\}$$.
2. If the input array is $$\{1, 3, 3, 3, 6, 3, 10\}$$, and the group size is $$4$$ the maximum number of groups that can be made is $$1$$, which is $$\{1, 3, 3, 3\}$$.

What I have tried so far, is to frame some equations ( given below ) but after that, I am struggling to come up with an algorithm to solve them.

Let $$F_1$$ be the frequency of the element $$B_1$$, $$F_2$$ be the frequency of the element $$B_2$$ and so on till $$B_n$$, where $$B_1 \dots B_n$$ are distinct elements from the array $$B$$.

Now I need to choose $$n_1, n_2, \dots n_i$$ such that

1. $$n_1 + n_2 + \dots + n_i = A$$
2. $$k\cdot n_1 \leq F_1\text{ , } k\cdot n_2 \leq F_2\text{ , }\dots \text{ , }k\cdot n_i \leq F_i$$
3. $$k$$ is the number of groups and we need to maximize it.

Length of $$B$$ can be as large as $$10^5$$ and $$A$$ can also be as large as $$10^5$$.

## I cant find a solution for a question of an array about prefix sum?

if I was given the shuffled array of a combination of prefix sum array and suffix sum array as Input. How to find out the number of initial array possible which can produce input array (combination prefix and suffix sum arrays).

How will we find whether an input array is valid as sum of prefix sum array and suffix sum array

## Max heap and array relation

This question is about max heap and array

Suppose there is max heap h , if n data already stored in heap h. An array that is formed by inserting a value larger than all the value in heap at the beginning/head of the heap h is assumed to be new array C . The array C is a heap (or) not ?

My answer: is heap because its bigger than any other element in array

if n data already stored in heap h. A new array D that is created by adding a value u to the heap h that is smaller than any of the n data already stored in heap . if u is added to last element in heap h, is Array D heap or not?

My answer: it is heap because the smallest one has to be in the leaf

But what is the relation with array? Is there rule to insert node in heap? I know that to insert node to array in heap we insert data as last element of heap and then put it in the root and heapify it

## Which statement best describes an Array variable?

a) Used to represent a group of variables that are of the same data type and that can be referenced using one variable name.

b) Can only be defined in a main method.

c) Not a Data Structure.

d) If the programmer attempts to store another piece of data in a memory location, the original data being stored is written over and lost.

## Search for maximal value smaller than V in an array composed of K linear functions

Sorry for the lack of clarity in the question description.

I have an array composed of length N composed of K linear subarrays. We define a linear subarray as a contiguous subarray of the array [l,r] where A[i]-A[i-1] = C, a constant, for all l<i<=r. (Note: C may be different for different subarrays.)

I wish to find multiple queries for the maximal value that is less than a queried value V in sublinear time per query, such as O(logK), or even O(logN). I am fine with any preprocessing in time such as O(K), O(KlogK), but not O(N). (Assume that the array has already been stored in terms of the K linear subarrays, perhaps in terms of the constant C and length of each subarray, with the subarrays ordered.)

Of course, a balanced binary search tree (BBST) or simply sorting achieves the purpose, but it requires O(NlogN) preprocessing, which is too much. Checking the largest valid value within each subarray takes O(K) per query, which is again too much.

Randomised algorithms are okay as long as they always achieve the correct answer and work fast enough in the average case, though deterministic algorithms are preferred.

Thanks for any and all responses.

## After running through my algorithm fine, my array returns as all zeros

I’ve spent a long time finally getting my algorithm in Python to invert Laplace transforms and live plot them to work, but unfortunately, although it seems to run fine within the function, it continuously just plots zeros!

I’ve wasted so much time getting this thing to work, and now I have no clue what could be wrong. So forgive me but I think I’ll have to post the whole thing.

The equation this is based on is a series-integral and it iterates until the series converges. However, it converges super slowly so I used Aitken’s delta-squared method to speed the whole thing up. The goal is to populate array y with each Aitken’s iteration from 0.000001 to 10 and then compare the estimation’ integral with the previous iteration’s if a random point in the former is close enough to the latter. This loops until the integrals have a difference of less than 0.01 or a set amount of iterations is reached (~30000).

This happens for 6 equations simultaneously using parallel processing. The graph live plots all 6 (in blue) compared to each of the actual equations they’re converging towards (in red) using matplotlib.

For debugging, I basically tried putting a bunch of print statements everywhere in the f_u function to see what was going on. Everything looked like it was going fine. But in the __main__ function and plot functions when I did the same, I was getting all zeros for the same array. I thought it was a local vs. global issue so I put global y in the plot and f_u, with no luck.

I know this isn’t doing this due to the parallelization; I tried without it with no luck. Basically, I suggest looking at what y does between the f_u function and the __main__ function, thats where the relationship with the y arrays breaks down I think, I just don’t know what to do to fix it.

To execute this, you’re gonna need all the packages in the import statement, including numba. You can remove the @jit decorations on the Laplace functions if you don’t want numba, but it will be sloooooow.

Here it is:

import matplotlib.pyplot as plt from matplotlib import style from matplotlib import animation import numpy as np from scipy.integrate import quad, simps from scipy.special import jv import math import random import datetime import multiprocessing as mp from numba import jit  start = datetime.datetime.now()     # Record time start  # Initialize plot style.use('fivethirtyeight')  fig, axes = plt.subplots(3, 2) ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = axes  plt.autoscale(enable=True)  for ax in axes.flat:     ax.label_outer()  # Initialize variables gamma = np.array([np.nan, 1, 1, 0, 1.5, 2, 1])    # Bromwich contour parameter for each equation num = 6     # Number of equations to be processed in total n = 0   # Repetition constant for equation 3, set to either zero or 1 (diverges at 1) max_count = 1000   # Number of data points in x and y epsilon = 10 ** -40     # Minimum number to divide by in Aitken's iteration err = 10 ** -4    # Maximum difference in y to trigger comparison in closing() max_err = 0.01    # Maximum difference in integrals computed in closing() to end iteration process  x_0 = 0     # Set first integral to 0 for now result = np.zeros(7)    # Vector to store Aitken's iteration for closing() comparison previous = np.zeros(7)     # Vector to store iteration before Aitken's for closing() comparison end = np.zeros(7)     # Vector to store end conditions -- running = 0, ended = 1  u, step = np.linspace(0.000001, 10, max_count, retstep=True)    # Initializing x values  y = np.empty([num, 4, max_count])     # Initializing y values -- form is y[equation number][iteration in Aitken's][x value] y_denom = np.empty([num, max_count])    # Initializing array to store Aitken's denominator values for each equation x_iter = np.empty([num, max_count])    # Initializing array to store Aitken's iteration as starting point for next iteration  def printer(num, k):    # Prints the equation number, iteration and y value at 10     if num == 1:         print(str(num) + "    " + str(k) + "    " + str(y[0][3][max_count-1]) + "\n")     elif num == 2:         print(str(num) + "    " + str(k) + "    " + str(y[1][3][max_count-1]) + "\n")     elif num == 3:         print(str(num) + "    " + str(k) + "    " + str(y[2][3][max_count-1]) + "\n")     elif num == 4:         print(str(num) + "    " + str(k) + "    " + str(y[3][3][max_count-1]) + "\n")     elif num == 5:         print(str(num) + "    " + str(k) + "    " + str(y[4][3][max_count-1]) + "\n")     elif num == 6:         print(str(num) + "    " + str(k) + "    " + str(y[5][3][max_count-1]) + "\n")  def plot1():    # Plots estimation 1 (blue) and actual equation 1 (red)     global y     ax1.clear()     line1, = ax1.plot(u, y[0][3][0:max_count])     ax1.plot(u, np.sin(u), 'tab:red')     return line1,  def plot2():    # Plots estimation 2 (blue) and actual equation 2 (red)     global y     ax2.clear()     line2, = ax2.plot(u, y[1][3][0:max_count])     ax2.plot(u, np.heaviside(u, 1), 'tab:red')     return line2,  def plot3():    # Plots estimation 3 (blue) and actual equation 3 (red)     global y     ax3.clear()     line3, = ax3.plot(u, y[2][3][0:max_count])     ax3.plot(u, np.cos(2 * np.sqrt(u)) / np.sqrt(np.pi * u), 'tab:red')     return line3,  def plot4():    # Plots estimation 4 (blue) and actual equation 4 (red)     global y     ax4.clear()     line4, = ax4.plot(u, y[3][3][0:max_count])     ax4.plot(u, np.log(u), 'tab:red')     return line4,  def plot5():    # Plots estimation 5 (blue) and actual equation 5 (red)     global y     ax5.clear()     line5, = ax5.plot(u, y[4][3][0:max_count])     ax5.plot(u, np.heaviside(u - 1, 1) - np.heaviside(u - 2, 1), 'tab:red')     return line5,  def plot6():    # Plots estimation 6 (blue) and actual equation 6 (red)     global y     ax6.clear()     line6, = ax6.plot(u, y[5][3][0:max_count])     ax6.plot(u, jv(0, u), 'tab:red')     return line6,  def animate(i):     # Plots all equations, used to live-update graph     ln1, = plot1()     ln2, = plot2()     ln3, = plot3()     ln4, = plot4()     ln5, = plot5()     ln6, = plot6()     return ln1, ln2, ln3, ln4, ln5, ln6,  @jit(nopython=True, cache=True) def f_p1(omega, u, k):      # Equation 1, Laplace form     b = (omega + k * np.pi) / u     a = gamma[1]      f1 = a * (1 / (a ** 2 + (b + 1) ** 2) + 1 / (a ** 2 + (b - 1) ** 2)) * np.cos(omega)     return f1  @jit(nopython=True, cache=True) def f_p2(omega, u, k):      # Equation 2, Laplace form     b = (omega + k * np.pi) / u     a = gamma[2]      f2 = a / (a ** 2 + b ** 2) * np.cos(omega)     return f2  @jit(nopython=True, cache=True) def f_p3(omega, u, k):      # Equation 3, Laplace form     b = (omega + k * np.pi) / u     a = gamma[3]      f3 = np.e ** (-a / (a ** 2 + b ** 2)) * (a ** 2 + b ** 2) ** (1 / 4) * np.cos(         (math.atan2(b, a) + 2 * n * np.pi) / 2) * np.cos(b / (a ** 2 + b ** 2)) / (                 np.sqrt(a ** 2 + b ** 2) * (np.cos((math.atan2(b, a) + 2 * n * np.pi) / 2) ** 2 + np.sin(                     (math.atan2(b, a) + 2 * n * np.pi) / 2))) * np.cos(omega)     return f3  @jit(nopython=True, cache=True) def f_p4(omega, u, k):      # Equation 4, Laplace form     b = (omega + k * np.pi) / u     a = gamma[4]      f4 = -(a * np.log(a ** 2 + b ** 2) + a * np.e) / (a ** 2 + b ** 2) * np.cos(omega)     return f4  @jit(nopython=True, cache=True) def f_p5(omega, u, k):      # Equation 5, Laplace form     b = (omega + k * np.pi) / u     a = gamma[5]      f5 = a * (np.e ** (-a) * np.cos(b) - np.e ** (-2 * a) * np.cos(2 * b)) / (a ** 2 + b ** 2) * np.cos(omega)     return f5  @jit(nopython=True, cache=True) def f_p6(omega, u, k):      # Equation 6, Laplace form     b = (omega + k * np.pi) / u     a = gamma[6]      f6 = np.sqrt((a ** 2 - b ** 2 + 1) ** 2 + (2 * a * b) ** 2) * np.cos(         (math.atan2(2 * a * b, a ** 2 - b ** 2 + 1) + 2 * n * np.pi) / 2) / (             ((a ** 2 - b ** 2 + 1) ** 2 + (2 * a * b) ** 2) * (                 np.cos((math.atan2(2 * a * b, a ** 2 - b ** 2 + 1) + 2 * n * np.pi) / 2) ** 2 + np.sin(                     (math.atan2(2 * a * b, a ** 2 - b ** 2 + 1) + 2 * n * np.pi) / 2) ** 2)) * np.cos(omega)     return f6  def closing(result, previous, num, k):    # Checks for convergence. If so, adds each term to f_0 and ends process     if abs(result - previous) < max_err:         diff = abs(result - previous)          print("Equation " + str(num) + " converges to " + str(diff) + " with " + str(k) + " iterations." + "\n")          if num == 1:             for i in range(max_count):                 y[0][3][i] += f_0(num, i)             end[1] += 1             return 1         elif num == 2:             for i in range(max_count):                 y[1][3][i] += f_0(num, i)             end[2] += 1             return 1         elif num == 3:             for i in range(max_count):                 y[2][3][i] += f_0(num, i)             end[3] += 1             return 1         elif num == 4:             for i in range(max_count):                 y[3][3][i] += f_0(num, i)             end[4] += 1             return 1         elif num == 5:             for i in range(max_count):                 y[4][3][i] += f_0(num, i)             end[5] += 1             return 1         elif num == 6:             for i in range(max_count):                 y[5][3][i] += f_0(num, i)             end[6] += 1             return 1     else:         print("Equation " + str(num) + " has not yet converged.\n")         return 0  def f_0(num, i):     # Initial integral in the series. Added at end after closing() convergence test     if num == 1:         x_0 = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * quad(             f_p1, 0, np.pi / 2, args=(u[i], 0))[0]     elif num == 2:         x_0 = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * quad(             f_p2, 0, np.pi / 2, args=(u[i], 0))[0]     elif num == 3:         x_0 = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * quad(             f_p3, 0, np.pi / 2, args=(u[i], 0))[0]     elif num == 4:         x_0 = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * quad(             f_p4, 0, np.pi / 2, args=(u[i], 0))[0]     elif num == 5:         x_0 = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * quad(             f_p5, 0, np.pi / 2, args=(u[i], 0))[0]     elif num == 6:         x_0 = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * quad(             f_p6, 0, np.pi / 2, args=(u[i], 0))[0]      return x_0  def f_u(u, num):    # Main algorithm. Here, the summation integrals iterate     global y, result, previous    # Forces retrieval of from global of these arrays? (attempt to debug)     k = 1   # Number of iterations      for i in range(max_count):  # First overall series iteration (initial 1st)         if num == 1:             y[0][0][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                 f_p1, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]         elif num == 2:             y[1][0][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                 f_p2, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]         elif num == 3:             y[2][0][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                 f_p3, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]         elif num == 4:             y[3][0][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                 f_p4, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]         elif num == 5:             y[4][0][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                 f_p5, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]         elif num == 6:             y[5][0][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                 f_p6, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]      for j in range(10000):   # Iteration loop. Goes until closing() or k = ~30000 for each equation         if j > 0:             for i in range(max_count):  # Sets the first iteration (out of 3 for Aitken's) equal to the previous Aitken's or the first iteration if j = 0 (1st)                 if num == 1:                     y[0][0][i] = x_iter[0][i]                 elif num == 2:                     y[1][0][i] = x_iter[1][i]                 elif num == 3:                     y[2][0][i] = x_iter[2][i]                 elif num == 4:                     y[3][0][i] = x_iter[3][i]                 elif num == 5:                     y[4][0][i] = x_iter[4][i]                 elif num == 6:                     y[5][0][i] = x_iter[5][i]             else:                 k += 1          for i in range(max_count):  # Second iteration for Aitken's (2nd)             if num == 1:                 y[0][1][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p1, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 2:                 y[1][1][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p2, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 3:                 y[2][1][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p3, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 4:                 y[3][1][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p4, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 5:                 y[4][1][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p5, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 6:                 y[5][1][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p6, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]          k += 1          for i in range(max_count):  # Third iteration for Aitken's (3rd)             if num == 1:                 y[0][2][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p1, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 2:                 y[1][2][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p2, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 3:                 y[2][2][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p3, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 4:                 y[3][2][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p4, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 5:                 y[4][2][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p5, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]             elif num == 6:                 y[5][2][i] = 2 * np.e ** (gamma[num] * u[i]) / (np.pi * u[i]) * (-1) ** k * quad(                     f_p6, -np.pi / 2, np.pi / 2, args=(u[i], k))[0]          k += 1          for i in range(max_count):  # Aitken's delta-squared method iteration using the previous 3 (4th)             if num == 1:                 y_denom[0][i] = (y[0][2][i] - y[0][1][i]) - (y[0][1][i] - y[0][0][i])                  if abs(y_denom[0][i]) < epsilon:                     print("Denominator too small to calculate. Exiting...\n")                     return 9                  y[0][3][i] = y[0][2][i] - ((y[0][2][i] - y[0][1][i]) ** 2) / y_denom[0][i]             elif num == 2:                 y_denom[1][i] = (y[1][2][i] - y[1][1][i]) - (y[1][1][i] - y[1][0][i])                  if abs(y_denom[1][i]) < epsilon:                     print("Denominator too small to calculate. Exiting...\n")                     return 9                  y[1][3][i] = y[1][2][i] - ((y[1][2][i] - y[1][1][i]) ** 2) / y_denom[1][i]             elif num == 3:                 y_denom[2][i] = (y[2][2][i] - y[2][1][i]) - (y[2][1][i] - y[2][0][i])                  if abs(y_denom[2][i]) < epsilon:                     print("Denominator too small to calculate. Exiting...\n")                     return 9                  y[2][3][i] = y[2][2][i] - ((y[2][2][i] - y[2][1][i]) ** 2) / y_denom[2][i]             elif num == 4:                 y_denom[3][i] = (y[3][2][i] - y[3][1][i]) - (y[3][1][i] - y[3][0][i])                  if abs(y_denom[3][i]) < epsilon:                     print("Denominator too small to calculate. Exiting...\n")                     return 9                  y[3][3][i] = y[3][2][i] - ((y[3][2][i] - y[3][1][i]) ** 2) / y_denom[3][i]             elif num == 5:                 y_denom[4][i] = (y[4][2][i] - y[4][1][i]) - (y[4][1][i] - y[4][0][i])                  if abs(y_denom[4][i]) < epsilon:                     print("Denominator too small to calculate. Exiting...\n")                     return 9                  y[4][3][i] = y[4][2][i] - ((y[4][2][i] - y[4][1][i]) ** 2) / y_denom[4][i]             elif num == 6:                 y_denom[5][i] = (y[5][2][i] - y[5][1][i]) - (y[5][1][i] - y[5][0][i])                  if abs(y_denom[5][i]) < epsilon:                     print("Denominator too small to calculate. Exiting...\n")                     return 9                  y[5][3][i] = y[5][2][i] - ((y[5][2][i] - y[5][1][i]) ** 2) / y_denom[5][i]          k += 1         printer(num, k)          rand = random.randrange(0, max_count)   # Setting random number for x value          # Comparison between y at random x in Aitken's vs the previous iteration. If close enough, triggers closing()         if num == 1:             if abs(y[0][3][rand] - y[0][2][rand]) < err:                 result[num] = simps(y[0][3][0:max_count], u, dx=step)   #Integrates Aitken's iteration (4th)                 previous[num] = simps(y[0][2][0:max_count], u, dx=step)    #Integrates integration before Aitken's (3rd)                 c1 = closing(result[num], previous[num], num, k)                 if c1 == 1:                     break         elif num == 2:             if abs(y[1][3][rand] - y[1][2][rand]) < err:                 result[num] = simps(y[1][3][0:max_count], u, dx=step)                 previous[num] = simps(y[1][2][0:max_count], u, dx=step)                 c2 = closing(result[num], previous[num], num, k)                 if c2 == 1:                     break         elif num == 3:             if abs(y[2][3][rand] - y[2][2][rand]) < err:                 result[num] = simps(y[2][3][0:max_count], u, dx=step)                 previous[num] = simps(y[2][2][0:max_count], u, dx=step)                 c3 = closing(result[num], previous[num], num, k)                 if c3 == 1:                     break         elif num == 4:             if abs(y[3][3][rand] - y[3][2][rand]) < err:                 result[num] = simps(y[3][3][0:max_count], u, dx=step)                 previous[num] = simps(y[3][2][0:max_count], u, dx=step)                 c4 = closing(result[num], previous[num], num, k)                 if c4 == 1:                     break         elif num == 5:             if abs(y[4][3][rand] - y[4][2][rand]) < err:                 result[num] = simps(y[4][3][0:max_count], u, dx=step)                 previous[num] = simps(y[4][2][0:max_count], u, dx=step)                 c5 = closing(result[num], previous[num], num, k)                 if c5 == 1:                     break         elif num == 6:             if abs(y[5][3][rand] - y[5][2][rand]) < err:                 result[num] = simps(y[5][3][0:max_count], u, dx=step)                 previous[num] = simps(y[5][2][0:max_count], u, dx=step)                 c6 = closing(result[num], previous[num], num, k)                 if c6 == 1:                     break          for i in range(max_count):  # Setting current Aitken's iteration to first iteration             if num == 1:                 x_iter[0][i] = y[0][3][i]             elif num == 2:                 x_iter[1][i] = y[1][3][i]             elif num == 3:                 x_iter[2][i] = y[2][3][i]             elif num == 4:                 x_iter[3][i] = y[3][3][i]             elif num == 5:                 x_iter[4][i] = y[4][3][i]             elif num == 6:                 x_iter[5][i] = y[5][3][i]      # If iteration limit reached, sets process closing condition to 1 and returns to main     end[num] = 1     return  if __name__ == '__main__':     i = 0      # Define and begin processes, one for each equation     p1 = mp.Process(target=f_u, args=(u, 1))     p2 = mp.Process(target=f_u, args=(u, 2))     p3 = mp.Process(target=f_u, args=(u, 3))     p4 = mp.Process(target=f_u, args=(u, 4))     p5 = mp.Process(target=f_u, args=(u, 5))     p6 = mp.Process(target=f_u, args=(u, 6))      p1.start()     p2.start()     p3.start()     p4.start()     p5.start()     p6.start()      # While any equation is running, update and show the plot every second     while end[1] != 1 or end[2] != 1 or end[3] != 1 or end[4] != 1 or end[5] != 1 or end[6] != 1:         animation.FuncAnimation(fig, animate, interval=1000, blit=True)         plt.pause(1)         plt.show(block=False)         plt.pause(1)      # Joining and closing each process when complete     p1.join()     p1.terminate()     p2.join()     p2.terminate()     p3.join()     p3.terminate()     p4.join()     p4.terminate()     p5.join()     p5.terminate()     p6.join()     p6.terminate()      end = datetime.datetime.now()   # Record time end      print("Runtime: " + str(end - start))      # Updates and plots final result     animate(i)     plt.show()      exit(0) 

Hope you can help me out. Thanks in advance.

## How does Indexed work in terms of sparse array

I want to use indexed given that s is an element [0,500] but I am unsure how to write that without getting a format error or a tensor error.

\[CapitalDelta]t = .0001; t = .0833; \[Sigma] = .2183; \[CapitalDelta]s = 5; s = [0, 500]; \[Mu] = ((\[Sigma]^2 Indexed[s, i]^2)/     Indexed[\[CapitalDelta]s, i]^2*\[CapitalDelta]t); \[Alpha] = (Indexed[s, i]/(    2*Indexed[\[CapitalDelta]s, i]^2*\[CapitalDelta]t)); cn1[k2_, n_] =   SparseArray[{{m_, m_} ->      1/2 + 1/2*\[Mu] +       1/2*Indexed[rate, {k2, n}]*\[CapitalDelta]t, {m_, l_} /;       l - m == 1 -> -(1/4)*\[Mu] -       1/2*Indexed[rate, {k2, n}]*\[Alpha], {m_, l_} /;       m - l == 1 -> -(1/4)*\[Mu] +       1/2*Indexed[rate, {k2, n}]*\[Alpha]}, {101, 101}] 

## What is the maximum number of swaps to sort an array containing number from 1 … n?

I have this algorithm to sort an array which contains unique numbers from 1 to n.

public static void cyclicSort(int[] nums) {     int i = 0;     while (i < nums.length) {         if (nums[i] != nums[nums[i] - 1]) {             swap(nums, i, nums[i] - 1);         } else {             i++;         }     } }  static void swap(int[] nums, int i, int j) {     int temp = nums[i];     nums[i] = nums[j];     nums[j] = temp; } 

How can I prove that in worst case, the running time of this algorithm is still asymptotically O(N)?

My observation:

• Although i will not increase right after each swap but when it’s increase, the next number of required swaps will also be decreased.
• The maximum number of swaps at i = 0 will be O(N-1).

Second question is: Is the running time still O(N) if it contains duplicated numbers?

## How to predict the number of comparisons done by QuickSort if you know the percentage to which the array is pre-sorted?

I’ve noticed that correlating the number of comparisons done by a naive implementation of QuickSort with the percentage of elements that were already sorted gives you a curly-brace-shaped-curve if you use logarithmic scale: So, how can this curly-brace-shaped curve be mathematically described (the red curve represents the behavior of the c++ “sort” function, and it appears much more complicated)? If it can be done precisely, then one can precisely predict how many comparisons QuickSort would do simply by passing through the array, counting the number of elements for which array[i]<array[i+1], and inserting that number into a formula. I’ve tried to find a mathematical formula that approximates that using a genetic algorithm, here is what I ended up with:

f(n,s)=exp((ln(n)+ln(ln(n)))*1.05+(ln(n)-ln(ln(n)))*0.83*abs(2.38854*pow(s,7)-0.284258*pow(s,6)-1.87104*pow(s,5)+0.372637*pow(s,4)+0.167242*pow(s,3)-0.0884977*pow(s,2)+0.315119*s)) 

Here, ‘f’ signifies the number of comparisons done by QuickSort, ‘n’ signifies the number of elements in the array and ‘s’ signifies the proportion of the elements that are already sorted: it’s -1 if the array is reverse-sorted, 1 if it’s already sorted, and approximately 0 if it’s randomly shuffled.

Can you come up with a better formula?

## How to display “META” array in register_taxonomy

How do I get the “META” field to go off “META: []” for something filled in? I am using this code:

register_taxonomy( 'job_listing_category', 'job_listing', [             'labels' => [                 'name'              => _x( 'Categories', 'Category taxonomy labels', 'my-listing' ),                 'singular_name'     => _x( 'Category', 'Category taxonomy labels', 'my-listing' ),                 'menu_name'         => _x( 'Categories', 'Category taxonomy labels', 'my-listing' ),                 'search_items'      => _x( 'Search Categories', 'Category taxonomy labels', 'my-listing' ),                 'all_items'         => _x( 'All Categories', 'Category taxonomy labels', 'my-listing' ),                 'parent_item'       => _x( 'Parent Category', 'Category taxonomy labels', 'my-listing' ),                 'parent_item_colon' => _x( 'Parent Category:', 'Category taxonomy labels', 'my-listing' ),                 'edit_item'         => _x( 'Edit Category', 'Category taxonomy labels', 'my-listing' ),                 'update_item'       => _x( 'Update Category', 'Category taxonomy labels', 'my-listing' ),                 'add_new_item'      => _x( 'Add New Category', 'Category taxonomy labels', 'my-listing' ),                 'new_item_name'     => _x( 'New Category Name', 'Category taxonomy labels', 'my-listing' ),             ],             'rewrite' => [                 'slug' => \$  permalink_structure['category_base'],                 'with_front'   => false,                 'hierarchical' => false,             ],             'hierarchical'          => true,             'update_count_callback' => '_update_post_term_count',             'show_ui'               => true,             'show_tagcloud'         => false,             'public'                => true,             'show_in_rest'          => true,         ] );