## Time complexity of pairs in array double loop

I know, that the following is: O(n^2),

int count = 0; for(int i = 0; i<array.length(); i++) {    for(int j = i+1; j<array.length(); j++) {        if(array[i] == array[j]) {            count = count + 1;        }    } } 

But, should something like count = count + 1; be taken into account? For predicting or making up a complex time equation, or using sum notation,

n + n-1 + n-2 + n-3 + (…) + 1 

## Merkle tree sorting leaves and pairs

I am implementing a Merkle tree and am considering using either of the two options.

The first one is sorting only by leaves. This one makes sense to me since you would like to have the same input every time you are constructing a tree from the data, that might not arrive sorted by default.

       CAB       /    \      CA     \    /    \    \   C     A     B /  \  /  \  /  \ 1  2  3  4  5  6 

The second one is sorting by leaves and pairs, which means that after sorting the leaves, you also sort all the pairs after hashing them, however I’m not entirely sure about the benefits of this implementation (if any).

       ACB       /    \      AC     \    /    \    \   C     A     B /  \  /  \  /  \ 1  2  3  4  5  6 

I have seen these implementations of Merkle trees in the past but am not sure about their benefits. So why choose one over the other?

## Find original array from array with pairs of adjacent elements

Given an array composed of pairs, like this:

[[3,5],[1,5],[3,2],[1,4]]

Each element in the array (call it pair) means that pair[0] and pair[1] are adjacent in the original array. Note, they can come in either order. For instance, for the sample array above, the original array would be:

4,1,5,3,2 (or the reversed version of this)

How can I do this quickly? I tried doing this as follows, which works, but it’s too slow:

Create a hashmap that maps adjacent elements. Map = {3: [5,2], 1: [5,4], 5: [1,3], 4: [1], 2:[3]}. My algorithm would then start with one of the keys that only has a corresponding value length of 1 (in this case either 4 or 2), and then add to an output array, and go through the hashmap. I.e. First I would add 4 to my output, and then go from key of 4 (with a corresponding value of 1), to the key of 1, with corresponding values of 5 and 4. I’d ignore 4 (since it’s already in output), and add 5, then go to the key of 5, and so on and so forth. This is too slow! Is there a better algorithm?

## Fastest Algorithm for finding All Pairs Shortest Paths on Sparse Non-Negative Graph

As discussed here Johnson’s Algorithm can be used to solve the APSP-Problem in $$O(V^2\log V + VE)$$ in stead of $$O(V^3)$$ for Floyd-Warshall. However, Johnsons Algorithm does quite a bit of work for the case that some weights are negative. Is there a faster way to compute this given that all weights are positive?

## Why can’t Hash Suite see any username/hash pairs in my SAM file?

I recently started experimenting with Hash Suite 3.5.1 – a Windows program that tests the security of password hashes.

A problem I’m already running into is that Hash Suite is only able to see the username and hashes on my Windows 10 laptop but not my Windows 10 desktop. The main difference (that I can see) between the two PCs is that my laptop has BitLocker enabled! There must be something else that I’m missing here, related to the SAM file version and behaviour.

Laptop:

I can see my usernames in Hash Suite when using the "Import: Local accounts" option.

I haven’t been able to test this against an offline copy of my laptop’s SAM file due to BitLocker making it more complicated to extract the SAM file (as Windows locks it when booted) but I will try to test this scenario soon.

Desktop:

An offline version of the SAM file reveals no username/hash pairs.

When attempting to import local accounts from within Windows (something that works on the laptop), I get the following error:

LM and NTLM are both greyed out when selecting the offline copy of my SAM file:

Does anyone have any ideas why these two different Windows 10 systems are behaving differently?

## Algorithm for enumerating over all possible pairs (by size)?

Part A

What is a possible algorithm for enumerating over all possible pairs, by size, between two enumerable, countably-infinte sets, $$X$$ and$$Y$$, of words $$w$$? Aka, starting with $$|x|min + |Y|min$$ as the first element in the enumeration and then carrying on upwards?

Part B (more the question I’m after)

