How does Trie and B+ tree compare for indexing lexicographically sorted strings [on the order some billions]?
It should support range queries as well.
From perf. as well as implementation complexity point of view.
i have question about hoare partition method here is code
and also pseudo code please if something is wrong correct
pseudo code
HOARE-PARTITION ( A, p, r)
1 x ? A[ p]
2 i ? p-1
3 j ? r +1
4 while TRUE
5 do repeat j ? j - 1
6 until A[ j ] = x
7 do repeat i ? i + 1
8 until A[i] = x
9 if i < j
10 then exchange A[i] ? A[ j ]
11 else return j
and my code
public class Hoare {
public static int partition(int a[],int p,int r) {
int x=a[p];
int i=p-1;
int j=r+1;
while (true) {
do
{
j=j-1;
} while(a[j]>=x);
do
{
i=i+1;
} while(a[i]<=x);
if (i<j) {
int t=a[i];
a[i]=a[j];
a[j]=t;
} else {
return j;
}
}
}
public static void main(String[]args){
int a[]=new int[]{13,19,9,5,12,8,7,4,11,2,6,21};
partition(a,0,a.length-1);
}
}
and mistake is this
error: Class names, 'Hoare', are only accepted if annotation processing is explicitly requested
1 error
any ideas
i have posted this question
http://stackoverflow.com/questions/2874487/how-can-i-implement-this-python-snippet-in-java
i have compiled it now i need to use in main project
public static void main(String[]args){
}
?
can anybody show me example?
i have posted this question
http://stackoverflow.com/questions/2874487/how-can-i-implement-this-python-snippet-in-java
i have compiled it now i need to use in main project
public static void main(String[]args){
}
?
can anybody show me example?
i have posted this question
http://stackoverflow.com/questions/2874487/how-can-i-implement-this-python-snippet-in-java
i have compiled it now i need to use in main project
public static void main(String[]args){
}
?
can anybody show me example?
ia have meet following problem
suppose we have sorted array of size 2^k-1 where k is given number we should copy this array into heapsearch array b the elements in odd positions of a go in order into last half of the positions of b positions congruent to 2 modul0 4 go into b's secodn quarter and so on this is not homework and please nobody tag it as homework it is from programming pearls please any ideas
I have this array:
$array = array
(
array('1', '2', '3'),
array('!', '@'),
array('a', 'b', 'c', 'd'),
);
And I want to know all character combination of sub arrays.. for example :
1!a
1!b
1!c
1!d
1@a
1@b
1@c
1@d
2!a
2!b
2!c
2!d
2@a
2@b
...
Currently I am having this code :
for($i = 0; $i < count($array[0]); $i++)
{
for($j = 0; $j < count($array[1]); $j++)
{
for($k = 0; $k < count($array[2]); $k++)
{
echo $array[0][$i].$array[1][$j].$array[2][$k].'<br/>';
}
}
}
It works, but I think it is ugly, and when I am adding more arrays, I have to add more for. I am pretty sure there is a way to do this recursively, but I don't know how to start/how to do it. A little help could be nice!
Thanks you!
I have the following interface:
public interface MyFunctor {
int myFunction(int x);
}
And I created a class which implements this interface :
public class Myfunction1 implements MyFunctor {
}
But it show me the error :
implement all abstract method
Please help me.
hi i have question what is different between
public static void printMax( double... numbers) {
and
public static void printmax(double numbers[])
?
is is double...numbers the same as double numbers[]?
Hi,
i'm trying to develop Pentago-game in c#.
right now i'm having 2 players mode which working just fine.
the problem is, that i want One player mode (against computer), but unfortunately, all implements of minimax / negamax are for one step calculated.
butin Pentago, every player need to do two things (place marble, and rotate one of the inner-boards)
I didn't figure out how to implement both rotate part & placing the marble, and i would love someone to guide me with this.
if you're not familiar with the game, here's a link to the game.
if anyone want's, i can upload my code somewhere if that's relevant.
thank you very much in advance
Lets suppose you have a 1000x1000 grid of positive integer weights W.
We want to find the cell that minimizes the average weighted distance.to each cell.
The brute force way to do this would be to loop over each candidate cell and calculate the distance:
int best_x, best_y, best_dist;
for x0 = 1:1000,
for y0 = 1:1000,
int total_dist = 0;
for x1 = 1:1000,
for y1 = 1:1000,
total_dist += W[x1,y1] * sqrt((x0-x1)^2 + (y0-y1)^2);
if (total_dist < best_dist)
best_x = x0;
best_y = y0;
best_dist = total_dist;
This takes ~10^12 operations, which is too long.
Is there a way to do this in or near ~10^8 or so operations?
I need to study about load-balancers, such as Network Load Balancing, Linux Virtual Server, HAProxy,...There're somethings under-the-hood I need to know:
What algorithms/technologies are used in these load-balancers? Which is the most popular? most effective?
I expect that these algorithms/technologies will not be too complicated. Are there some resources written about them?
Thank you very much for your help.
I have a project with a requirement to get the BPM of a wave or MP3 file programmatically using .Net (VB.Net or C#).
Does anyone know of a binary or library for this or have a code snippet to steer me in the right direction?
I need make a merge sort using an additional array. Here is my code:
public class extra_storage{
public static void main(String[]args) {
int x[]=new int[]{12,9,4,99,120,1,3,10};
int a[]=new int[x.length];
mergesort(x,0,x.length-1,a);
for (int i=0;i<x.length;i++){
System.out.println(x[i]);
}
}
public static void mergesort(int x[],int low,int high, int a[]){
if (low>=high) {
return;
}
int middle=(low+high)/2;
mergesort(x,low,middle,a);
mergesort(x,middle+1,high,a);
int k;
int lo=low;
int h=high;
for (k=low;k<high;k++)
if ((lo<=middle ) && ((h>high)||(x[lo]<x[h]))){
a[k]=x[lo++];
}
else {
a[k]=x[h++];
}
for (k=low;k<=high;k++){
x[k]=a[k];
}
}
}
But something is wrong. When I run it the output is this:
1
0
3
0
4
0
9
0
What is the problem?
hi i have following question
task is this generate k distinct positive numbers less then n without duplication
my method is following
first
create array size of k where we should write these numbers
int a[]=new int[k];
//now i am going to cretae another array where i check if (at given number position is 1 then generate number again else put this number in a array and continue cycle
i put here a piece of code and explanations
int a[]=new int[k];
int t[]=new int[n+1];
Random r=new Random();
for (int i==0;i<t.length;i++){
t[i]=0;//initialize it to zero
}
int m=0;//initialize it also
for (int i=0;i<a.length;i++){
m=r.nextInt(n);//random element between 0 and n
if (t[m]==1){
//i have problem with this i want in case of duplication element occurs repeats this steps afain until there will be different number
else{
t[m]=1;
x[i]=m;
}
}
so i fill concret my problem
if t[m]==1 it means that this element occurs already so i want to generate new number but problem is that number of generated numbers will not be k beacuse if i==0 and occurs duplicate element and we write continue then it will switch at i==1 i need like goto for repeat step
or
for (int i=0;i<x.length;i++){
loop:
m=r.nextInt(n);
if ( x[m]==1){
continue loop;
}
else{
x[m]=1;
a[i]=m;
continue;//continue next step at i=1 and so on
}
}
i need this code in java
please help
I would like to know if there is something similar to PHP natsort function in python?
l = ['image1.jpg', 'image15.jpg', 'image12.jpg', 'iamge3.jpg']
l.sort()
gives:
['image1.jpg', 'image12.jpg', 'image15.jpg', 'iamge3.jpg']
but I would like to get:
['image1.jpg', 'iamge3.jpg', 'image12.jpg', 'image15.jpg']
How can I prove that if a balanced digraph is weakly connected, then it is also strongly connected? (balanced digraph means that for every node, it's indegree and outdegree is the same and weakly connected means the non-directed version of this graph is connected).
What I can think of so far is: if the graph is balanced, it means it is a union of directed cycles. So if I remove any cycle, it will stay balanced. Also each vertex in the cycle has one edge coming into it and one edge leading out of it..
Then I guess I need to use some contradiction or induction to prove that the graph is strongly connected.. That's where I confused.
Hi,
Are there any open source algorithms in c# that solve the problem of creating a difference between two text files?
It would be super cool if it had some way of highlighting what exact areas where changed in the text document also.
I was recently given this interview question and I'm curious what a good solution to it would be.
Say I'm given a 2d array where all the
numbers in the array are in increasing
order from left to right and top to
bottom.
What is the best way to search and
determine if a target number is in the
array?
Now, my first inclination is to utilize a binary search since my data is sorted. I can determine if a number is in a single row in O(log N) time. However, it is the 2 directions that throw me off.
Another solution I could use, if I could be sure the matrix is n x n, is to start at the middle. If the middle value is less than my target, then I can be sure it is in the left square portion of the matrix from the middle. I then move diagnally and check again, reducing the size of the square that the target could potentially be in until I have honed in on the target number.
Does anyone have any good ideas on solving this problem?
Example array:
Sorted left to right, top to bottom.
1 2 4 5 6
2 3 5 7 8
4 6 8 9 10
5 8 9 10 11
Given a list of (say) songs, what's the best way to determine their relative "popularity"?
My first thought is to use Google Trends. This list of songs:
Subterranean Homesick Blues
Empire State of Mind
California Gurls
produces the following Google Trends report: (to find out what's popular now, I restricted the report to the last 30 days)
Empire State of Mind is marginally more popular than California Gurls, and Subterranean Homesick Blues is far less popular than either.
So this works pretty well, but what happens when your list is 100 or 1000 songs long? Google Trends only allows you to compare 5 terms at once, so absent a huge round-robin, what's the right approach?
Another option is to just do a Google Search for each song and see which has the most results, but this doesn't really measure the same thing
i have write bellow at this link http://stackoverflow.com/questions/2896811/question-about-siftdown-operation-on-heap code above ritten is pseudo code and i am interested if according to pseudo code my program is correct?
I want to implement a code that loops inside an array that its size is set by the user that means that the size isn't constant.
for example:
A=[1,2,3,4,5]
then I want the output to be like this:
[1],[2],[3],[4],[5]
[1,2],[1,3],[1,4],[1,5]
[2,3],[2,4],[2,5]
[3,4],[3,5]
[4,5]
[1,2,3],[1,2,4],[1,2,5]
[1,3,4],[1,3,5]
and so on
[1,2,3,4],[1,2,3,5]
[2,3,4,5]
[1,2,3,4,5]
Can you help me implement this code?
This was one of the interview questions asked. How to find the length of a linked list that is having cycle in it. I know how to calculate whether a linked list has a cycle or not using Hare and Tortoise technique. I even know how to calculate the length by storing the addresses in a hashset.
But what I was not able to tell is how to calculate the length of the linked list without using a external space of O(n). Please help me. Thanks.
hi, first of all this is not homework!!
my question is from book: Algorithms in C++ third edition by robert sedgewick
question is: there is given array of size n by 2^n(two dimensional) and we should fill it by binary numbers with bits size exactly n or
for example n=5 so result will be
00001
00010
00011
00100
00101
00110
00111
and so on we should put this sequence of bits into arrays please help me