## Confused by proof of correctness of Majority

I have been studying a streaming algorithm to determine if there is a majority element in a stream. But am confused by a proof for it.

The algorithm works as follows. You keep one counter $$c$$ and a store for one item called $$a^*$$. When a new item arrives, first you check if $$c == 0$$. If so you set $$c=1$$ and $$a^*$$ stores the arriving item. Otherwise, if $$c>0$$ and the arriving item is the same as $$a^*$$ you increment $$c$$ or decrement $$c$$ if not.

If there is a majority element then it will be stored in $$a^*$$ at the end.

In the notes from http://www.cs.toronto.edu/~bor/2420f17/L11.pdf there is a proof of this fact (called simpler proof).

I can see that if there is a majority item then $$c’$$ will be positive at the end of the stream. But:

• How do we know that $$a^*$$ will hold the majority item at the end?
• Does $$c’$$ being positive imply that $$c$$ will be positive too?

## A bit confused about the time complexity of this theorem vs. my situation

In this paper polynomiality of n-fold integer programming problem is discussed.

(My question is very simple and it is stated at the end. There is no need to deeply understand the excerpts they are provided for the purpose of being complete.)

Excerpt 1:
The n-fold integer programming problem. Fix a $$p \times q$$ integer matrix $$A$$. Given positive integer $$n$$ and integer vectors $$b = (b^0, b^1, \ldots , b^n)$$ and $$c = (c^1, \ldots , c^n)$$, where $$b^0 \in \mathbb{Z}^q$$, and $$b^k \in \mathbb{Z}^p$$ and $$c^k \in \mathbb{Z}^q$$ for $$k = 1, \ldots, n$$, find a nonnegative integer vector $$x = (x^1, \ldots , x^n)$$, where $$x^k \in \mathbb{N}^q$$ for $$k = 1, \ldots, n$$, which minimizes $$cx= \sum_{k=1}^{n}c^k x^k$$ subject to the equations $$\sum_{k=1}^{n} x^k = b^0$$ and $$Ax^k = b^k$$ for $$k = 1, \ldots, n$$.

Excerpt 2:
In this article, we establish the following theorem. Naturally, the input size is $$n$$ plus the bit size of the integer objective vector $$c \in \mathbb{Z}^{nq}$$ and the integer right-hand side vector $$b \in \mathbb{Z}^{q+np}$$.
Theorem 1.1. Fix any integer matrix $$A$$. Then there is a polynomial-time algorithm that, given any $$n$$ and any integer vectors $$b$$ and $$c$$, solves the corresponding n-fold integer programming problem.

My Question:
I have an Integer Programming at hand. For a given integer $$k$$, my $$A$$ (like above) is $$3 \times 2k$$, and my $$n$$ (like above) is $$k$$, and let us assume that bit size of my integers is of $$O(\log (k))$$. Is the aforementioned theorem still applicable to my situation? Especially because $$q$$ in my situation depends on $$k.$$

## I’m really confused with my .htaccess config

My directory structure is

- Assets - Dashboard    - index.php    - account.php index.php about.php verify.php 

What i basically want it to be:

1. Remove the .php extension for example http://example.org/about.php should be http://example.org/about/ (including the trailing slash as well)
2. If .php is encountered in the URL redirect it back to http://example.org/about/
3. Instead of having the URL as http://example.org/verify.php?key=123456 it should be http://example.org/verify/123456
4. Conditions to be met in sub directory as well for example http://example.org/dashboard/ should be the URL instead of http://example.org/dashboard/index.php

My .htaccess file looks like this

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^.]+)  1.php [L] RewriteRule ^verify/([0-9a-zA-Z]+)\.php /verify.php?key=$1 [NC,L] <FilesMatch "\.(jpg|png|svg|css)$  "> Header set Cache-Control "proxy-revalidate, max-age=0" </FilesMatch>   <Files .htaccess> order allow,deny deny from all </Files>  Options All -Indexes  ErrorDocument 403 /404.html ErrorDocument 404 /404.html ErrorDocument 500 /404.html 

Im really sorry for not giving much clarity.

I’m running it on localhost XAMPP web server.

• Rule 3 and 4 works absolutely fine!
• Rule 1 works fine but when it encounters the trailing slash it gives me a 404.
• Rule 2 doesn’t seem to work.

## Confused between 2 phase locking and 2 phase commit

I understand that both algorithms are very different, but what I don’t understand is whether they achieve the same thing in the end. 2PC is for atomic commits and 2PL is for serializable isolation. But don’t they both achieve the two things? don’t these goals imply each other in the end?

## Confused about fighter’s Two Weapon Fighting Style

A fighter in a campaign I am running has the Two Weapon Fighting Style and I am having some trouble with finding details on how it works.

• Does he have to wield two light weapons? Or can he use (for example) a sword and a battleaxe?

• Can he strike two different targets within his range for one attack (e.g., sword attacks a goblin, off-hand weapon attacks another goblin)?

• What exactly is the penalty — is it that the damage modifier only goes to weapon #2 and weapon #1 gets no damage modifier?

## Really confused about latency with pipelining

I finished watching a video about pipelining https://www.youtube.com/watch?v=eVRdfl4zxfI which I thought made sense. Latency is the amount of time it takes to complete each instruction. Even with pipelining, the time it takes to complete an instruction is still the sum of the time it takes for every stage, in this case it’s 20ns.

But then I did a bit more studying and found out the latency is supposed to be time for the longest stage to finish execution + the “cost” of pipelining, rather than the sum of time it takes to execute all the stages? http://web.cs.iastate.edu/~prabhu/Tutorial/PIPELINE/perform.html

Is there something I’m missing?

## Confused in how to insert a slack variable in a constrain inequality

According to my understanding , we should put a slack variable to equate an inequality constrain by inserting the slack varaible in the side that is less than the other side , for example if we have 4x+2<2 this will be 4x+2+slack_variable=2 .But here in Wikipedia :
https://en.wikipedia.org/wiki/Slack_variable In the example section , it says the following “By introducing the slack variable y>=0, the inequality Ax<=b can be converted to the equation y-Ax+b = 0” Which means that the slack variable is inserted in the bigger side ! Please some one explain this confusion.

## Confused about spell sources for Artificer

I am going to play my first D&D campaign soon. I have played lots of Neverwinter nights (not the mmo) which I hope will give me something of a grounding.

Anyway, I have chosen to be an Artificer.

The spell list states that some of the spells are from Xanathar’s Guide to Everything. I did some googling, found a link to the book’s content and the spells are not listed there… Confused!

I do some more googling and find out that they actually seem to be in the Players Companion for Elemental Evil.

What confuses me more is that the same spells listed here also have comments from people saying that they are not in the normal players guide but are in fact in Xanathar’s.

Could someone help me out? Where is the true source for these spells?

## Confused about O(n) and O(1)

int n = 1000; int cnt = 0; for (int i = 0; i < n; i++)    cnt++; 

Is the above code O(n) or O(1)? If I run the above code many times, it still iterates 1000 times. I’m really confused. I assumed it’s O(1), but I’m not sure about it. Could anyone verify this?

## Confused on Variational AutoEncoder

I’m a bit confused on how Variational Autoencoders are trained. In particular I’m confused on how the latent variable is generated for each input.

My questions are as follows:

1. When running stochastic gradient descent does the sampled latent variable stick with the data point during the entire run or does a new latent variable get sampled each time descent is run?

2. If running batch or full gradient descent, each data point gets its own set of sampled latent variables right?

3. How do you check for convergence? Assuming the latent variable is sampled at each iteration, it’s not clear to me how you can evaluate if you have converged or not given the stochastic nature of the performance function.