Is there a way to enumerate over all pairs $$(x,y)$$ so that there is one element (in the enumeration) of each size and no more? And, as an extra condition, the enumerator needs to be able to do this encoding of the pairs it enumerates in a way such that it doesn’t "mangle" the pairs. To define mangle: I need to be able to extract (read) $$X$$ and $$Y$$ back out of any string in the enumeration in poly time (measured in length of string in the enumeration (aka $$|X|+|Y|+or -|bits|$$ (depending on encoding used by enumerator)). So, whatever encoding the enumerator uses for its representation of the pairs…one needs to be able to decode that string back into $$(x,y)$$ in poly time and there has to be at least one string of each length representing some valid pair. So, given a natural number $$b$$, there is an element of the enumeration that is of length $$b$$ and we can decode that string of length $$b$$ back into ($$x,y$$) in less than $$b^k$$ time (just as an aside, this also means that $$|x,y|).

## Simplify Difference of Conjugate Pairs

Is it possible to easily simplify the difference of conjugate pairs?

In particular, if there’s just a single variable, then

FullSimplify[a - Conjugate[a]] 
2 I Im[a] 

But trying to do the same thing with a slightly more complex expression fails:

FullSimplify[a Conjugate[b] - Conjugate[a] b] 
a Conjugate[b] - Conjugate[a] b 

I have found one solution (answered below) but it relies on a FullSimplify which doesn’t seem very optimal.

## Finding largest farthest increasing pairs in array?

Is there a simple linear algorithm for finding in an array A two such elements that $$A[i] > A[j]$$ and $$i – j$$ is as large as possible? If one wants to actually return the indices, then linear memory usage seems impossible to avoid. If the only result needed is the value $$i – j$$, i.e. the distance, can we get away with less than linear memory?

Obviously, one can use constant memory if one is willing to loop over all pairs (i, j).

## Why does TLS1.3 use same cipher suite for RSA and ECC key pairs?

As per this answer RSA and ECC certificates should use different cipher suites. I tried to test it. It holds true for TLSv1.2. But for TLSv1.3 I see same cipher suite being used for both types of certificates(Tested via Google Chrome=>Dev Tools=>Security). Why is that?

Here is how I generated an ECC cert:

openssl ecparam -out nginx.key -name prime256v1 -genkey openssl req -new -key nginx.key -out csr.pem openssl req -x509 -nodes -days 365 -key nginx.key -in csr.pem -out nginx.pem 

Generating RSA cert:

 openssl genrsa -out rsa.key 2048  openssl req -x509 -new -nodes -key rsa.key -days 7300 -out rsa.pem 

With TLS1.3 both the certs result in usage of same cipher suite:

The connection to this site is encrypted and authenticated using TLS 1.3,  X25519, and AES_256_GCM. 

With TLS1.2, RSA cert:

    The connection to this site is encrypted and authenticated using TLS 1.2,  ECDHE_RSA with X25519, and AES_256_GCM. 

With TLS1.2, ECC cert:

The connection to this site is encrypted and authenticated using TLS 1.2,  ECDHE_ECDSA with X25519, and AES_256_GCM. 

## N numbers, N/2 pairs. Minimizing the maximum sum of a pairing. Proving greedy algorithm

So say I have n numbers, where n is even. I want to pair the numbers such that the maximum sum of the pairs is minimized. For example -2, 3, 4, 5. The ideal pairing is (-2, 5), (3, 4), since its maximum sum is 7, and that is the minimal sum possible for a max sum in any pairing. The key to the algorithm is to sort the values from least to greatest. Then pair the least with the greatest, and so on, until you reach the center of the ordering.

Example: 3, -2, 4, 5

Algorithm sorts the values: -2 , 3, 4, 5

Then pairs first with last: (-2, 5)

Then pairs the next available first and last: (3, 4)

Terminates since no pairs left.

This is a greedy algorithm and I am trying to prove that it is always correct using a “greedy stays ahead” approach. My issue is that I am struggling to show that the algorithm’s maximum sum is always $$\leq$$ optimal maximum sum. My intention was to suppose for contradiction that the optimal maximum sum is $$<$$ the algorithm’s maximum sum. But I’m not sure how to find a contradiction. How would this proof go?