Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Skip to content
# Tag: structures

## data structures – Time complexity of algorithms

## data structures – Given a binary min-heap, find the $k$-th element

data structures – Given a binary min-heap, find the $k$-th element – Computer Science Stack Exchange
## data structures – Reverse An Array whats wrong with this type of code?

data structures – Reverse An Array whats wrong with this type of code? – Computer Science Stack Exchange

$begingroup$
## data structures – Should Binary Expressions make use of built in functions in interpreters?

## data structures – Sort a d-sorted array

## lo.logic – Are there structures in a finite signature that are recursively categorically axiomatizable in SOL but not finitely categorically axiomatizable?

## data structures – So just fresh installed windows needing help debloating

## data structures – find the strong component containing the vertex v

data structures – find the strong component containing the vertex v – Computer Science Stack Exchange

$begingroup$
## data structures – Memory allocation of priority queues

## disk structures – SQL Server Logical Device for Directories

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.

Sign up to join this community

Anybody can ask a question

Anybody can answer

The best answers are voted up and rise to the top

Asked

Viewed

7 times

$begingroup$

```
import java.io.*;
import java.util.*;
public class reverseAnArray2
{
public static void main(String args())throws IOException
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter size");
int n = sc.nextInt();
int a () = new int (n) ;
int b () = new int (n) ;
System.out.println("Enter elements");
for(int i=0;i<n;i++)
{
a(i)=sc.nextInt() ;
}
int size = n;
System.out.println("Reverse array is : ");
int p=0;
while(n>=0 && p<n)
{
a(--n) = a(p) ;
++p;
}
for(int i =0;i<size;i++)
{
System.out.println(+ a(i));
}
}
}
```

The output comes correct but only up to the last $n/2$ terms, rest of it gets repeated. The output was correct when I used another fresh array to store data. But that’s not an optimal code. I want to reverse it without using another array.

$endgroup$

Notice that you increment $p$, whilst also decrementing $n$. Since your condition in the `while`

loop is that `p < n`

, then the while loop will only work for half the elements.

Also, note that you delete the last $n/2$ values, since you modify them without first reading them.

$endgroup$

Computer Science Stack Exchange works best with JavaScript enabled

I have been developing a statically typed language with support for autocasting. The language has a lot of built in functions with good support for overloading. I’ve noticed that this built in function system could be used to evaluate binary expressions by implementing operator built in functions with different overloads e.g.

```
int operator+(int, int)
float operator+(float, float)
int operator-(int, int)
float operator-(float, float)
```

It feels like I’m doubling up my efforts to handle operator evaluation, when realistically they could piggyback the built in method system which has type checking and links the node (my interpreter uses the visitor pattern) to the actual function that would retrieve the parameters and do some computation with them – effectively what the old operator system already has to evaluate an expression.

Does this approach sound sensible? In theory it sounds good to me but I don’t know if I’m oversighting something. I know that all languages must have a intrinsic implementation for operators, but I don’t know how they link it to the actual AST.

**Implementation**

If this approach is indeed a good approach, at what level should I implement the built in function support to a binary expression? For example I could adjust the parser so that when it receives 2+2 it can generate a methodCall node with parameters `(2, 2)`

and the name `operator+`

, which would effectively treat all operators as calls to methods from the get go. Or I could stick with a binaryExpression node and link it to the correct function during semantic analysis.

Given an array (1,…,n), The array will be called **d-sorted**, if every key in the array is located in a distance not greater then a constant * d* from his location in the sorted array

I need to write algorithms that get a d-sorted array with the length of n and sorts the array in the runtime of:

- Θ(n) if
**d**is a constant - Θ(n(log(log(n)))) if
**d**is Θ(log(n))

My Attempts:

I wrote this following pseudo-code:

```
Sort_d_array(A(),d)
min-heap-size <- d
for i <- 1 to n
BUILD-MIN-HEAP(min-heap,heap-size)
if min-heap not empty
then EXTRACT-MIN <- A(i)
if i+d<=n
then heap-insert-min(min-heap,A(i+d))
```

But in terms of runtime, all I get is BigO(nlog(log(d)))

MY METHOD:I initialized`i <- 1`

and then I built a`min-heap`

that contains all of the first d elements

as long as the`heap is not empty`

, I used`EXTRACT-MIN`

and put the element at i index in

the array and if`i+d<=n`

, then`A(i+d)`

will be an element in the

min-heap

Any help?

Recall that a structure $mathcal{M} = langle M, I^sigma_M rangle$ in a signature $sigma$ is categorically axiomatized by a second-order theory $T$ when, for any $sigma$-structure $mathcal{N} = langle N, I^sigma_N rangle$, $langle N, mathcal{P}(N), I^sigma_N rangle vDash T$ just in case $mathcal{N}$ is isomorphic to $mathcal{M}$.

It is fairly easy to find a structure in a finite signature that is categorically second-order axiomatizable but not finitely categorically second-order axiomatizable. Add a single function symbol $f$ to the language of second-order arithmetic, and choose a non-second-order-definable $zeta: mathbb{N} rightarrow mathbb{N}$. Then consider the theory $T$ that adds to the axioms of second-order arithmetic ($mathsf{Z}^2$) the sentence $f(bar{n}) = overline{zeta(n)}$ for each natural number $n$, where $bar{m}$ is the canonical numeral for $m$. (I owe the idea for this example to Andrew Bacon.)

