## Computing average access time

A computer has a cache memory and a main memory with the following features: 

– Memory cache access time: 4 ns – Main memory access time: 80 ns – The time needed to load a line in cache is 120 ns. – Write-through policy. If the hit ratio in this computer is 95 % and the 90% of the memory accesses are read operations, what is the average access time?

It seems a bit weird to me since I have read through this site calculate the effective (average) access time (E AT) of this system but I still do not know how to do it. I would appreciate any help. Thanks!

## Proving injectivity for an algorithm computing a function between sets of different types of partitions [closed]

I am attempting to solve the following problem:

Let $$A$$ be the set of partitions of $$n$$ with elements $$(a_1, \dots, a_s)$$ such that $$a_i > a_{i+1}+a_{i+2}$$ for all $$i < s,$$ taking $$a_{s+1} = 0.$$ Define $$g_n = F_{n+2}-1$$ and let $$B$$ be the set of partitions of $$n$$ as $$b_1 \ge \dots \ge b_s$$ such that $$b_i \in \{g_n\}$$ for all $$i,$$ and if $$b_1 = g_k$$ for some $$k,$$ then $$g_1, \dots, g_k$$ all appear as some $$b_i.$$ Prove $$|A|=|B|.$$

Attempt: Let $$e_i$$ be the vector with $$1$$ at position $$i$$ and $$0$$ elsewhere. If $$b_1 = g_k,$$ let $$c=(c_k, \dots, c_1)$$ count how many times $$g_i$$ appears. We calculate $$f: B \to A$$ as follows:

Let $$c=(c_k,\dots,c_1), a=(0,\dots,0).$$ While $$c \ne 0,$$ let $$d_1 > \dots > d_k$$ be the indices such that $$c_{d_i} \ne 0.$$ Replace $$c, a$$ with $$c-(e_{d_1}+\dots+e_{d_k}), a+(g_{d_1} e_1 + \dots + g_{d_k} e_k)$$ respectively. After the while loop ends, let $$f(b)=a.$$

Let $$\sum a, \sum b, \sum c$$ be the sum of the components of $$a, b, c$$ respectively. Since $$\sum c$$ decreases after every loop, the algorithm terminates and $$f(b)$$ is well-defined. Since $$c_k g_k + \dots + c_1 g_1 + \sum a$$ does not change after every iteration, is $$\sum b$$ at the start and $$\sum a$$ at the end, we have $$\sum f(b) = \sum b = n,$$ so $$f(b)$$ is also a partition of $$n.$$ Now $$a = (g_k, \dots, g_1)$$ after the first loop, which satisfies the condition $$g_i > g_{i-1}+g_{i-2}$$ since $$g_i = F_{n+2}-1 = (F_{n+1}-1)+(F_n-1)+1 > g_{i-1}+g_{i-2}.$$ Furthermore, after every iteration of the loop, the difference $$a_i – (a_{i-1}+a_{i-2})$$ changes by $$0, g_{d_j}-g_{d_{j-1}} > 0,$$ or $$g_{d_j}-(g_{d_{j-1}}+g_{d_{j-2}}) > 0,$$ so we have $$a_i > a_{i-1} + a_{i-2}$$ at the end and hence $$f(b) \in A.$$ Thus, $$f: B \to A$$ is well-defined.

In order to prove the injectivity of $$f,$$ it suffices to prove each loop iteration as a mapping $$(c,a) \to (c’,a’)$$ is injective, which would imply the mapping $$(c,0) \to (0,a)$$ that the while loop creates is injective. Indeed, if $$f(b_1) = f(b_2) = a$$ with $$(c_1, 0), (c_2, 0)$$ being sent to $$(0, f(b_1)) = (0,a), (0, f(b_2)) = (0,a)$$ respectively, then we have $$(c_1, 0) = (c_2, 0) \Rightarrow c_1 = c_2 \Rightarrow b_1 = b_2.$$

Suppose $$d_1 > \dots > d_i, f_1 > \dots > f_j$$ are the non-zero indices of $$c_1, c_2$$ respectively and $$c_1 – (e_{d_1}+\dots+e_{d_i}) = c_2 – (e_{f_1}+\dots+e_{f_j}), a_1+g_{d_1}e_1 + \dots+ g_{d_i} e_i = a_2 + g_{f_1} e_1 + \dots + g_{f_j} e_j.$$ If $$x \ge 2$$ is an entry of $$c_1,$$ it decreases by $$1,$$ so the corresponding entry in $$c_2$$ after $$c_2$$ is modified is also $$x-1,$$ which means it must’ve been $$(x-1)+1 = x$$ before since $$x-1>0.$$ Thus, if the values of two positions of $$c_1, c_2$$ differ, one is $$1$$ and the other is $$0.$$ However, if $$c_1 = (1,0), a_1 = (3,1), c_2 = (0,1), a_2 = (4,1),$$ then $$(a_1, c_1), (a_2, c_2)$$ both get sent to $$((5,1), (0,0)).$$ I can rule out this specific example by arguing that one of the pairs is illegal and could not have come from any choice of initial $$c,$$ but I have no idea on how to do this in general.

What should I do next in order to show $$f$$ is injective? Furthermore, since the problem I’m trying to prove is correct, injectivity would imply $$f$$ is secretly a bijection. But I have no clue on how to even start on the surjectivity of $$f,$$ so I just constructed a similar algorithm for $$g: A \to B$$ in the hopes of proving $$g$$ is injective too. If I can show $$f$$ is injective I will probably know how to show $$g$$ is.

