473,799 Members | 3,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2278
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*****@airmai l.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.co m> wrote in message
news:O8******** *****@TK2MSFTNG P12.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*****@cherwe llinc.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*@iamtiredof spam.com> wrote in message
news:ce******** ************@tw ister.nyc.rr.co m...
"Bernie Yaeger" <be*****@cherwe llinc.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
4410
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 0xAA, 0x?? and get two matches... I've been all around Google but still can't find any suggestions on how anything like this can be implemented..... Can someone please give me a clue? Some well-known algorithm maybe? Thanks!
2
6468
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_ { char szInput; char szOutput; int iSum;
1
1252
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 more than 3-4 Mb of data in plain text, and you can imagine that interpreting or getting information from such a big file is time consuming, that's why I tryed to implement some archiving functionality. My question is if someone knows a fast string...
1
1653
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 Services ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY ** ---------------------------------------------------------- http://www.usenet.com
8
2369
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 be great if the engine (or so) would accept multiple parameters (like a search offset, a max number of bytes to search in etc.) Any ideas Thanks a lot again Gordon
8
2388
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 cache of proxy and send to client if it is cache, if it is not there then it have to get data from web server and store in proxy server cache. so i am thinking to use binary tree search(or AVL tree) to search request URL content in cache if it...
4
5350
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 the Identifier. The logical way would be to read the record once and put it in an STL container such as vector and then use lower_bound to search for a given identifier. But for some strange reason i'm asked to not use a container but instead...
15
2140
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 instant search for my gui Instant search, i mean that my program search words and show words to user as user type letters.
5
3188
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 search algorithms that can be used are Linear Search and Binary Search. The sorting algorithms are bubble, selection and Insertion sort. First, the user is asked whether he/she wants to perform a search option, a sort operation, or exit the program. If...
0
9544
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.