Neil Forrest

Greenhorn
+ Follow
since Apr 03, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Neil Forrest

Hey all,
Can anyone direct me to a good tutorial on BER encoding? I'm having to encode {weight, 276} {lastname, "Harrison"} for an assignment and I can't find anything that actually shows me how to do this.

Thanks,
Neil
Hi,
Can anyone steer me to easy to follow information on doing checksums and in particular with UDP?
Thanks,
Neil
Thanks, I figured out most of it but I've got another question. When I telnet in with port 80 then CRLF I get a black screen and anything I type in doesn't show up, only a cursor moves with the keystrokes. It's really annoying not knowing if I've made a mistake. Is this what is suppose to happen?

Neil
Hi all,
So I'm taking this course about the Internet, and I'm suppose to telnet into a web server, type in a one line request message for some object on the server to see a HTTP response message. First off this book assumes I know how to telnet into a web server, wrong! Can anyone explain in simple language what I have to do?

Thanks,
Neil
Awesome, thanks soooo much.
Neil
18 years ago
Hi,
I'm stumped. My isValid()method ensures that a fileName is in the proper format when inputted into a textfield. Below are the criteria for an acceptable input. How do I code that fileName can only contain exactly one period, "."?

private boolean isValid(String fileName) {
if (!fileName.endsWith(".bst")) {
newsF.setText("Filename is not valid--must end with .bst");
return false;
} else if (!Character.isLetter(fileName.charAt(0))) {
//blah blah
} else if...WHAT HERE...
newsF.setText("The text in the BST FILE field is not a valid--must not contain more than one period");
return false;
}else
return true;
}

It's probably simple but I can't figure it out...
Thanks,
Neil
18 years ago
Thanks to both of you...great resources!
Neil
18 years ago
Hi,
I'm working on an assignment that asks for me to do specific documentation on some methods that I've had to code. It sounds like I have to describe in detail what each of the methods do, but I'm not clear on to what length I should go and if there is any specific format. Does anyone know of some simple examples of java documentation that I might look at to get an idea?
Thanks,
Neil
18 years ago
Hi,
Can anyone spot the logic bug in my code? It's a binary search program. I'm timing the search times for different inputs. It works up until the input is n=10^6 on the command line. Then it just keeps running. The longest I've let it go is over 12 hours. What I don't get is that for lesser n values, it's really fast. Memory is not the problem...

public class Binary{
//** declarations of variables
int[] list,list_search;
int size,count;
long time1;
long time2;

//** constructor
public Binary(int n, int k){
size=n;
count=k;
int i;
list=new int[size];
list_search=new int[count];
time1 = 0;
time2 = 0;

//** generate the list of elements
for(i=0;i<size;i++){
list[i]=1+(int)(n*Math.random());
}
for(i=0;i<count;i++)
list_search[i]=1+(int)(n*Math.random());
//sort the list
sort();
//search the element
startsearch();
}

//** sort the list before binary search... done in ascending order
public void sort(){
int i,j,temp;
for(i=0;i<size;i++){
for(j=i;j<size;j++){
if(list[i]>list[j]){
temp=list[i];
list[i]=list[j];
list[j]=temp;
}
}
}
}

//** method for binary search
public void binary(int key){
int low=0;
int high=size-1;
int middle;

while(low<high){
middle=(low+high)/2;
if(key==list[middle])
break;
else if(key<list[middle])
high=middle-1;
else if(key>list[middle])
low=middle+1;

}


}

public void startsearch(){
int i;
time1 = System.currentTimeMillis();
for(i=0;i<count;i++){
binary(list_search[i]);
time2 = System.currentTimeMillis();
}

System.out.println("Search Time: "+ (time2 - time1) +" ms");

}

//** main function
public static void main(String args[]){
int n,k;
if(args.length!=2){
System.out.println("Required number of arguments are not provided");
}
else{
n=Integer.parseInt(args[0]);//parsing the size for number of elements in the list
k=Integer.parseInt(args[1]);// parsing the size of number of elements to be searched
Binary ss =new Binary(n,k);//object created to compare the two search

}
}
}
18 years ago
Hi,
My code compiles, and the searches work but the timings won't work, I purposely entered commands that would take extended times, but I still get outputs of 0ms. Obviously I've coded this part wrong but I can't seem to spot where I've gone wrong. I've attached where I think the problem lies. Can anyone see where I've messed up?