This theory $T$, however, is not recursively axiomatizable. Is there a structure in a finite signature that has a recursive categorical second-order axiomatization but no finite categorical second-order axiomatization?

I believe that it is possible to find a recursively axiomatizable second-order theory $T$ whose spectrum (i.e., the set ${kappa in mathsf{Card}: exists mathcal{M} (mathcal{M} vDash T$ and $vert mathscr{M} vert = kappa)}$) is shared by no finitely axiomatizable second-order theory, using partial truth predicates. (Consider the theory with $mathsf{Z}^2$ relativized to some predicate $N$ and ${$“The cardinality of the non-$N$s is not $Sigma^1_n$-characterizable”$: n in omega}$.) But I cannot see how to turn this into a categorical theory.

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.

Sign up to join this community

Anybody can ask a question

Anybody can answer

The best answers are voted up and rise to the top

Asked

Viewed

12 times

$begingroup$

I’m trying to solve this question for practising purposes:

“Describe a linear-time algorithm for computing the strong component containing a given vertex v. On the basis of that algorithm, describe a simple quadratic-time algorithm for computing the strong components of a digraph.”

The question can be found here . It is question 31.

They give a couple of hints:

“Partial solution: To compute the strong component containing s

- Find the set of vertices reachable from s
- Find the set of vertices that can reach s
- Take the intersection of the two sets

Using this as a subroutine, you can find all strong components in time proportional to t(E+V), where t is the number of strong components.”

**My thoughts so far:**

- In order to find the vertices reachable from s, I can to DFS (or BFS, but will stick with DFS) from s. If n is the number of vertices and m is the number of edges this takes O(n+m) time, which seem fine for the purpose. I need to safe every discovered vertex somewhere. Not sure which datastructure works best for this. I will come back to this problem later.
- In order to find all vertices that can reach s, I could bild/compute the reverse of the graph and to another DFS from a again. Computing the reverse of the graph should be O(n+m) and the DFS is O(n+m). So in total I have 3*O(n+m) which is just O(n+m). Of course the discovered vertices also need to be safed.
- I’m not sure about how to build the intersection. Of course this is going to depend on how I saved the nodes before. So here are my ideas:

Building the intersection:

- If I saved the nodes in two separate arrays (one for the first DFS and one for the second) I possibly could use a Hash-Table. This should be O(|firstNodes| + |secondNodes|) time. Maybe this would be ok, since O(|firstNodes| + |secondNodes|) is smaller than O(n+m), but it doesn’t seem optimal to me and it need extra space.
- What if I mark the nodes I discoverd with the first DFS. Then I do the second DFS and check if nodes are already marked. If yes, I mark them “special” as belonging the the strong component? I wouldn’t have a list afterward that gives me the vertices of the strong component s belongs to but the strong component is still computed? For this approach I would need extra space at every node (in order to mark it).
- In order to find all strong compoonents in time proportional to t(E+V) I could then to the same procedure on a vertex that is not yet marked as belonging to a strong component -> as long as there are such vertices, therefore t times. I would need to make sure, that every strong component is marked differently (e.g. increaing integers) and that the “I fould you” marks from the DFS are gone after each iteration (but not the marks for the strong components).

What do you think? What have I missed?

Thank you and happy Easter!

$endgroup$

Since you are not trying to write an optimal algorithm, like this one or that one, I suggest you do not try to optimize space usage too much, especially if the optimization only diminish the multiplicative constant, but not the asymptotic space complexity.

All your ideas are sound. During a BFS, since you need to check if vertices are seen or not, the common way to do it is to use a boolean array. Now for a strongly connected component, you will run two BFS’s, and use two boolean arrays. The intersection can be computed by a index-wise AND.

$endgroup$

Computer Science Stack Exchange works best with JavaScript enabled

An associative dictionary is any data structure which maps keys to values. Binary search trees, hash tables, and B-trees are all examples of associative dictionaries. It is incorrect to say that an associative dictionary must be a binary search tree.

Similarly, a priority queue is any data structure which allows insertion in any order and removal in priority order. A binary heap is an example of a priority queue, but it is incorrect to say that a priority queue must be a binary heap.

There are lots of other data structures which implement priority queues, including n-ary heaps (for n greater than 2), binomial heaps, Fibonacci heaps, Brodal queues, van Emde Boas trees, and many more besides.

And that’s leaving aside the issue that a binary heap doesn’t strictly need to be stored in contiguous memory. Any storage scheme can be used as long as it can be indexed like an array and supports $O(1)$ access time.

Your privacy

DreamProxies - Cheapest USA Elite Private Proxies
100 Private Proxies
200 Private Proxies
400 Private Proxies
1000 Private Proxies
2000 Private Proxies
ExtraProxies.com - Buy Cheap Private Proxies
Buy 50 Private Proxies
Buy 100 Private Proxies
Buy 200 Private Proxies
Buy 500 Private Proxies
Buy 1000 Private Proxies
Buy 2000 Private Proxies
ProxiesLive
Proxies-free.com
New Proxy Lists Every Day
Proxies123