Why decision tree method for lower bound on finding a minimum doesn’t work

(Motivated by this question. Also I suspect that my question is a bit too broad)

We know $ \Omega(n \log n)$ lower bound for sorting: we can build a decision tree where each inner node is a comparison and each leaf is a permutation. Since there are $ n!$ leaves, the minimum tree height is $ \Omega(\log (n!)) = \Omega (n \log n)$ .

However, it doesn’t work for the following problem: find a minimum in the array. For this problem, the results (the leaves) are just indices of the minimum element. There are $ n$ of them, and therefore the reasoning above gives $ \Omega(\log n)$ lower bound, which is obviously an understatement.

My question: why does this method works for sorting and doesn’t work for minimum? Is there some greater intuition or simply "it just happens" and we were "lucky" that sorting has so many possible answers?

I guess the lower bound from decision tree makes perfect sense: we do can ask yes/no questions so that we need $ O(\log n)$ answers: namely, we can use binary search for the desired index. My question still remains.

What method can be used to obtain a fifth and sixth “bonus feat”?

The goal is to obtain a total of six feats that clearly have the label of "bonus feat" at first level. The character class is Erudite, which has two first level bonus feats. Taking two flaws grants two more bonus feats.

How can I obtain the last two bonus feats at first level? Is there a race or template which has two features or abilities using the words bonus feat?

Not interested in TOs (theoretical optimizations), or methods which require helper NPCs, or wealth beyond a starting Erudite’s Wealth by Level.

calling a protected method in other packages [closed]

package com.example.sample; public class Test1; {     public enum EncodingFormat     {         _7Bits,_8Bits,Unknown;         protected String tosdkString()         {             switch(this)             {                 case _7Bits: return "7";                 case _8Bits: return "8";             }             return "";         }         static protected EncodingFormat fromString(String source)         {             switch(source)             {                 case "7": return _7Bits;                 case "8": return _8Bits;             }             return Unknown;         }     } } 
package com.example.destination;  import com.example.sample.test1;  public class Test2 extends Test1 {     protected Test2(SDK sdk)     {         m_sdk = sdk;     }      }     private void write(EncodingFormat encodeFormat) throws SdkException, WriteException     {          m_rbasdk.SetParam(PARAMETER_ID.P62_REQ_ENCODING_FORMAT, encodeFormat.tosdkString());     }  } 

Here I am getting error as tosdkString() has protected access in com.example.sample.test1.EncodingFormat. Can some one help me in resolving this issue.

Double JWT submit method

I’m implementing my JWT method by using the double submit method: where we separate the payload & header portion of the JWT from the signature.

The header & payload is stored in a separate cookie, not HttpOnly so its accessible by the client, and the signature is HttpOnly.

The implementation seems pretty straight forward, but I’m having an issue understanding how refresh works.

For example, since I’m using firebase, the users jwt token has an expiration of 1 hour. When that expires, we need to automatically refresh the token, but this means we are refreshing the whole token. The whole point of the signature token is to be session long.

How can we refresh just the payload & header part of the token, without it affecting the signature?

The strategy I am using is based on this article: https://medium.com/lightrail/getting-token-authentication-right-in-a-stateless-single-page-application-57d0c6474e3

Emergency method to erease all data off a machine within seconds

Imagine you are carrying highly sensitive information with you, maybe on a mission in a war zone. You get in an ambush and quickly need to erase all the files before they fall in the wrong hands. This has to happen within seconds.

What devices are used for such operations, are there special hard drives which have a physical switch to erase all memory at once? I’m thinking of active storage devices, which lose all information once the power supply is separated. Or is it enough to have the proper software combined with a regular HDD or SSD?

Does this method attempting to maximizing Assassin damage work?

I have a plan on how to get a lot of damage out with the assassin from Dnd 5e but I wanted to run the order of actions by you guys to see if it is correct or not.

Assassin 17/warlock 3

  • Apply serpent venom poison to rapier
  • Casts Invisibility via warlock invocation “Shroud of Shadow” (Xanathar’s Guide to Everything)
  • Sneaks to target
  • Casts Hex on the target which is a bonus action and chooses constitution so the enemy gets a disadvantage on constitution saving throws
  • Invisibility drops since Hex was cast
  • Casts Green-Flame Blade for melee attack

If the attack hits then the enemy will have to make a constitution saving throw to prevent death strike and the poison however they will have disadvantage from hex. They will then take:
(2d6 hex + 18d6 sneak attack + 6d8 fire + 6d6 poison + 5 dex modifier + 2d8 rapier)*2

Is the enemy surprised even though I used hex before my attack? Is there anything wrong with this order of events? Is my calculation also correct?

Is there any good method to find if a grammar is optimal for a problem?

I’ve been thinking about grammatical evolution problems and how the grammar influences the algorithm performance. It came to my mind the huge impact that the grammar that you’re using has in the time that takes an algorithm to reach an optimum solution.

The simplest example would be if your problem doesn’t involve trigonometric operations. If you’re trying to find f(x) = 3x - 1/2, including sins, tangents or square roots in your grammar will, almost certainly, slowen your algorithm as the population complexity will grow. Other not-so-evident simplifications for a grammar would be trigonometric identities:

tan(x) = sen(x) / cos(x) 

Talking about this last example, I don’t know how to determine the importance of the impact of including tan(x) between the grammar rules to produce valid solutions. Or in other words, knowing if adding tan(x) will be better in terms of performance than don’t doing it and thus, forcing the evolution to combine two or more operators and terminals to being able to use that operation and making the grammar ambiguous.

So this two are the questions:

  1. Is there any way of knowing if a grammar is optimal for finding a solution?
  2. Which evolutionary algorithm or machine learning method (considering that I’m almost profane in this discipline, some explanation is wellcome) would you use for finding optimal or sub-optimal grammars?


C++ STL: How does the distance() method work for a set/ multiset (stored internally as a self balancing tree)?

I’m working on the problem: Count smaller elements on right side using Set in C++ STL

The solution is to add each element to the set and then to count the elements on the left, the distance function is called.

This is the algo:

1. Traverse the array element from i=len-1 to 0 and insert every element in a set. 2. Find the first element that is lower than A[i] using lower_bound function. 3. Find the distance between above found element and the beginning of the set using distance function. 4. Store the distance in another array Lets say CountSmaller. 4. Print that array 

I’m having a hard time to visualize or understand how can distance function be used with a set like structure since internally, the set data is stored as a self balanced tree (Red Black Tree). Whats the concept of distance for a self balancing tree and how does calling distance() give us the count of smaller elements on the right side?

How to create another shipping method which based on the previous shipping method

I have two shipping methods,

  • Standard
  • Express

Standard shipping method will be calculated based on the items amount and other data. In the express shipping method, I just want to add x amount. Let say if the standard shipping is 50 then it will be increased in the express 52. and if it is 60 then it will be 62. So basically increase the express shipping cost by adding 2 to standard shipping cost.

How this can be done?