Spelling Error Fequency

W

Word Heretic

G'day "Howard Kaikow" <[email protected]>,

Howard, ALWAYS use a bubble sort for lists <100

The cpu overhead for the other methods isn't worth it for small lists
- even shell sorts.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Howard Kaikow reckoned:
 
W

Word Heretic

G'day "Greg Maxey said:
Set colErrors = New Collection
Set oSpErrors = ActiveDocument.Range.SpellingErrors

Jez's eg is good because it explicitly instances an empty collection.
When we get an error, the VBA line is only trying to do one thing, so
we know what the real problem is.


It seems like ColErrors (a collection of spelling errors) should simply be

Set colErrors = ActiveDocument.Range.SpellingErrors

This is the simplified version. Now, when something goes wrong with
the object initialisation, we don't know whether there was a problem
creating a new object, or whether there was a problem accessing the
spellingerrors collection.

So you are right and wrong all at once. Your way would be simpler, but
a) under very specific and infrequent circumstances it causes problems
in itself
b) makes it harder to debug problems

Also, Jez and I belong to the old school of programming. Formally
DECLARE your variables, then INITIALISE them, then USE them. By using
this top-down approach to coding it makes it far easier to read the
code afterwards.


Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Greg Maxey reckoned:
 
W

Word Heretic

G'day "Greg Maxey" <[email protected]>,

I regularly can't remember whether stuff comes in or goes out with
what statement lol. However, the VBE's help system is excellent on
this, the eg code it provides for those statements makes LOTS of sense
VERY quickly. So don't panic - rely on help and you'll be ok.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Greg Maxey reckoned:
 
H

Howard Kaikow

Word Heretic said:
G'day "Howard Kaikow" <[email protected]>,

Howard, ALWAYS use a bubble sort for lists <100

The cpu overhead for the other methods isn't worth it for small lists
- even shell sorts.

Use Insertion or Selection sort.
Bubble is the worst.

See http://www.standards.com/index.html?Sorting for a program that
demonstrates performance differences.

For example, I just ran 10 samples of size 100, sorting strings using
bubble, insertion and selection sort.
Total times were 93, 38 and 55 milliseconds respectively for a
caseinsensitive sort, and 75, 36 and 18 milliseconds respectively for a case
sensitive sort.
 
W

Word Heretic

G'day "Howard Kaikow" <[email protected]>,

Ok, let us take this example.

I fill a collection of data objects from a text file (produced from a
form save as data only)

At most, there will dozens of items, and indeed I have dimmed the
array to a max of 99 elements

Now, I have two choices.

Howards Method - CPU intensive and SLOW

Write all object contents to a temp doc - SLOW
Invoke sort (which is damn quick for CONTENT sorts)
Read all elements back into collection - SLOW


The Heretical Method

Run a bubble-sort on the collection items. (Quick, as n<100)


Why?

The 'statistical' inefficiency of the bubble sort is negated by the
small value of n. With n inside two orders of magnitude (n<100),
there is little difference between a N! (quick sort | partition sort)
and N^2-1 (bubble sort).

The bubble sort requires very quick maths with little additional
overhead. The shell sort and the partition sort introduce many more
lines of code, thus slowing down execution of a single loop.

Additionally, the standard convention with bubble sorts is to include
a flag to set on swap. If you complete an iteration without setting
the flag, the data is ordered. Thus, the bubble sort is the only sort
with an 'early completion' meaning for nearly ordered data of any size
it is far faster than either of the other methods.

So, your sort method depends on data source, built-in methods
available to deal with it, and then a high-level analysis of the data
itself.

I have achieved speed increases from 30 secs runtime down to 0.04
seconds on mainframes by employing them sensibly. This was an extreme
example case, but never-the-less demonstrates my point. There is a
niche for bubble sorts in the domain of sorting data.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Howard Kaikow reckoned:
 
H

Howard Kaikow

Word Heretic said:
G'day "Howard Kaikow" <[email protected]>,

Ok, let us take this example.

I fill a collection of data objects from a text file (produced from a
form save as data only)

At most, there will dozens of items, and indeed I have dimmed the
array to a max of 99 elements

Now, I have two choices.

Howards Method - CPU intensive and SLOW

Write all object contents to a temp doc - SLOW
Invoke sort (which is damn quick for CONTENT sorts)
Read all elements back into collection - SLOW

Whoa!

I'm not writing the contents to a temp doc.
Using sort code directly.

Run the timing program I posted and you'll see the results.
 
W

Word Heretic

G'day "Howard Kaikow" <[email protected]>,

You have completely missed my point.

The statement you made, with very little context, was never use a
bubble sort. I just conclusively showed you should use them under
specific circumstances, which hardly ever arise in content issues.
However, as this is a VBA group your comments could easily be
misconstrued without the proper context.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Howard Kaikow reckoned:
 
G

Greg

Howard, Word Heretic,

Not to jump in the middle fo your spat.

Howard,

Can you answer this question posted earlier:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top