Doest sorting accept a dynamic programming solution?

Are there any known / efficient dynamic programming solutions to sorting?

I understand of course that dynamic programming applies to scenarios where we have overlapping subproblems and optimal substructure, but I wonder if there are transformations and representations of the sorting problem where these conditions are met, and even better, where doing so may actually be useful.

PKCE vs Dynamic Client Registration for public clients

The RFC recommends to use PKCE for web (public client)/native apps. It’s not stated that Dynamic Client Registration (DCR) is bad but it’s not stated as an alternative either. I am wondering if there is any negative aspect of the DCR that i am overlooking.

I would say that the biggest difference between the two is the fact that PKCE is much easier to implement with less bookkeeping while offering about the same protections as DCR.

Looking through the use cases defined in the DCR specification, it looks like the use case of native app or SPA app is included.

Is there a reason why is not included in the best practices? Which use case is ideal to use the DCR?

Turning VTM battles more dynamic

I’m playing a VTM 20th edition campaign with my friends, and they are really liking it, the only thing that is not great is the combat.

Sometimes the group battle just one or two enemies, and it’s fine, but now they are at war with the Sabbath, and the Camarilla is helping then in some battles, but then the combat turns into something like 10 versus 5, and then it gets a little boring, for me, because I’m controlling all the characters and for then, because they need to wait 10 actions to do something.

I know that one solution would be to just reduce the size of the battles, but battles of this size are really great for my storytelling at the moment, is there anything else I can do?

Dynamic programming problem

our uni is closed because of the COVID-19 and I’m trying to homelearn dynamic programming.

In our algorithms book, there is the following problem: (an example problem for dynamic programming)

A driver has 3 cars. He wants to use all of the 3 cars, but want to use the least gas. Each car has a different engine, so it will consume different amounts of gas to get to each destination. What is the least amount of gas we can consume while still using each car? After he switches cars, he can’t go back to the previous car.

Input description:

First is a number $ n$ , which is the number of destinations that he wants to reach. Then there are 3 lines, each is the gas consumed while trying to reach each destination (line 1 is car 1, line 2 is car 2, etc..)

Example input:


2 4 1 5 1 1 2

3 3 2 5 3 2 2

1 1 5 4 3 3 3

Example output:

12 (third car (2 destinations), first car (4 destinations), second car (1 destination).)

However, I can’t figure out how to start, as I’m still learning DP. Could you please help me or give me any hints?

I think it’s a great good example problem, because other problems are very similar so if I master this one, I should be able to solve other problems.


MySQL 5.7 – Calling procedure with dynamic name

I’m trying to write a MySQL (5.7) procedure that dynamically calls another procedure based on the one of its inputs.

The code I came up with so far is this (procedure_exists works for checking whether or not the function is available):

CREATE PROCEDURE process_event (IN event_type VARCHAR(32), IN aggregate_id CHAR(36), IN payload JSON) BEGIN     DECLARE handler_name VARCHAR(38) DEFAULT CONCAT('handle', event_type);      IF procedure_exists(handler_name) THEN         SET @handler_sql = CONCAT('CALL ', handler_name, '(?,?)');          PREPARE prepared_statement FROM @handler_sql;          SET @aggregate_id = aggregate_id;         SET @payload = payload;          EXECUTE prepared_statement USING @aggregate_id, @payload;     END IF; END; 

This doesn’t work however, because I keep getting

[0A000][1336] Dynamic SQL is not allowed in stored function or trigger

From what I understand, disallowing that by default makes perfect sense, but from what I’ve gathered there seems to be no way of opting in to theoretically less secure behavior, by allowing certain types of statements or disabling the check altogether.

Do you have any suggestions for getting this to work?

In short the question boils down to this:

Can I somehow have a procedure to which I pass event_type (VARCHAR(32)), aggregate_id (CHAR(36)) and payload (JSON) which will then automatically call handle{event_type}(aggregate_id, payload) if it exists?

How to approach weighted job/interval scheduling problem with 2 machines (dynamic programming)

Given N jobs where every job is represented by the following: Start Time, Finish Time and Value Associated (>= 0) and two machines that can do the jobs,

