Divide And Conquer Algorithm Implementation

Oct 18, 2014

I was given an algorithm to implement and i did it in java. its some divide and conquer algorithm probably some comparison sort..heres the code i wrote...

import java.util.*;//so as to get the functions for using arrays
public class main
{
public static void main(String[] args)
{
int m[]={10,2,3,4,5,6,7,8,9,1};
int result[]=new int[200];

[Code] ....

the program compiles without errors. but while running i get the following errors:

java.lang.ArrayIndexOutOfBoundsException: 10
at main.abc(main.java:28)
at main.main(main.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)

View Replies


ADVERTISEMENT

Divide And Conquer

Oct 28, 2014

I believe i need Divide and Conquer method, maybe im wong..

I have to solve this:
x2+s(x)+200·x=N

N is given by the user, also A and B, which is the range of X.
but the range can be up to 1,000,000,000

View Replies View Related

Dijkstra Algorithm Implementation Does Not Work Properly

Jan 5, 2015

I have to implement Dijkstra algorithm in Java.

Input file looks like this:

3
5
1 5 1
4 5 3
3 4 5
4 3 7
1 6 9
2 5 12
2 6 3
5 4 4

First and second numbers are in order source and destination points.

First and second numbers in another each line represent edges. Third one is wage of each edge.

My code looks as follows:

import java.util.*;
import java.io.*;
class Vertex implements Comparable<Vertex>
{
public int name = 0;
public ArrayList<Edge> adjacencies = new ArrayList<Edge>();
public double minDistance = Double.POSITIVE_INFINITY;
public Vertex previous;

[Code] .....

View Replies View Related

Not Getting Divide By Zero Error

Dec 31, 2014

here is code :

public final static void main(String[] args){
double d = 10.0 / -0;
if(d == Double.POSITIVE_INFINITY)
System.out.println("Positive infinity");
else
System.out.println("Negative infinity");
}

now ideally this might throw Arithmetic Exception.. but it prints positive infinity ,.. why.. ??

View Replies View Related

How To Divide More Than Two Numbers Using ArrayList

Jun 11, 2014

I made a calculator that does the basic operations but I want to be able to divide more than two numbers by repeatedly entering values using an arraylist and I keep getting the indexoutofboundsexception and I don't know why? I understand the reason behind the outofboundsexception but I can't figure out why in this case. Here is a snippet:

public Double division(ArrayList<Double> list){
Double dnum = 0.0;
Double divide = numList.get(0); // Initialize divide to first element in the arraylist
for(int i=0; i < numList.size(); i++){

[Code] ....

View Replies View Related

Add / Subtract / Multiply And Divide To Get Irrational Number

May 12, 2014

public static void main (String [] args) {
int a = (int) 0.25;
int b = (int) 1.25;
int result = a + b;
System.out.println("Result of addition is "+ result);
}
}

View Replies View Related

Divide Array In Two Parts - Equal To Sum Of Elements

Dec 1, 2014

Divide an Array in two Parts in such a way so that sum will be equal while we add all the elements of array.

View Replies View Related

I/O / Streams :: Divide A Text File Into Blocks Of 128 Bits

Feb 7, 2006

I have to divide a text file into blocks of 128 bits. I think i must use the ByteArrayInputStream and ByteArrayOutputStream classes. is there any website showing how to user these two ByteArrayInputStream and ByteArrayOutputStream classes in detail. or it would be much better if you could show me a portion of the code.

View Replies View Related

Swing/AWT/SWT :: Java2D Graph Plotting - Divide X And Y Axis With Frequencies

May 29, 2014

I am using Java 2D API to implement Graph plotting. I am able to transform and scale the origin upright.

Now, I need to divide the x & y axes with frequencies (Ex: On Y-axis: 0 10 20 30 40 etc ..) and then plot points (Ex: [34, 54] etc) accordingly.

Which methods to use or way out to make this implementation?

View Replies View Related

JSP :: Check Box Implementation

Sep 30, 2014

1. In jsp 1 , i have 3 checkboxes(chkbox1,chkbox2,chkbox3) , if i select check boxes (chkbox1, chkbox2), and click on submit, corresponding two text fields (chkbox1,chkbox2) will have to appear in the next jsp i.e., jsp 2.

2. In jsp 1 , i have 3 checkboxes(chkbox1,chkbox2,chkbox3) , if i select check boxes (chkbox2, chkbox3), and click on submit, corresponding two text fields(chkbox2,chkbox3) will have to appear in the next jsp i.e., jsp 2.

Like this, which ever checkbox i select, corresponding text fields should appear in the subsequent jsp.

View Replies View Related

HashCode And Equals Implementation

May 15, 2014

Its that very old question regarding hashcode and equals implementation which i am not getting .

import java.util.*;

public class MyElement {
public static void main(String a[]){

HashSet<Price> lhm = new HashSet<Price>();
lhm.add(new Price("Banana", 20));
lhm.add(new Price("Apple", 40));

[Code] .....

In the above program even if i comment out the Hashcode method , i believe it is still taking the memory address values from the native hashcode method of Object class. but the equals override implentation says that i have two insertions which are same . So as per my logic it should not allow the duplicate element to enter.but its not so ...the duplicate element is well inserted without hashcode .

View Replies View Related

Grid Layout Implementation

Mar 13, 2014

How to implement GridLayout. In my applet, I want to make a grid of 2 rows and 2 columns. In each grid I want to add a Label and a TextField. I want the background to be red.

So my code would be?

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class GridLayoutApplet extends Applet implements ActionListener{
// construct components
Label fNameLabel = new Label("First Name");
TextField fNameField = new TextField(20);

[Code] .....

I have read about panels and frames but, it is all confusing to me. How can you add a label and a TextField to one square of the grid?

View Replies View Related

FFT Convolution Implementation In Java

Dec 26, 2014

Not necessarily Java related, more a general programming issue I have come a long and I am currently using java to mock up a project that will eventually get moved over to C++.

I am trying to implement FFT Convolution into a java project and have things partially working, I do not know if it is a coding issue, logic issue or if I simply know nothing of FFT and convolution.

For starters I got an FFT library that I do have working, if I create a small array pass it into the forward FFT, do a little bit of bit manipulation (converting a complex array of size n*2 into a re[] and im[] of size n), run the inverse FFT and do the same bit manipulation again I get back where I started.

However if I take two arrays, a Dirac Delta function (an array with a 1 followed by zeros for the rest of the array) and a stepping kernel (ex. {1, 2, 3, 4 etc}), I would expect to get the forward FFT of both arrays, bit manipulation, multiply them together, Inverse FFT, and bit manipulate again and the result would be the kernel. I have not had such luck.

This is the gist of the program:

// bit manipulation, converts complex array to two re and im arrays
public void bitTwiddle(double [] real, double [] real2, double [] imaginary){

double [] realCopy = new double [] {0, 0, 0, 0, 0, 0, 0, 0};
double [] imaginaryCopy = new double [] {0, 0, 0, 0, 0, 0, 0, 0};

for (int idx = 0; idx < (N * 2); idx++){
realCopy[idx] = real [idx];

[Code] ....

This is the result:

Quote
=====================================================================
Dirac Delta In Time Domain:
Real:1.000.000.000.00
Imag:0.000.000.000.00
=====================================================================
Dirac Delta Frequency Domain
Real:0.500.500.500.50
Imag:0.000.000.000.00
=====================================================================
Kernel In Time Domain
Real:1.002.003.004.00
Imag:0.000.000.000.00
=====================================================================
Kernel In Frequency Domain
Real:5.00-1.00-1.00-1.00
Imag:0.00-1.000.001.00
=====================================================================
Result: Dirac Delta x Kernel
Real:2.50-0.50-0.50-0.50
Imag:0.00-0.000.000.00
=====================================================================
Result In Time Domain
Real:0.501.501.501.50
Imag:0.000.000.00-0.00

View Replies View Related

Comparator Interface Implementation?

Mar 6, 2014

Something about implementing Comparator interface isn't very clear to me: overriding the compare method.

Like here for example:

//This sorts a list of objects holding information based on age: the name and the age of the person
 
public class Person {
String name;
int age;
public Person (String name, int age)
{
this.name = name;
this.age = age;

[Code] ....

What exactly is happening behind the scenes? I don't understand mostly the part where it returns a 0, a 1, or a -1. After it returns one of those values, what really happens next?

For the displaying of the list, is the method toString() being accessed to output the list in the System.out.println statement?

For the generics, why do we use Person?

View Replies View Related

Why Class Implementation Is Not Possible In Java

May 14, 2014

Why Class implementation is not possible in java....

View Replies View Related

Abstract Method With No Implementation

Mar 6, 2014

An abstract method is a method with no implementation. So would like to know what is the purpose of calling it if there is no implementation?

View Replies View Related

Implementation Of Immutable Queue

Nov 12, 2014

The following codes shows an implementation of an enqueue function of a FIFO immutable queue, and the output result shows the String "c".

I don't understand why since I expected it should be null.

The head and the tail of an ImmutableQueue Object are two separate queue, and each time I call the enqueue function, it just return a new object with a new tail, however, the head is not modified except the first two times I call the function.

Therefore, I expected head.next.next should be a null element, but the result is not like that.

public class ImmutableQueue<E> {
private int size =0;
public Queue<E> head;
public Queue<E> tail;
public ImmutableQueue(){}
private ImmutableQueue(Queue<E> hd, Queue<E> tl){
head=hd;
tail=tl;

[Code] ....

View Replies View Related

Decision Table Implementation In Java?

Jan 8, 2015

how to start with decision table implementation in java

View Replies View Related

Object Locking Mechanism Implementation?

Jul 21, 2014

I want to implement new locking mechanism similar to like how threads locking or synchronized does the operation. Any inputs to implement out own locking mechanism ?

View Replies View Related

Priority Queue Implementation Using Heap / BST

Dec 4, 2014

I am in the process of implementing Priority queue, as I understand that there are many data structures you could use to implement. I implemented it with the an array, which it works absolutely fine. However I have limitations on what collections I can use from the collections classes. I fact I cant use any of the collections classes. Meaning I cant use array.

I’m trying to implement Priority Queue using heap. And implementing heap using binary trees. But however I have a few questions which I need to clarify and I cant think of any other way of resolving it. Ofcourse I can implement my own simple array class using linked list.

Inserting into heap would be quite simple, as I just need to find the right last position from left to right leaf to insert the node into the tree. However after inserting, you may want to make sure that leaf node values are > than root node. Therefore, the root node will always be with the highest priority.

I call these steps where you compare from top down as bubbledown and bubbleup. To do this I really need a for each node within the treee node to have attribute pointing to its root node. So in case of bubbleup I always have a pointer for a given node to its root, without it would mean I would to traverse through the entire tree to identify its root. Which I believe is very inefficient.

Or have I taken this completely wrong? Or is it the case that heap are only best with arrays and therefore use array (by implement it using linked list?)

View Replies View Related

Implementation Of Login Page With Java

Mar 25, 2014

Code for login page by java and how we can implement it.

View Replies View Related

To Obtain Explanation On Singleton Implementation

Jan 11, 2014

I've found following code for Singleton Implementation from this forum, I am having a difficulty of understanding following,

1. When Singleton instance will be created, ( From which call ) ?

2. What feature of Static Inner class allow object to be singleton ?

3. How Inner Class implementation is thread safe ?

4. What will happen if variable "instance" mark as non-static, Will it still grantee singleton implementation ?

Java Code:

public class Singleton {
// Note private constructor
private Singleton() {}
private static class SingletonInner {
private final static Singleton instance = new Singleton();
}
public static Singleton getInstance() {
return SingletonInner.instance;
}
} mh_sh_highlight_all('java');

View Replies View Related

File Transfer Protocol Implementation

Mar 19, 2013

I have to write a code for File Transfer Protocol! It says that I only need to write code for client, but it also says that I have to run the program and send some files to server. I guess than I also need server side as well. I have to write my own classes, I cannot import some existing classes. I have to connect to the server with password and username and after that send some files to the server. I don't know anything about FTP. Can i maybe do this by Sockets and ports? I worked something with that.

View Replies View Related

Implementation Of Stack Methods In Java

Jun 3, 2014

I have to implement all the stack methods in java such as push, pop empty, not using the ready methods but have to create them and to execute an exercise but is sth wrong with it

public class Stiva {
/** the problem is here how to declare the stack 1 and stack 2 and kreu(head) gjmax(size)*/
int Gjmax;
int array[] = new int[Gjmax];
int kreu;
private Stiva stiva1;
private Stiva stiva2;

[Code] .....

View Replies View Related

FIFO - Implementation Of Immutable Queue

Nov 12, 2014

The following codes shows an implementation of an enqueue function of a FIFO immutable queue, and the output result shows the String "c". I don't understand why since I expected it should be null.

The head and the tail of an ImmutableQueue Object are two separate queue, and each time I call the enqueue function, it just return a new object with a new tail, however, the head is not modified except the first two times I call the function.

Therefore, I expected head.next.next should be a null element, but the result is not like that.

public class ImmutableQueue<E> {
public Queue<E> head;
public Queue<E> tail;
public ImmutableQueue(){}
private ImmutableQueue(Queue<E> hd, Queue<E> tl){
head=hd;
tail=tl;

[Code] ......

View Replies View Related

Implementation Of All Stack Methods In Java

Jun 3, 2014

I have to implement all the stack methods in java such as push, pop empty, not using the ready methods but have to create them and to execute an exercise but something wrong with it....

public class Stiva {
/** the problem is here how to declare the stack 1 and stack 2 and kreu(head) gjmax(size)*/
int Gjmax;
int array[] = new int[Gjmax];
int kreu;
private Stiva stiva1;
private Stiva stiva2;

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved