$\Phi_1=1$ or $\Phi_1=2$ for the dynamic $\text{Table-Insert}$ , where $\Phi_i$ is the potential function after $i$ th operation, as per CLRS

The following is the section from Introduction to Algorithms by Cormen. et. al. in the Dynamic Tables section.

In the following pseudocode, we assume that $ T$ is an object representing the table. The field $ table[T]$ contains a pointer to the block of storage representing the table. The field $ num[T]$ contains the number of items in the table, and the field $ size[T]$ is the total number of slots in the table. Initially, the table is empty: $ num[T] = size[T] = 0$ .

$ \text{Table-Insert(T,x)}$

$ 1\quad \text{if $ size[T]=0$ }$

$ 2\quad\quad \text{then allocate $ table[T]$ with $ 1$ slot}$

$ 3\quad\quad size[T] \leftarrow 1$

$ 4\quad\text{if } num[T] =size[T]$

$ 5\quad\quad\text{then allocate $ new-table$ with $ 2 • size[T]$ slots}$

$ 6\quad\quad\quad\text{insert all items in $ table[T]$ into $ new-table$ }$

$ 7\quad\quad\quad\text{free $ table[T]$ }$

$ 8\quad\quad\quad table[T] \leftarrow new-table$

$ 9\quad\quad\quad size[T] \leftarrow 2 • size[T]$

$ 10\quad \text{insert $ x$ into $ table[T]$ }$

$ 11\quad num[T] \leftarrow num[T] + 1$

For the amortized analysis for the a sequence of $ n$ $ \text{Table-Insert}$ the potential function which they choose is as follows,

$ $ \Phi(T) = 2.num[T]-size[T]$ $

To analyze the amortized cost of the $ i$ th $ \text{Table-Insert}$ operation, we let $ num_i$ denote the number of items stored in the table after the $ i$ th operation, $ size_i$ denote the total size of the table after the $ i$ th operation, and $ \Phi_i$ denote the potential after the $ i$ th operation.

Initially, we have $ num_0 = 0, size_0 = 0$ , and $ \Phi_0 = 0$ .

If the $ i$ th Table-Insert operation does not trigger an expansion, then we have $ size_i = size_{i-i}$ and $ num_i=num_{i-1}+1$ , the amortized cost of the operation is $ \widehat{c_i}$ is the amortized cost and $ c_i$ is the total cost.

$ $ \widehat{c_i}=c_i+\Phi_i- \Phi_{i-1} = 3 \text{ (details not shown)}$ $

If the $ i$ th operation does trigger an expansion, then we have $ size_i = 2 . size_{i-1}$ and $ size_{i-1} = num_{i-1} = num_i —1$ ,so again,

$ $ \widehat{c_i}=c_i+\Phi_i- \Phi_{i-1} = 3 \text{ (details not shown)}$ $

Now the problem is that they do not make calculations for $ \widehat{c_1}$ the situation for the first insertion of an element in the table (line 1,2,3,10,11 of code only gets executed).

In that situation, the cost $ c_1=1$ , $ \Phi_0=0$ and $ num_1=size_1=1 \implies \Phi_1 = 2.1-1 =1$

We see that $ \Phi_1=1 \tag 1$

So, $ $ \widehat{c_1}=c_1+\Phi_1-\Phi_0=2$ $

But the text says that the amortized cost is $ 3$ , (I feel they should have said the amortized cost is at most $ 3$ , from what I can understand)

Moreover in the plot below,


The text represents graphically the $ \Phi_1=2$ which sort of contracts $ (1)$ , but as per the graph if we assume $ \Phi_1=2$ then $ \widehat{c_i}=3, \forall i$

I do not quite get where I am making the fault.

Dynamic Update for 2D Random Walk

I have code for a random walk