Here is an example of $$f, g$$ in practice:

Let $$n = 41, b = (12, 7, 7, 4, 4, 2, 2, 2, 1) \Rightarrow c = (1, 2, 2, 3, 1).$$

$$((1, 2, 2, 3, 1), (0,0,0,0,0)) \to ((0, 1, 1, 2, 0), (12, 7, 4, 2, 1)) \to ((0, 0, 0, 1, 0), (19,11,6,2,1)) \to ((21,11,6,2,1),(0,0,0,0,0)),$$ so $$f(b) = (21,11,6,2,1).$$

Let $$a = (21, 11, 6, 2, 1).$$

$$((21,11,6,2,1),(0,0,0,0,0)) \to ((9,4,2,0,0), (1,1,1,1,1)) \to ((2,0,0,0,0),(1,2,2,2,1)) \to ((0,0,0,0,0),(1,2,2,3,1)),$$ so $$g(a) = (12, 7, 7, 4, 4, 2, 2, 2, 1).$$

## Computing FIRST and FOLLOW

Given the following grammar with terminals $$VT=\{[,],a,b,c,+,-\}:$$

$$S \rightarrow [SX]|a$$

$$X \rightarrow +SY|Yb|\epsilon$$

$$Y \rightarrow -SXc|\epsilon$$

This should be the FIRST function:

$$first(S) = \{[,a\}$$

$$first(X) = \{\epsilon,+,-,b\}$$

$$first(Y) = \{\epsilon,-\}$$

What would the FOLLOW function be?

## Create an algorithm for computing the shortest path in O(m + nlogn)

So I’m trying to write an algorithm for computing the shortest path with constraints on the vertices you can visit in O(m + nlogn) time. In this problem, we are given an indirect weighted (non negative) graph G = (V, E), a set of vertices X ⊂ V, and two vertices s, t ∈ V \ X. The graph is given with adjacency lists and we can assume that it takes O(1) time to determine if a vertex is in X. I’m trying to write an algorithm which can compute the shortest path between s and t in G such that the path includes at most one vertex from X if such a path exists in O(m + nlogn) time. I know that this algorithm would require a modified Dijkstra’s algorithm but I’m unsure how to proceed from here. Could anyone please help me out? Thank you

## When computing asymptotic time complexity, can a variable dominate over other?

I want to express the asymptotic time complexity for the worst case scenario of sorting a list of $$n$$ strings, each string of length $$k$$ letters. Using merge-sort, sorting a list of $$n$$ elements requires $$O(n\log n)$$. Comparing two strings of length $$k$$ has a cost of $$O(k)$$. Therefore, the cost would be $$O(kn\log n)$$.

However, I know some restrictions about $$k$$ and $$n$$ due to the nature of the problem. In particular, I know that for any list, $$0 \lt k \leq 20$$, and $$0 \lt n \leq 80000$$. In other words, the number of words in a list might vary in a much larger range than the length of the words.

In that case, would it be correct to say that $$n$$ dominates over $$k$$ and therefore the cost could be expressed as $$O(n\log n)$$? Or does the fact that we are discussing asymptotic costs make those restriction meaningless (as we are describing how the algorithm is impacted by the growth of each variable, regardless of how much they can actually grow)? In general, if two variables are independent, is it possible to dismiss one of them from the asymptotic cost under certain circumstances?

## Parallel Computing

Write a parallel algorithm which runs in $$\Theta(n)$$ time and transposes a $$n*n$$ matrix on the $$2D$$ mesh SIMD Model with wraparound connections. Processing element $$P(i, j)$$ has local variables $$A(i, j)$$ and $$T(i, j)$$, where $$1 \leq i, j \leq n$$. When the algorithm begins execution $$A(i, j) = a(i, j)$$. After execution $$T(i, j) = a(j, i)$$. No processing element should use more than a constant number of variables. Prove that the cost of the algorithm is $$\Theta(n)$$. (Question adapted from MJ Quinn book, Parallel Computing Theory and Practice 2nd Edition, Chapter 7).

## Computing the partition function

Are there in any relatively efficient algorithms to compute the partition function $$P(n)$$ for a given $$n$$? What’s the runtime complexity or class of this problem as a function of $$n$$?

Perhaps I’m missing something trivial here, but other than listing some recurrent definitions of this function and some of their asymptotics, I don’t see this precise information (complexity class, and known algorithms with their runtime/space complexity) in either of these articles:

• Partition(number theory)
• Partition function (number theory)

## Minecraft Computing

Basic computers have been created and optimized several times before in Minecraft. These were based on logic gates constructed from the ‘redstone torch’ block. I (who knows little of computers) was wondering if you could create one based on ‘shulker boxes’ which hold 27 slots that you can read, write, and move around a machine.

## Computing the minimum distance between each pain of points

I am trying to read an algorithm for computing minimum distance between each pair of points from the book: Algorithm Design

Algorithm Design

It considers the points in a line. If the points are in a line why we need to sort them? We can start from the beginning and compute the distances from starting pint to all the points on the right.

Some body please guide me why we need sorting?

## Circuit depth of computing the continued fractions of a rational number

If you want to convert a rational number into its continued fraction, what is the circuit depth of this process, in terms of the total number of bits of input?

I was reading through some notes which mentioned that the work being done while computing the continued fraction is basically the same as the work being done while computing a GCD. Are their circuit depths similar?