Java recursively exercise [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm in need of some guidance on the following exercise.
I have a custom list in which it has cities, each city knows to which city it connects this is the route, the route has a time which it take you to get between cities. What im asked to do is: given a city and sometime X:
public IList citiesWithRange(City c, int timeMinutes);
I should return to all the cities I can reach within that time frame. IList is a list made by me. Any help would be appreciated.
Thanks.

What you need is an implementation of an algorithm which returns the paths between nodes in a graph.
Take a look at Dijkstra's algorithm here:
https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
This can be helpful too:
https://www.ics.uci.edu/~eppstein/161/960208.html

You can attempt to solve this problem with a few easier steps in your recursive function
This function should be called on the starting city and be given a stack to add valid cities too, as well as an amount of time
Exit if time remaining is negative
Log current city to a stack
Loop through all connecting cities, calling the recursive function on each of them with the stack and time remaining minus travel time
At the end of this, the stack will contain all valid cities and may have duplicates
Remove the duplicates and you have all of the possible cities you can travel to

Related

huffman tree without using priority queues [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
for my project i have to create a huffman tree project, but my lecturer has said that i cannot use priority queues to build it?
But i dunno how to implement that.
Are there any other ways i can create a huffman tree without using priority queues?
This is an example of a huffman tree but it is using priority queues
enter image description here
enter image description here
There's a trick that is often used to build Huffman trees in practice:
Create a list of your symbols with probabilities, and sort it in ascending order
Create an initially empty list for combined symbols. This will remain sorted as we work.
While there is more than one symbol in the lists:
Remove the two smallest symbols from the beginnings of two lists
Combine them and add them to the end of the combined list. Because the new symbol has a higher combined probability than any combined symbol created before, this list remains sorted.
After the initial sorting, the smallest probability symbol will always be the first one of one of the two lists, so no priority queues or searching is required to find it.
This technique is quite clever, and your lecturer would not expect you to think of it yourself, so it was probably taught or referenced in class.

Java - Recursively Permute List Without For Loops [closed]

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 7 years ago.
Improve this question
I want to create a different way of permuting a list like [apple, banana, orange] without using for loops recursively that will work for any size list and input etc. I already created one with using for loops, but I can't figure out myself without using for loops to solve the problem as this second part of solving a permutation without a for loops recursively is also going to be a question on our next exam (study guide I am reading) any idea how I would tackle this so I can see and understand how it works for the next exam question?
You can emulate a loop by the following recursion:
do nothing for the empty list
otherwise
work on the first element
recurse, using the sublist that starts with the second element

LSH implementation for finding clusters [closed]

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
Hie guys.
I am very new to stack exchange and I am currently doing a research on graph theory.
The set of questions I'm going to ask are very introductory since I'm a beginner level programmer (not acquainted with hashing, buckets, vectors etc data structure wise).
My idea is to take in a dataset of the form (timestamp t, node i, node j) which says that there is an edge between i and j at time t. The idea is to search the neighborhood set of each nodes and hash them. If their "vectors" (I don't understand what that is) hash into the same bucket - they are candidates for cluster formation.
But he problem is I want to do experiments and try to run it. But have no idea how do I implement a hash function, and then bucket them together.
I'm not saying help me out with the code. But a pointer (pseudo code) would be very helpful. Like telling me to initialize a hash table etc etc
A hash code is an integer which is calculated from the properties of whatever it is you want to hash. That number is then used as an index into an array.
In this case it seems that you want to use the N dimensions of your vector to calculate this hash code. It's up to you to write a function that calculates that hash codes in a way that vectors that should be clustered all get the same hash code.
Language specific details about hash tables in Java or Python is very easy to find with a web search.

Recursive Division Random Maze Generation [closed]

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 9 years ago.
Improve this question
I'm currently doing a project where I want to randomly generate mazes for a game. After studying performance levels etc for maze generation I've decided to use the Recursive Division method. Whilst the explanation of the algorithm is somewhat understandable I'm struggling to formulate the algorithm in a pseudo format so that I can understand it fully and begin coding it. Can someone help me with a detailed explanation of the process or some pseudo-code? All help is greatly appreciated.
EDIT: From what I understand I will need to decide whether to divide horizontally or vertically. How is this decision made and what is the process of this division with regards to starting point and finishing point?
Begin with an empty field.
Bisect the field with a wall, either horizontally or vertically. Add a single passage through the wall.
Repeat step #2 with the areas on either side of the wall.
Continue, recursively, until the maze reaches the desired resolution.
Jamis Buck on Maze Generation: Recursive Backtracking

Mapping algorithm of subjects [closed]

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 9 years ago.
Improve this question
I am trying to make a system that assesses students' exams to learn their weaknesses. The exam consists of all subjects on their syllabus.
How do I --
Measure the skill of a student based on his/her score on the exam
Extract from the exam the topics on which the student performed poorly
My question is what algorithm should I use to map the syllabus based on the incorrect answers. Please help me. I'm new to this.
Update:
The input would be their exam with their answer and the output would be their knowledge level and suggestion of which topic should they study more
If you need more information please ask, i really need to know what algorithm should i use.
A simple system consists of tagging each question with one or more topics, then tallying the correct answers, sort by percentage, and output e.g. You got 3/8 (38%) of StackOverflow questions right
I notice you haven't tagged a specific language, so I'll outline the way I would do it in Python.
Could you not have a dict (this is composed of a a key - this could be the subject, and a corresponding value - this could be the exam result).
You could then sort the dict by values, in order from high to low. The best subjects would be at the top and the worst at the bottom.
If you're not using Python, you could use the Map type from C++ instead.

Categories