//** method for sequential search
public void sequential(int key){
int i;
time1 = System.currentTimeMillis();
for(i=0;i<size;i++){
countSequential++;
if(key==list[i])
break;
}
time2 = System.currentTimeMillis();
}


//** method for binary search
public void binary(int key){
int low=0;
int high=size-1;
int middle;
time3 = System.currentTimeMillis();
while(low<=high){
middle=(low+high)/2;
countBinary++;
if(key==list[middle])
break;
else if(key<list[middle])
high=middle-1;///search low end of the list
else
low=middle+1;///search higher end of the list
}
time4 = System.currentTimeMillis();
}

public void startsearch(){
int i;
for(i=0;i<count;i++){//searching each element once sequentially and then binary in the same list
sequential(list_search[i]);
binary(list_search[i]);
}
System.out.println("The number of comparisions done per element search:");
System.out.println("Sequential: "+countSequential/count);
System.out.println("Search Time: "+(time2 - time1));
System.out.println("Binary: "+countBinary/count);
System.out.println("Search Time: "+ (time4 - time3));
}

Thanks,
Neil
18 years ago
Hi,
I'm wondering if anyone can suggest an "Algorithm Analysis and Data Structures for Java" book that I can use to supplement my text? I've read another entry in this forum and Rob Lafores' book was suggested. Any others come to mind?

Neil
18 years ago
Hi,
Hope you can help...my program below compiles but it's not performing as I'd like. The idea is that once the two arguments are entered on the command line: array size(n) where the max size is 10^6 and number of searches(k);the program generates a random search value. What should happen is that based on the two arguments, the search value is either found or not and the search time is captured in ms. First off I'm not sure how to incorporate the random value component into the code, and second, no matter what I input as arguments, I get a search time of 0ms.

Any hints?

Thanks,
Neil

//SequentialSearch.java

import java.io.*;
import javax.swing.*;


public class SequentialSearch
{
private long time1; // start time
private long time2; // end time

public SequentialSearch()
{
time1 = 0;
time2 = 0;
}

public int sequentialSearch(int[] list, int k)
{
boolean found = false;
int i, searches = 0;
time1 = System.currentTimeMillis(); // set start time

// search list
for(i = 0; i < list.length; i++)
{
searches++;
if( k == list[i]) // if true, key is found
{
found = true;
break;
}
}

time2 = System.currentTimeMillis(); // set end time

if ( found == true )
{
System.out.println("Search Value: " + k +
"\nValue Found: Yes" +
"\nSearch Comparisons: " + searches +
"\nList Size: " + list.length +
"\nSearch Time: " + (time2-time1));
}
else
System.out.println("Search Value: " + k +
"\nValue Found: No" +
"\nSearch Comparisons: " + searches +
"\nList Size: " + list.length +
"\nSearch Time: " + (time2-time1));
return 0;
}

public static void main (String[] args) throws IllegalArgumentException
{

SequentialSearch s = new SequentialSearch(); // create reference to SequentialSearch class
Assert.notFalse(args.length == 2, "Usage: SequentialSearch <size> <searches>");
int n = Integer.parseInt(args[0]); // number of array elements
int k = Integer.parseInt(args [1]); // search target key
int [] list = new int[n]; // create list array of n size

System.out.println("Argument 1 = " + args[0] + "\nArgument 2 = " + args[1] + "\n\n");

for(int i = 0; i < list.length; i++)
list[i] = i + 1;

s.sequentialSearch(list, k); // invoke search method
}

}
18 years ago
Hi,
I'm new to Java. My mission is to implement a sequential search and time the performance with an array size=10^i, i=1,2,3,4,5,6. The command line has to take 2 arguments: size and number of searches. My code is below. Any suggestions in making this mess actually work?
Thanks...



[added code tags - Ilja]
[ April 04, 2005: Message edited by: Ilja Preuss ]
18 years ago