pt = Accumulate[{Sin@#, Cos@#} & /@ RandomReal[{0, 2 Pi}, 1000]]; boundary = {Min@pt, Max@pt}; Norm@Last@pt; ListLinePlot[pt, PlotRange -> {boundary, boundary}, AspectRatio -> 1] 

which produces something like this:

Random Walk

I want to try to animate this, so that I can see how the random walk updates step by step with each new coordinate. I tried using DynamicUpdating but I couldn’t really get it to work. Is there any way to achieve this? Any help is extremely appreciated!

Create dynamic sql query to select all related data in DB based on entry table and ID

Hope all is well. I am hoping you can help me.

Problem Statement – I’m tasked to create a dynamic SQL statement which will select all related data from a given table where the Identifier is passed. For each table where the relevant data is found i would like the data to be exported onto a separate tab of within excel

If i was doing this manually done this i would perform the following queries and export the data onto each tab;

Select * from  Mason where id = 12345 Select * from  MasonContacts where Companyid= 12345  Select * from  MasonOpportunities  where Comid = 12345  

However given the sheer volume of tables this isn’t viable.

Step 1 : Type in my identifier (in this case my identifier is a field called "Id" in the Table "Mason") The query will always start from this table.

Table Name : Mason Field : Id = "12345"

Step 2 : Search against table "MasonContacts", search against the field "Companyid". Return all columns & records where the field "Companyid = 12345"

Table Name : MasonContacts Field : Companyid

Step 3 : Search against table "Mason Opportunities ", search against the field "Comid". Return all columns & records where the field "Company = 12345"

Table Name : MasonOpportunities Field : Comid

Looking forward to your help

Sets in Mathematics are immutable but in Computer Science sets are mutable and called “Dynamic Sets” – truth of the statement

While reading the classic text Introduction to Algorithms by Cormen et. al. I came across the following claim:

Sets are as fundamental to computer science as they are to mathematics. Whereas mathematical sets are unchanging, the sets manipulated by algorithms can grow, shrink, or otherwise change over time. We call such sets dynamic.

I felt a bit odd after reading the statement that "set" in Mathematics and in CS are different from the mutable point of view. Now in Mathematics what we deal with are theoretical aspect of things and as such "set" is a theoretical concept and so it is in Theoretical CS. If it is immutable in mathematics then so it is in CS. Mathematics and Theoretical CS are interlinked. So given a graph algorithm which say finds the minimum shortest path between a pair of vertices , we can’t say whether it belongs to Mathematics or CS.

Often in algorithms we write statements as :

$ $ S = S \cup \{a\} \quad \text{view $ 1$ }$ $

Which seems to sort of change our set $ S$ , but if we look it in this way:

$ $ S’= S \cup \{a\} \quad \text{view $ 2$ }$ $

$ $ S=S’$ $

So in the second situation we are not modifying our actual set $ S$ we are forming a new set $ S’$ with $ S$ augmented with $ a$ and then after that we are making the variable $ S$ refer to $ S’$ .

What I feel is that the concept of the set being mutable or immutable is solely dependent on the data-structure of representation of the abstract concept of "sets" and since in data-structure the two steps in view $ 2$ are combined and implemented, so they are called dynamic sets.

In short I feel that Dynamic Sets are data-structure implementation of sets and not the abstract sets.

dynamic keystroke

What complications arise in dynamic keystroke monitoring as a bio-metric authentication mechanism when the users’ keystrokes are sent over the internet? In particular, what characteristics of the keystroke sequences are valid, and which ones are distorted by the network?

Add ID to widget within a dynamic sidebar

I would like my widgets to have a unique ID, preferably based on the title given to the widget. My specific case is that I would like to have a jump link (<a href="#widget-title">) to target widgets in a dynamic sidebar located in the footer of my site. I would like my widget to be wrapped in a div, i.e. <div id="widget-title">, or even better, if I could add that id to the tag that contains the widget’s title, i.e. <h3 id="widget-title"> (I’d love to avoid an extraneous div).

I know that each widget has its own ID somewhere that I could access, but I worry that if I use that, then add/change/delete widgets later, the ID may change. But I can and will always keep the widget title consistent. Right now the widget I have in mind has an ID of custom_html-4, but I’d like something more static and semantic.

Is it possible to have and use a dynamic dictionary for brute-forcing?

For some reason – totally useless for the question – I have this PDF file with a password I forgot and I have no way to remember. I know for a fact (the person who created and gave me this PDF told me so) that the password starts with "AAbcDef", has some other characters but I don’t know how many. It also has a ‘2’ after AAbcDef, don’t know where precisely, AND also has a special character. In short: it’s a 9+ character password that may contain all the possible ASCII characters.

To crack this password I’m using John the Ripper, to create the dictionaries I’m using Crunch, so I can easily create all the dictionaries I need and then mix them in a single file. The problem is that I had to give up after testing all the possible 12-characters-long passwords, because the size of the file was HUGE. It weighted 100 GBs, which meant I couldn’t go any further because I don’t have enough memory on my SSDs or HDDs.

But even having enough memory, it simply wouldn’t be suitable. What if I had to search for all the characters? What if this password were just a 12 long character password, but I had to build the dictionaries with all the permutations and dispositions for all the ASCII characters?

So, how do hackers hack those kind of passwords? I’m certainly missing something, but I lack further knowledge and Google only tells me stuff I already know. Do they use some sort of dynamic dictionary where the program creates a new password by itself and then tests it, until it find the right one?

Minimization of amount in the change coins problem using the dynamic programing approach

I’m learning the dynamic programming approach to solve the coins change problem, I don’t understand the substitution part

Given: amount=9, coins = [6,5,1],

the instructor simplified it with this function:

minCoins = min {(9-6)+1 , (9-5)+1, (9-1) +1} = min{4, 5, 9} = 4

I don’t understand the logic of this min method: why we say that to change amount of 9 coins, we can simply, take the minimum of: 9 – {all coins} +1 ?

here’s a Gif that visualizes the instructor’s approach: https://i.stack.imgur.com/Zx2cG.gif

(*taken from the Algorithmic Toolbox course/ instructor: Prof. Pavel A. Pevzner)

Sitemap: Should I dynamically update sitemap for dynamic content or create a page containing all the dynamic links

Say i have the following route http://<my-domain>/{category}/subjects/{id}/Sitemap: Should I dynamically update sitemap for dynamic content or create a page containing all the dynamic links

the ones in the brackets are dynamic, I’m struggling with what is better or any better way to let google crawl through all these dynamic links

Approach 1: manually doing the job by removing or adding the record to site map and updating <lastmod>

Approach 2: create a page that includes all those links and reference that page in sitemap.xml

The second approach can be generated as a plain html file which is generated from the server app. Or, a simple webform aspx page that dynamically generates those links without having to create an html file.

Dynamic Programming – Thief Variation Probem

I’ve encountered a Dynamic Programming problem which is a variation of the thief one.

Say you are a thief and you are given a number of houses in a row you should rob :

$ $ House_1,House_2 \dots House_N$ $

with each house having the following values : $ $ (x_i \geq y_i \geq z_i \gt0)$ $

You profit X if you rob a house but none of the adjacent houses.

You profit Y if you rob a house and exactly one of the adjacent houses.

You profit Z if you rob a house and both of the adjacent houses.

Cases with houses A-B-C would be :

$ $ Profit(001)=0+0+C_x$ $ $ $ Profit(101)=A_x+0+C_x$ $ $ $ Profit(110)=A_y+B_y+0$ $ $ $ Profit(111)=A_y+B_z+C_y$ $

Where 1 stands for robbing the house and 0 for not robbing the house

Obviously you can’t utilize the Z value for the first and the last house and each set of values is random.

Now the question is : Which houses should you rob to get the maximum profit?

My main issue is that i can’t establish a base case for this problem.

At first i thought of creating a N*M array with M being the maximum amount of houses i can rob from 0-N when every house is not robbed and think like : Rob it – Don’t rob it but came up with nothing.

Any tips or directions would be appreciated.

Thanks in advance.