Is sentinel node exactly dummy node? - data-structures

Let us say in a linked list, many leetcode solutions suggest that we can create a dummy node to make a problem easier ( dummy_node = ListNode(0) ). My DS&A professor also recommends us to have a sentinel node pointing to the head of the linked list. I wonder are they talking about the same thing? Thanks in advance!

Yes, it is.
The term sentinel node I heard is from CS61B. They mean exactly the same thing.
However, since a lot of people don't know what sentinel is(I forget the leetcode question number, but the hottest comment of a linked list problem solution is like, "wow, I have solved so many linked list problems using dummy node without knowing it is called sentinel"), I will continue using the term dummy or dummy_node

Related

Barnes-Hut tree creating

I am currently trying to create a Barnes-Hut octree, however, I still not fully understand how to do this properly. I have read threads here, this article and some others. I believe I do understand how to make a tree if every node contains the information about the indices of particles inside, and if you keep storing the empty nodes. But if you do not want to? How to make a tree such that at the end you will only have necessary information: say, monopoles and quadrupoles for all non-empty nodes. I made so many different attempts that now I am completely confused, to be honest. What should I contain in each node? What would be the pseudocode for such thing?
P.S. By the way, is it different for monopoles and quadrupoles? I mean I can imagine that you do not need the exact information about the particles inside the node to calculate a monopole (it is just a full mass of node), but for quadruple?
Thank you in advance!
P.S. By the way, I use julia language if it is somehow relevant.

What are some pagerank alternatives?

This is strictly related to the graph algorithm(not SEO or anything). I'm interested in knowing if there are other algorithms out there that solely use the structure of a graph(not content like keywords, etc) to make inferences?
So for example, if your given a large graph full of nodes how can you make inferences assuming you have no idea what the values within the nodes actually mean(for example, pagerank knows who's linking(edges) to whom and doesn't know anything about the content itself)?
This is not exclusive to web searching, anything that uses graph structure to make inferences.
As well as HITS [as suggested by #larsmans], there is also SALSA, which is concidered more "stable" from HITS [and thus is less vulnerable to be affected by spammers].
You are also encourage to have a look at this survey or ranking algorithms
The main alternative to PageRank is HITS.
Another alternative to page rank is OPIC.

Algorithm to assign Exams to Rooms?

I have a problem that I have no idea what it is or how to solve it. I know there is a name for the problem (after it is known, the title could be changed to reflect it).
Its somewhat of getting a perfect fit for a particular list based on a passed formula. For eg.
I have 2 lists of objects. One list of rooms and one list of exams. For each exam, I loop through all available rooms, execute a formula (which returns a value from 0-1), 1 meaning its a good fit, and assign the highest one to the exam. I continue the loop over and over to find the best fit (which may lead to infinite loop).
I am trying to avoid using a genetic algorithm to solve this. Anyone got any idea what the name of the problem is and also a possible solution?
ps. Can an admin rename the title if I do not get the chance to?
This is the Assignment problem. Wikipedia will tell you more about how to solve it.

Search algorithm for a sorted double linked list

As a learning excercise, I've just had an attempt at implementing my own 'merge sort' algorithm. I did this on an std::list, which apparently already had the functions sort() and merge() built in. However, I'm planning on moving this over to a linked list of my own making, so the implementation is not particuarly important.
The problem lies with the fact that a std::list doesnt have facilities for accessing random nodes, only accessing the front/back and stepping through. I was originally planning on somehow performing a simple binary search through this list, and finding my answer in a few steps.
The fact that there are already built in functions in an std::list for performing these kinds of ordering leads me to believe that there is an equally easy way to access the list in the way I want.
Anyway, thanks for your help in advance!
The way a linked list works is that you step through the items in the list one at a time. By definition there is no way to access a "random" element in the list. The Sort method you refer to actually creates a brand new list by going through each node one at a time and placing items at the correct location.
You'll need to store the data differently if you want to access it randomly. Perhaps an array of the elements you're storing.
Further information on linked lists: http://en.wikipedia.org/wiki/Linked_list
A merge sort doesn't require access to random elements, only to elements from one end of the list.

Algorithm for a planning tool

I'm writing a small software application that needs to serve as a simple planning tool for a local school. The 'problem' it needs to solve is fairly basic. Namely, the teachers need to talk with the parents of all children. However, some children have, of course, brothers and sisters in different groups, so these talks need to be scheduled next to eachother, to avoid the situations were parents have a talk at 6 pm and another one at 10 pm. Thus in short, given a collection of n children, where some children have 1 or more brothers or sisters, generate a schedule where all the talks of these children are planned next to each other.
Now, maybe the problem can be solved extremely easy, but on the other I have a feeling this can be a pretty complicated problem, that needs and can be solved with some sort of algorithm. Elegantly. But am I right? Is there? I've looked at the Hungarian alorithm but it doesn't quite apply to this particular problem.
Edit: I forgot to mention, that all talks take the same amount of time.
Thanks!
I think it is quite easy.
First group the kids which belong together because they share parents. Schedule the children inside a group consecutively, schedule the rest as random.
Another way to abstract it and make the problem easier is to look from the parent perspective, see brothers and sister as "child" and give them more time. Then you can just schedule the parents at random, but some need more time (because they have multiple childeren).
One approach woul dbe to define the problem in a declarative constraint language and then let it solve the problem for you. The last time I did this, I used ECLiPSe, which is a nifty little language where you define your problem space by constraints, and then let it find allowable values that satisfy those constraints.
For example, I believe you have two classes of constraints:
A teacher may only have one
conference at a time
All students in the same family must
have consecutive slots
Once you define these in ECLiPSe, it will calculate values for each student that satisfy the requirements. If you go this way, you can also easily add constraints as you need to. For example, it's easy to say that a teach is unavailable for slot Y, or teachers must take turns doing administrative work, etc.
This sorts feels like a "backpack algorithm" type of problem. You need to group the family members together then fill slots appropriately.
If you google "backpack algorithm", you'll see enough write-ups to make your head spin and also some good coded solutions.
I think if each talk could be reduced to "activities" where each activity has a start time and an end time you could use the activity-selection algorithm studied in computer science. It is based on a greedy approach and could be solved in O(n) (where n is the number of activities). You could find more information here. I am sure you will need to have to do a pre-processing here to be able to reduce the brother/sister issue as activities of the same type.

Resources