Binary Search
| While writing programs, I have often searched the Web for answers to particular problems, and have been grateful for the assistance gleaned from many sources. In the interest of returning the favour/s, this small group of pages has been written. I hope that the contents will be of interest and that they will benefit other programmers searching for an answer. Binary search becomes very useful when large arrays are used. The developed Binary Search algorithm handles mixed numerical-alphanumerical array data - a simple array or an array of arrays. It optionally returns the first instance of a target value, permitting one to iterate up through the other instances of that value. For the binary search, a sorted array is necessary. Javascript has an efficient built-in algorithm in its sort() function. However, this only sorts alphabetically. Therefore, an additional, purpose-built function is required to handle particular data types, The SortIt() function uses the Javascript sort() function to sort multiple columns in numerical/alphabetic order, with numerals first. In a recent application, arrays involving up to 10 columns of data also had to be sorted. In this case, the greatest required depth turned out to be a sort on 6 columns. SortIt() does this pretty quickly. Filing is not native to Javascript. However, in desktop applications, ActiveX can be used in conjuction with Javascript. All the normal file operations, reading/writing/appending data, creating folders, setting attributes, etc can be done. To avoid the operating system ActiveX warnings, your program should run under an .hta envelope, ie, as an application (like an .exe file). Details of how to do this are given. IE issues warnings regarding the length of a running script. When handling complex calculations/disk operations, etc, these warnings become a nuisance and detract from usability, adding operator annoyance. To avoid continuous long-script reminders, one needs to "tune" the registry. This is quite simple. A desktop shortcut icon to startup your application is useful and gives a nice finishing touch. You may encouter a lot of difficult-to-trace and varying error reports when running on Windows XP and Server - faults that did not arise when running on your development system. This can be due to idiosyncrasies of the system, and not due to your programming. It was found that the Read-only Attribute can not be permanently changed by Windows Explorer. The attribute is reset to read-only after one iteration. Thus a write operation would result in an error, the second and subsequent time a write or delete was attempted. A command-line or Javascript folder attributes action is required. I hope these pages prove useful! Please hi-light the portions of text you wish to retain, and use 'Copy' or ctrl+C. |
|