• Post Reply Bookmark Topic Watch Topic
  • New Topic

Algorithms  RSS feed

 
George Willis
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I'm working on generating some bijective Base-26 numbers. I figured that one way to generate them is to create a series of loops, one within the other type of thing like a software raisin counter. As I was researching I came across the Wiki article at http://en.wikipedia.org/wiki/Hexavigesimal. In the article there appeared to be a rather elegant (to me at least) alogrithm:


Using remainders might have occurred to me eventually (some day). What really freaked me out was the "n--" part. That's pretty cool! But now I kind of have that Wayne's World "I'm not worthy of Heather Locklear" kind of feeling. There appear to be many book hits on Amazon about alogrithms. Any suggestions from the JavaRanch brain trust (books, methods or approaches) that can help me achieve the level where I can come up with alogrithms like the one above without simply stumbling across it in Google?

Thanks
 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

First things first - algorithms not algorithms

The second best book i can suggest is the book that was used when i went back to do my PhD studies (used for both undergrad and grad algorithms courses in computer science) - (2002)Introduction to Algorithms

The hands down best ever books on algorithms is The Art of Computer Programming - i had the honor of taking an algorithms course when i was going for my ba (1975). Instructor was great - book (semi numerical algorithms - volume 2) was wonderful. Kunth set the bar which hasn't been matched yet…… but it does have multiple volumes (and i think it is up to 6 volumes now).

But note: these are not java algorithms, but a discussion of the algorithms in a language neutral way.

-steve
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's a neat solution to the problem. But your question isn't really about Java, it's more about how to come up with that idea, right? After all that algorithm works perfectly well in many other languages and you could even implement it with paper and pencil. So "Creativity" is maybe what you're after here. So let me suggest a little book called "How to Solve It" which was written back in 1945. Here's how Amazon describes it:

A perennial bestseller by eminent mathematician G. Polya, How to Solve It will show anyone in any field how to think straight.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Willis wrote:What really freaked me out was the "n--" part...

Me too, until I re-read your first sentence.

Bijective numbers are interesting, undoubtedly, and can be useful for creating unique symbolic (String) keys; however, beyond that they don't have a vast amount of practical use. And that '--n' is actually an extra step that isn't needed in a normal conversion (integer division truncates in most languages) - and for huge numbers, like the sort that can be held by a BigInteger, possibly quite a lengthy one.

However, if this sort of stuff interests you, you might be interested in reading up on Gray codes; or indeed, one of the best pages I know on "bit hacks".

Enjoy!

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Fahlbusch wrote:First things first - algorithms not algorithms

huh?
 
George Willis
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without being too gushy about it, WHAT A GREAT SITE!

Ergo algo: Thank you for the correction. Dyslexia has struck again. I do not think that I will ever mis-spell that word in the future though. I might ask to trade afflictions with Mr. Fahlbusch (couldn't mis-spell a word if he wanted to) if it weren't for my fear of unintended consequences. Is there another site for discussions for those topics?

Introduction to Algorthims (book) - Looks good. From the Amazon reviews it is not light reading though. Not afraid there.

The Art of Computer Programming (book set) - Do you think that the assembly language format (from Amazon reviews) for algorithms will be a stumbling block for a Java noob? Mr. Fahlbusch did indicate that algorithms were discussed in a general way. I don't want to just drop $200 for something that is not going to be approachable in the near future. If it is discussed in a mathematical format it should be OK.

How to Solve It (book) - I just happen to have a 2nd Edition in my library. I'll start there!

Mr. Gutkowski - You get a Bingo on "keys". I had the idea of generating unique database primary keys by using time stamps. But, time stamps are not granular enough to generate keys at any processing speed. So, I needed something to append to the timestamp. Also, thanks for your suggested topics of interest. It's a huge universe!

 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have corrected the thread title so there are no longer any missspellings in this thread.
 
George Willis
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I suppose that I could have done that.
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Willis wrote:I had the idea of generating unique database primary keys by using time stamps.


Well, the easiest way to generate unique primary keys for a database table is to ask the database to do it for you. That has two advantages: (1) The database will do it reliably, and (2) You don't have to do anything except tell the database that you want it done.
 
George Willis
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would that be a simple numerical key (1, 2, 3, etc.)?
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:
Steve Fahlbusch wrote:First things first - algorithms not algorithms

huh?


I think he meant: "algorithms", not "alogrithms". See first post.



 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes - it is normally an integer value that would increase by 1 for each record posted to the table. (but it might not be - i have seen alpha generated keys and not sequential keys - not normal, but this is a feature of mostly all databases).

As to the books, these are classics - Hint: you may find them in a library. --- and the thing they call an assembly language is mix and is really there for a formalized implementation of the algorithms. But before you buy any see if you can borrow.

Also the Intro to Algorithms is currently a standard text for most university algorithm courses - you could see if you could get a used book on the cheap.

And i only corrected the spelling in case you were doing searches - and it was my spell checker that fixed the word.

Lastly, yes this is a great site and you have bumped into three great folks: Paul, Fred and Winston.

Welcome to the site.

-steve
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Willis wrote:Would that be a simple numerical key (1, 2, 3, etc.)?


You mean the primary keys generated by the database? Usually that's what they would use, but really you shouldn't care. If your primary key is supposed to have some meaning, then it's often better to have another (non-key) column which supports that meaning.
 
George Willis
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks to all.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Willis wrote:Would that be a simple numerical key (1, 2, 3, etc.)?

Sure, but wouldn't a bijective string just be a conversion of a number? In the way that Steve suggests, there's no conversion involved at all; and if there is a more natural, unique key for your table, then it would probably make sense to use that.

The example cited in the page is for spreadsheet columns; and there it makes absolute sense, because it is a visual key for us puny humans. In general, there are far easier ways of getting a unique key though.

Winston
 
George Willis
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you again.
My interest was in fact to have a visual but unique key. It is solely my desire to have it and may not be otherwise practical. Because I am trying to learn Java my whim has given me some hands on with GregorianCalendar, I know the difference between StringBuilder and StringBuffer, get to handle Eclipse nagging me while I'm trying to put this together, I've learned the word bijective, and have come a little closer to understanding Java and coding in general because of JavaRanch.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!