473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

searching algorithm

I need a little help with an algorithm. Let's say I have an array with 15
items. I want to find "Fern" where there are "Able", "Me Also",
"Zimmerman", etc in no particular order. Forget about the fact that it's an
array - I know how to search an array. I just want an algorithm that will
do the following:

1. search the first 1/2 - say 8 items. If the value is less than what I'm
seeking, the algorithm needs to return 'search 1 - 8 only'; else 'search 9
through 15'. I want to continue, searching 1 - 4 now, then 5 - 8 (supposing
it's < the value I seek), etc. until I lock in on the item I need or at
least the closest group.

Tx for any help you can offer.

Bernie Yaeger
Nov 20 '05 #1
6 2262
Bernie,

This algorithm you suggest is a simple binary search,
however, it requires the array to be sorted.

There are many references for binary search, try
google.

Generally, the algoritm divides the current group
in half and probes at that point. The current group
initially is the entire file.

The algorithm continues until
1) entry found
2) entry can not exist in the array

There is a subtle difference about entry not existing,
the key is to never look at the same element two times
in succession.

I repeat, emphatically, your suggested algorithm ONLY
works with a sorted array.

Pat

-----Original Message-----
I need a little help with an algorithm. Let's say I have an array with 15items. I want to find "Fern" where there are "Able", "Me Also","Zimmerman", etc in no particular order. Forget about the fact that it's anarray - I know how to search an array. I just want an algorithm that willdo the following:

1. search the first 1/2 - say 8 items. If the value is less than what I'mseeking, the algorithm needs to return 'search 1 - 8 only'; else 'search 9through 15'. I want to continue, searching 1 - 4 now, then 5 - 8 (supposingit's < the value I seek), etc. until I lock in on the item I need or atleast the closest group.

Tx for any help you can offer.

Bernie Yaeger
.

Nov 20 '05 #2
Pat,

Yes, of course you are correct. My reference to no particular order is
incorrect. That was intrisic in the pattern I laid out.

I'll look on google, as you recommend. Tx for your help

Bernie
"Patrick Ireland" <ir*****@airmail.net> wrote in message
news:06****************************@phx.gbl...
Bernie,

This algorithm you suggest is a simple binary search,
however, it requires the array to be sorted.

There are many references for binary search, try
google.

Generally, the algoritm divides the current group
in half and probes at that point. The current group
initially is the entire file.

The algorithm continues until
1) entry found
2) entry can not exist in the array

There is a subtle difference about entry not existing,
the key is to never look at the same element two times
in succession.

I repeat, emphatically, your suggested algorithm ONLY
works with a sorted array.

Pat

-----Original Message-----
I need a little help with an algorithm. Let's say I

have an array with 15
items. I want to find "Fern" where there

are "Able", "Me Also",
"Zimmerman", etc in no particular order. Forget about

the fact that it's an
array - I know how to search an array. I just want an

algorithm that will
do the following:

1. search the first 1/2 - say 8 items. If the value is

less than what I'm
seeking, the algorithm needs to return 'search 1 - 8

only'; else 'search 9
through 15'. I want to continue, searching 1 - 4 now,

then 5 - 8 (supposing
it's < the value I seek), etc. until I lock in on the

item I need or at
least the closest group.

Tx for any help you can offer.

Bernie Yaeger
.

Nov 20 '05 #3
Hi Bernie,

Are you interested in the Binary Search for it's own sake or are you
interested in looking up values quickly? I only ask because BinarySearch is a
method of both Arrays and ArrayLists.

Regards,
Fergus
Nov 20 '05 #4
That's the right question, Fergus. The answer is 'for its own sake' - I
want to understand how to develop such an algorithm; I'm aware of the
existing methods and their use.

Tx

Bernie
"Fergus Cooney" <fi****@post.com> wrote in message
news:O8*************@TK2MSFTNGP12.phx.gbl...
Hi Bernie,

Are you interested in the Binary Search for it's own sake or are you
interested in looking up values quickly? I only ask because BinarySearch is a method of both Arrays and ArrayLists.

Regards,
Fergus

Nov 20 '05 #5
"Bernie Yaeger" <be*****@cherwellinc.com> wrote...
That's the right question, Fergus. The answer is 'for its own sake' - I
want to understand how to develop such an algorithm; I'm aware of the
existing methods and their use.


Bernie: I'm glad to hear this. I have an example on my website
http://www.leylan.com/

You have to navigate to the Clipper / Look Towards the Past article. If you
read it you will see that I was explaining to Clipper developers in 1995 how
they could translate code written in other languages in order to get
solutions they needed. I found a binary sort algorithm written in Pascal
and I present the Pascal and the translated Clipper code. You could easily
translate either one into VB.

If you want a kick, consider translating the Z-80 assembly language example
I listed for creating an LED display.
Nov 20 '05 #6
Hi Tom,

Tx - I'm going to take a look at your site right now.

Bernie
"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:ce********************@twister.nyc.rr.com...
"Bernie Yaeger" <be*****@cherwellinc.com> wrote...
That's the right question, Fergus. The answer is 'for its own sake' - I
want to understand how to develop such an algorithm; I'm aware of the
existing methods and their use.
Bernie: I'm glad to hear this. I have an example on my website
http://www.leylan.com/

You have to navigate to the Clipper / Look Towards the Past article. If

you read it you will see that I was explaining to Clipper developers in 1995 how they could translate code written in other languages in order to get
solutions they needed. I found a binary sort algorithm written in Pascal
and I present the Pascal and the translated Clipper code. You could easily translate either one into VB.

If you want a kick, consider translating the Z-80 assembly language example I listed for creating an LED display.

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Richard Berg | last post by:
Hello, I need to search a byte array for a sequence of bytes. The sequence may include wildcards. For example if the array contains 0xAA, 0xBB, 0xAA, OxDD then I want to be able to search for...
2
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
1
by: Pacher R. Dragos | last post by:
I have recently developed an application in c witch acts like a system logger for windows 2003 server domain controllers and my problem is that of the size. In a normal day my program produces...
1
by: New Devil | last post by:
How can i implement searching in knowledge base.What is the simplest algorithm for searching in knowledge base.and how can i implement it in C#? Posted Via Usenet.com Premium Usenet Newsgroup...
8
by: Gordon Knote | last post by:
Hi can anyone tell me what's the best way to search in binary content? Best if someone could post or link me to some source code (in C/C++). The search should be as fast as possible and it would...
8
by: sandeep | last post by:
Our team is developing proxy server(in VC++)which can handle 5000 clients. I have to implement cache part so when ever a new request com from client I have to check the request URL content is in...
4
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given...
15
by: Gigs_ | last post by:
Hi all! I have text file (english-croatian dictionary) with words in it in alphabetical order. This file contains 179999 words in this format: english word: croatian word I want to make...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.