## Parallelism – time complexity of Parallel.ForEach

``````// first select companies to process from db

foreach (company) {
// select the employees
foreach (employee of company) {
// select items they can access
foreach (item) {
// do some calculation and save
``````

I think this will be an O (n ^ 3) time complexity. Please correct me if I am wrong. Big O always gave me a headache. My question is, if you introduce parallel processing at the first level, what will it be? What if we introduce a second? `parallel.foreach()` Also for the second iteration?

Posted on Categories Articles

## Java time complexity of subset problem

The subset exercise from LeetCode:

``````Example: For Input nums = (1,2,3) Return Output:
(
(3),
(1),
(2),
(1,2,3),
(1,3),
(2,3),
(1,2),
()
)
``````

has as backtrack solution:

``````public List> subsets(int() nums) {
List> list = new ArrayList<>();
Arrays.sort(nums);
backtrack(list, new ArrayList<>(), nums, 0);
return list;
}

private void backtrack(List> list , List tempList, int () nums, int start){
for(int i = start; i < nums.length; i++){
backtrack(list, tempList, nums, i + 1);
tempList.remove(tempList.size() - 1);
}
}
``````

The solution was hit here.
I would like to know how complex this solution is in terms of time and space. Apparently the temporal complexity `O(N * 2^n)`, The `N` come from the `tempList.add()` Operation, I have a problem understanding where the `2^N` I'm from.

## Algorithms – Improve algorithmic complexity

We have an array of N size. We need to perform Q queries that include each query, and Index I, for which we do the following:

``````for j=I+1 to N:
if A(j)``````
``` The queries are not independent of each other, so we have to use the modified array every time. I've thought a lot, but could only find a brute-force solution with the complexity of O (Q * N). Can someone tell me a better solution? E.g: - Array- 4 3 4 3 2, Query-3 2 After Query 1(Index 3, element 3)- 4 3 4 3 0 After Query 2(Index 2,element 4)-4 3 4 0 0 ```
``` ```
``` Author AdminPosted on November 10, 2019Categories ArticlesTags algorithmic, Algorithms, Complexity, improve ```
``` Complexity theory – First attempt to convert context-free grammar into Chomsky normal form This is my first attempt to convert a context-free grammar into a normal Chomsky form. I think I have the right answer, would appreciate any feedback if I made a mistake somewhere. Context free grammar V = {M, N, O} Σ = {+, *, (, ), x} R = { M ---> M + N M ---> N N ---> O * N N ---> O O ---> ( M ) O ---> x Chomsky normal form conversion Step one M will appear on the right side, so I'll create a new state called A: A ---> M M ---> M + N M ---> N N ---> O * N N ---> O O ---> ( M ) O ---> x Step two Ignored because there are no epsilon symbols Step three Give terminals next to non-terminals their own rule: A ---> M Y N M ---> M Y N M ---> O Z N N ---> O Z N N ---> Q M P O ---> Q M P O ---> x Y ---> + Z ---> * Q ---> ( P ---> ) Step four Remove productions A ---> B N M ---> B N M ---> C N N ---> C N N ---> D P O ---> D P O ---> x Y ---> + Z ---> * Q ---> ( P ---> ) B ---> M Y C ---> O Z D ---> Q M The context-free grammar is so … A ---> B N M ---> B N M ---> C N N ---> C N N ---> D P O ---> D P O ---> x Y ---> + Z ---> * Q ---> ( P ---> ) B ---> M Y C ---> O Z D ---> Q M Author AdminPosted on November 8, 2019Categories ArticlesTags Attempt, Chomsky, Complexity, contextfree, convert, form, grammar, normal, theory Complexity Theory – An algebro-combinatorial argument that P = NP This question has fascinated me for a long time and I recently wrote an article about it. The version of the calculation described in this article is similar to that used in topological quantum computing (but with access to higher topological dimensions). See here: https://engrxiv.org/8ht2m/ Abstract from article – We present a paper on a new quantum theory algorithm for solving the 3-satisfiability problem. The algorithm presented is not a standard quantum algorithm in the sense that it is intended only for true "physical" quantum systems (if it can be realized on these systems at all). Instead, we assume that the 3-satisfiability problem has an intrinsic complex quantum form that can be programmed to construct a solution space solution for satisfiable instances, or to show that such a model can not be constructed. This provides surprising results for the ability of classical systems to abstractively simulate general quantum systems. We also present other relevant structures, mathematical and physical, that have close analogies to the methods and structures presented. What do you think? As with all P / NP evidence, there can only be a gaping hole that we can not see. Author AdminPosted on November 7, 2019Categories ArticlesTags algebrocombinatorial, argument, Complexity, theory Complexity Theory – What are the requirements for a superset of P to be closed under carp reductions? Therefore, in our exercise on complexity theory, we discussed today that P, NP, and BPP are closed by carp reduction. We also thought that the evidence could probably be extended to simple generalizations of these three "classes of classes" (non-deterministic, deterministic, probabilistic) like EXPTIME. This asked us the question: Suppose you have a class of languages $$C supseteq P$$What are the necessary (and sufficient?) Requirements for $$C$$ be closed under carp reduction? Terminology: A language $$A$$ is reducible to another language $$B$$written $$A leq_m B$$ iff $$exists$$deterministic poly-time turing machine $$K_ {A, B}: forall x in {0,1 } ^ *: x in A iff K_ {A, B} (x) in B$$ holds. A class $$C$$ is closed under $$leq_m$$ iff $$forall B, A subseteq {0,1 } ^ *: B in C land A leq_m B implies A in C$$ holds. Author AdminPosted on November 5, 2019Categories ArticlesTags carp, closed, Complexity, reductions, requirements, superset, theory Complexity Theory – Post Correspondence Problem: Finding the Total Number of Solutions To let $$A = {a, b }$$ be an alphabet. $$P = A ^ * times A ^ *$$ An instance of the PCP is a non-empty list $$D = (d_1, d_2, …, d_n) in P ^ n$$ of couples of words. To a PCP instance $$D in P ^ n$$ an index sequence $$(i_1, i_2, …, i_m) in {1, …, n } ^ m, m in mathbb {N ^ +},$$ is a solution for D if it has the following property: to the $$(t, b) = d_ {i_1} diamond d_ {i_2} diamond … diamond d_ {i_m}: t = b$$ d) Now: $$d_1 = (ab, a), d_2 = (ab, ba), d_3 = (ba, b).$$ Explain why this PCP instance has no solution. My Answer: The first part of the pair always has two letters, while the second part has only one letter except a couple. This means that the first part always gets bigger than the second, unless you just use it $$d_2$$ since both the first and the second part each have two letters. But you can not do it $$d_2$$ since the initial letters do not match, you would already have to start with $$d_1$$ or $$d_3$$ which means that the first part becomes much larger than the second part. So you would never come to a solution. Is there a more formal way to answer the question? e) What are the possibilities for the total number of solutions for a random PCP instance? My Answer: I've tried to think about the different number of letters every Domino has for each part. But it does not seem right. Can you give me an indication of how to find out if and how many solutions exist? Author AdminPosted on November 5, 2019Categories ArticlesTags Complexity, Correspondence, finding, number, post, problem, Solutions, theory, Total Algorithms – Complexity of finding an alternating Hamiltonian (x, y) path in two-color complete edge graphs To let $$G$$ Be a simple complete diagram with an edge 2 coloring. An alternating Hamilton (x, y) path is a Hamiltonian path that starts at the vertex $$x$$ and ends at the vertex $$y$$ so that the colors of its edges alternate along the path. In (1) J. Bang-Jensen and G. Gutin raise the following problem: Exercise 5.14 Is there a polynomial time algorithm for finding an alternating (x, y) Hamiltonian path in $$G$$ With $$x, y$$ given? Does anyone happen to know the status of this problem? I think the problem is in P if the endvertices are unspecified. (1) Bang-Jensen, G. and Gutin, G., Changing Cycles and Paths in Edge-Color Multigraphs: A survey, Discrete Mathematics 165/166 (1997) 39-60 Author AdminPosted on November 5, 2019Categories ArticlesTags Algorithms, alternating, complete, Complexity, edge, finding, graphs, Hamiltonian, path, twocolor Complexity Theory – MaxClique is DP hard I want to show that MAX – CLIQUE = {(G, k) | the largest clique of G has the size, which is exactly k} DP completely The idea is to reduce MAX-CLIQUE to C = {(G1, k1, G2, k2) | G1 has a k1 clique and G2 has none k2-clique what i already know is dp-hard. I have seen the solution on the second page of this link, but it seems that there is an error in the fifth paragraph, because the graph that forms G # _1 equals the product tensor of the cardinality string k1 with the graph G1, because every chain has a number of clicks equal to 2, Author AdminPosted on November 4, 2019Categories ArticlesTags Complexity, hard, MaxClique, theory Complexity of the Hamiltonian path in directed full two-dimensional graphs Finding a Hamiltonian pathway in a directed bipartite graph is NP-complete. Problem 1 What is the complexity of the problem if we insist that the underlying graph of the digraph is completely bipartite? Is that known? (In other words, what is the complexity if the digraph is half-complete and not some digraph?) There is a variant of the problem we want to consider Problem 2 What is the complexity of the problem if the underlying graph is completely bisected (that is, the digraph is half-completely divided into two) and we specify the start and end vertex of the path? Author AdminPosted on November 4, 2019Categories ArticlesTags Complexity, directed, full, graphs, Hamiltonian, path, twodimensional Posts navigation Page 1 Page 2 … Page 40 Next page ```