Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i have a problem.
I have a element and another list of elements, which are connected to the first one in some way.
i want to check, which elements of the list are children of the first. Save the result in an array. Then i will pick the first child and look for his children. save that and so on and on and on.
The problem is, i dont know the exact number of relations. so i could have many many loops and searches.
do i need to program every single loop and array (to save to) or is there a better way?
EDIT:
Iam talking about DB tables. I have two tables. I want to check the children (data in table2) for every element in table1. So i start with a Loop in table1. Elements in Table 1 and table2 are connected with coordinates xy. so iam searching for all elements in table2 where table1_element1.xy == table2.xy. As result there could be n children. Now i want to save them and start for those children a new loop to find for every child his children based on the coordinates. save that new result an so on and on.
More clear?
Thank you.
this problem can be easily solved with the help of recursion.
In this case your termination condition will be when any node don't have any relation in the list or when you reach the end of the list where you are storing the children.
Thanks
While the question is a little vague, rather than programming every individual loop, a more elegant way of writing this would be through recursion. You would set your break condition to be when you find a child (if I'm understanding the problem correctly) with no relations.
As for the storage issue, it sounds like you may want to use some form of a Topology data structure where each node would hold a list of all nodes connected to it through your relation.
Hope this helps.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
Is this Cosmos DB (SQL API) query:
SELECT * FROM c WHERE c.Name = 'John'
Faster or cheaper than
SELECT * FROM c WHERE c.Personal.Name = 'John'
I'm trying to understand the consequences of designing my data flat VS nested (not normalized vs de-normalized).
Thanks
The two versions of query you mention are probably very close in terms of cost, but the more important impact of model complexity in my experience is the cost of writes. Cosmos creates an index by default for every possible path from the item root. That means the more complex your model, the more paths will be indexed, which directly increases the cost of a write operation. As the indexing docs note:
By optimizing the number of paths that are indexed, you can
substantially reduce the latency and RU charge of write operations.
So if you embed a Personal item within your root item with multiple properties, you make your item more expensive to write.
There are also quite a few questions on StackOverflow from people asking how to write queries for their complicated object models, who never like the comment "why not a more straightforward model?" If you have the chance, avoid that fate. :)
In general, keeping items as simple and small as possible seems like the rule of thumb to follow. As always, test and see. The RU cost of queries are deterministic so you can directly know the impact of a change just by tweaking variables and running a quick test.
This is a question from the last years exam in my Data Structures course..
So, a Queue (data structure) consisting of n elements is implemented using pointers. The question is to find the maximum and minimum number of pointers used in that data structure?
So, I don't really understand where to start with this. I know the implementation of Queue using pointers. From it, I guess we only need two pointers, one for Front and Rear, which may be the minimum.
On the other hand, the elements of the Queue are cells that contain pointers on the next element, so there should be n+1 pointers?
Would be grateful for a nice explanation of this..or at least a hint if nothing else?
I have been working on implementing a priority queue of strings in c++ using a binary tree.
As I think the simplicity of recursion is great. I am not going to post code as I have already spent a long time today with the debugger and I am not asking for someone to debug for me, but basically after implementing recursive methods to dequeue and insert elements and testing correct behavior with up to 1000 random strings I have used a test hub that tries to enqueue 10000 random strings and I have a stack overflow error. After this, I have changed my recursive methods for others that use a pointer cursor to scan my tree to insert and dequeue using the same logic and it has not crashed as I expected (i have coded it almost as a linked list).
The question is then, Can I cause stack overflow through recursion even if I use to pass by reference?
These recursive methods are part of a class and defined as private.
I hope the question is not vague but I am still not experienced enough in c++.
Thanks a lot for your help!
In recursion you're calling your function again and again. On every call you use the stack memory for parameters, stack variables and more. So basicly the answer is definitely yes, a deep recursion can cause a stack overflow.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Simplified Question:
Is it practical for a programmer to keep track of the addresses of variables, so that a variable's address can be used as a point of data on that variable?
Original Question:
I am attempting to wrap my head around how variables are stored and referenced by address using pointers in Go.
As a general principal, is it ever useful to assign a variable's address directly? I can imagine a situation in which data could be encoded in the physical (virtual) address of a variable, and not necessarily the value of that variable.
For instance, the 1000th customer has made a 500 dollars of purchases. Could I store an interger at location 1000 with a value of 500?
I know that the common way to do something like this is with an array, where the variable at position 999 corresponds to the 1000th customer, but my question is not about arrays, it's about assigning addresses directly.
Suppose I'm dealing with billions of objects. Is there an easy way to use the address as part of the data on the object, and the value stored at that location as different data?
for instance, an int at address 135851851904 holds a value of 46876, 135851851905 holds 123498761, etc. I imagine at this point an array or slice would be far too large to be efficient.
Incidentally, if my question due to a misunderstanding, is there a resource someone can provide which explains the topic in deep, but understandable detail? I have been unable to find a good resource on the subject that really explains the details.
is it ever useful to assign a variable's address directly?
You can use the unsafe package to achieve that but the idea is that you don't do it unless you have a concrete and otherwise unsolvable use-case that requires it.
Could I store an interger at location 1000 with a value of 500?
As mentioned before it is possible but choosing an arbitrary address won't get you far because it may not even be mapped. If you write to such a location you'll get a access violation (and your program will crash). If you happen to hit a valid address number you'll likely be overwriting other data that your program needs to run.
Is there an easy way to use the address as part of the data on the object, and the value stored at that location as different data?
In general no.
If you managed to build some kind of algebraic structure closed under the operations by which your own pointer-arithmetic is defined in a finite set of addresses which you can guarantee to always be a valid virtual memory segment then yes but it defeats the purpose of using a garbage collected language. Additionally it would be hell to read such a program.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So, I have a website with a search bar.
I have only figured out how to get results when they match (at least in part using Like %searchterm%) and it works.
Obviously, this does not help me if the user misspells something.
We have discovered through HeatMapping that we are losing people on this.
How can I implement a "smarter" search feature?
Thanks,
Yoni
The "real" solution that you are looking for might be more complicated than you think. You could use simpler solution that will work fine like using the DIFFERENCE function.
I am trying to leave a comment, but not able to. So i have to leave it here, and it might not be the ideal answer Yoni is expecting. I can think of two ways of doing it.
use asp.net autocomplete function. It will query the db, and feed the user back with suggested search results dynamically when users are typing which will prevent users mistyping somehow. many search engines use it frequently like Google, Yahoo. In asp.net, its very easy to wire it up.
ASP.NET Auto Complete
This is how Auto complete looks like
add a class to re-process the search terms before querying the database, so you wont get 0 hit if users mis-spell or mis-type something. This is very broad, and it varies a lot depending on your business model concept.
Hope it helps. :)
This is quite a complex matter, impacting on both coding complexity and query performances.
Of course there may be a lot of approaches to achieve the results you ask for.
Personally, I would start by working with aliases: for each word that user may search for, I would create a set of aliases, that may be related to word semantic value or to mistyping of the word itself, eg:
Word: sheet
Aliases: paper, shet, shee ...
So, each single word must be indexed (and this could be a cumbersome aspect to deal with, depending on your contents), and for each woed there may be many aliases.
Then apply a sequential logic like the following:
1 - standard search, as the one you already did
-> if nothing matches
2 - alias search
-> if nothing matches
3 - start "playing" with wildcard characters (this could definitely kill your db however)
I understand this is a quite generic answer, but I don't think there may be an absolutely good approach - performance wise - to your question.