|
How can a find a minimum in right sub tree using recursion
|
|
|
|
|
I'm sorry ... what do you mean ...?
You should give an Example ...
modified 22-Mar-17 9:14am.
|
|
|
|
|
Just recursively trace down the left branches in the right sub tree. The left element is always lowest.
|
|
|
|
|
To begin, I have the set of K values S={v_1, ..., v_K}. I want to pick the smallest value, replace it with another value, and again pick the smallest -- do this K times. So, initially, my best set B is empty, and I want to perform :
Step 1. Find minimum of S. Say it has index n. B=[B, v_n] (i.e., append v_n to B)
Step 2. Update S by replacing v_n with another value (not important how that other value is computed).
Repeat Steps 1 and 2 till B has K values.
I believe a reasonable way to do this is to first construct a min-heap from the initial S (KlogK complexity), and then I can (take out the root + insert new element) for (K-1) times. Assuming taking out root and insertion both are logK complexity, total complexity would be KlogK + 2(K-1)log(K) = (3K-2)logK.
As a next step, once I have the set B, I want to compute some function f(b) for each b in B, and repeat the above procedure with the set {f(b)} instead of the set S. In other words, taking the set {f(b)} as S now, I would like to perform the above described procedure. Brute force way -- I could first use up (3K-2)logK units of time to find B, then compute the set {f(b)}, and then use another (3K-2)logK units of time on {f(b)}. But, it is quite apparent I can do better by pipelining. Essentially, as soon as I start getting entries of B, I can compute f(.) for the available entries, and do some of the sorting operations.
Can you suggest a good/optimal way for the overall problem ?
|
|
|
|
|
i need co-occurrence matrix algorithm in any language. plz share ur results with me.
|
|
|
|
|
|
If you google for it, you will find many examples. Try googling for co occurence matrix python to get started.
This space for rent
|
|
|
|
|
Pete O'Hanlon wrote: co occurence matrix python That's just the Nokia snake game.
|
|
|
|
|
That takes me back. The seconds I wasted on that game
This space for rent
|
|
|
|
|
My wife still has an old phone that she keeps powered up just for that.
|
|
|
|
|
can't able to fine exact code. its confusing
|
|
|
|
|
Part of the art of becoming a programmer is knowing how to search. Paste your search link in as a reply so I can see how you searched.
This space for rent
|
|
|
|
|
|
The search terms I used. Google[^]
This space for rent
|
|
|
|
|
|
thanks but i dont know how to run it. its not giving an error but dont know how to compile it. not giving any output
|
|
|
|
|
The links I found are just to point you to the information that may help you. It is up to you to work out how to use it and, if necessary, find out why it does not work.
|
|
|
|
|
We are not a free search service!
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
how rude ur ans
|
|
|
|
|
I don't think it was rude. He was trying to give you some genuine advice that will stand you in good stead in the years to come... as have the others that are suggesting that you actually need to put some of your own effort into this exercise.
|
|
|
|
|
In some cities, the sewage system does not work properly and every time it rains, water accumulates on the streets and in between buildings, blocking traffic and causing distress.
You have an N number of buildings and an array with the height of every building.
You want to find out what is the maximum volume of water that would hypothetically accumulate after heavy rain, in between 2 buildings.
Input: N > 0 on the first line, array of N integer elements on the second line.
Output: integer positive X units of water.
Example: The following sequence of heights will generate the structure below:
Sequence: 1 2 1 5 2 4 1 0 1 2 6 4 5 2 3 4 1 2
The biggest block of water would contain 20 units of water.
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace heavy_rain{
class Program{
static void Main(string[] args){
System.IO.StreamReader sr;
int n = 0, i = 0, result = int.MaxValue;
int[] buildingHeights = null;
try {
sr = new System.IO.StreamReader(args[0]);
String[] lines = new String[2];
String line = null;
while ((line = sr.ReadLine()) != null) {
lines[i++] = line;
}
n = int.Parse(lines[0]);
buildingHeights = new int[n];
String[] heights = lines[1].Split(' ');
for(int j = 0; j < heights.Length; j++) {
buildingHeights[j] = int.Parse(heights[j]);
}
Console.WriteLine(result);
}
catch (Exception e) {
System.Diagnostics.Trace.WriteLine(e.Message);
}
}
}
}
|
|
|
|
|
I don't think you'll find anyone here to do your homework for you. You'll have to do it yourself. But if you get stuck and have a specific question, come back and ask.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Member 13003743 wrote: The biggest block of water would contain 20 units of water. That does not make much sense. Ask your professor what is the connection is between height of building and amount of water.
|
|
|
|
|
Always assume that your teacher is reading this site, and will notice your attempt to cheat on your homework.
Expecting other people to do your work for you will not end well. How do you think that would go down in the real world, when you've got a real job and a mortgage to pay?
If you don't know how to start, then talk to your teacher.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Your main effort was to copy your assignment.
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|