The goal is to find the maximum value subset of the jobs such that no two jobs in the subset overlap.

How should I approach this? I could only think of using the solution for a single machine and then doing it again for the second machine…

$ \Omega(m)$ and $O(m)$ meaning in theorem proof about dynamic array complexity

My algorithms and data structures’ book states that to create a dynamic array the following procedure is followed:

Let $ d$ be the length of an array $ a $ and $ n $ the number of elements stored in it. Each time an insertion operation is done, if there is enough space $ (n+1<d)$ , $ n $ grows by 1; otherwise if $ n=d$ , we allocate and array $ b$ of size $ 2d$ , $ d$ is updated to$ 2d$ and all elements are copied to it, then we do $ a=b$ . Similarly, everey time a deletion operation is performed, $ n$ decreases by 1, when $ n=d/4$ , we allocate and array of size $ d/2$ , $ d$ is updated to $ d/2$ and we copy all elements of the array $ a$ to the array $ b$ an do $ a=b$ .

The pseudocode of the functions doing the array doubling and halving is shown in the picture

enter image description here

then the following theorem is prooved:

The execution of N insertion or deletion operations in a dynamic array requires a time $ O(n)$ , beside d=$ O(n)$

proof: Let $ d$ be the length of an array and n the number of elements stored in it After doubling the array’s size there are $ m=d+1$ elements in the new array of $ 2d $ positions. We need at least m-1 insertion requests for a new doubling and at least $ m/2 $ deletion requests for a halving. Similarly,after a halving, there are$ m=d/4$ elements in the new array of $ d/2 $ elements, for wich at least$ m+1$ insertion requests are needed for a new doubling and at least $ m/2 $ deletion requests are needed for a new halving.

In any case, the cost of $ O(m) $ time required for the resizing can be virtually distributed among the $ \Omega(m)$ operations that caused it(starting from the last resizing) . Finally, supposing the when the array is created there are $ n=1$ and $ d=1$ , the number of elements of the array is always one fourth of its size, so $ d=O(n)$

I am a beginner with this $ \Omega(m)$ and $ O(m)$ , I know the mathematical definitions and I’ve been reading a lot about it but I am not able to understand it well in context. I know big O should indicate an upper bound on the time complexity of an algorithm and big omega a lower bound.

I don’t understand the last paragraph when they use these symbols, Why is the time cost O(m), why are they using $ \Omega(m)$ for the number of operations that caused the resizing (besides specifically what operations are they referring to?) and why do they write $ d=O(n)$ , what should I understand from it? Any help will be greatly appreciated

ACF Dynamic select values not showing data

This question makes me crazy for almost 2 weeks. I know I am not expert in WordPress, so I am seeking for help here.

I have create a href that when user click it will go to new page.

<a href="./create-class?post=<?php echo $  post->ID; ?>">Add Class2</a> 

This href post the Post id. Url display:


create-class page:

At create-class page,I am using GET method to display post id from url

$  post = $  _GET['post']; 

I have acf form in create-class page for create new post. In this form, there have dynamic select field but the select field not display any data.

 <?php      acf_form(array(           'post_id'   => 'new_post',           'field_groups' => array(150),           'post_title'  => false,           'post_content'  => false,           'new_post'    => array(                   'post_type'   => 'classes',                   'post_status' => 'publish',                   ),           'return'    => '%post_url%',           'submit_value'  => 'Submit',           //'updated_message'    => 'Course Submit!',         )); ?> 

in my function.php I create function for dynamic select:

function acf_load_t_first_name2_field_choices($  field) {     global $  post;     //$  post = $  _GET['post'];     // reset choices     $  field['choices'] = array();       // get the textarea value from options page without any formatting     $  choices = get_field('t_first_name',$  post->ID);        // loop through array and add to field 'choices'     if( is_array($  choices) ) {          foreach( $  choices as $  choice ) {              $  field['choices'][ $  choice ] = $  choice;          }      }       // return the field     return $  field;  }  add_filter('acf/load_field/name=t_first_name2', 'acf_load_t_first_name2_field_choices');  

Is there something wrong with my code?