ANSI charactors

  • 28 Replies
  • 1056 Views
*

Korrelan

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1115
  • Look into my eyes! WOAH!
    • YouTube
Re: ANSI charactors
« Reply #15 on: September 14, 2018, 12:48:22 am »
Are you getting binary sort and binary search mixed up?

 :)
It thunk... therefore it is!... my project page.

*

LOCKSUIT

  • Emerged from nothing
  • Trusty Member
  • *************
  • Transformer
  • *
  • 2183
  • First it wiggles, then it is rewarded.
Re: ANSI charactors
« Reply #16 on: September 14, 2018, 12:55:21 am »
so if my IDs are sorted like this 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
and not like 4 1 7 2 9 3....
then I can just find "3736" in 1 hit?...

I just want to find "47487" in millions of Ids in a fast amount of time man...

And I don't understand how Binary Search can find the middle ID to start cutting it down by half when it can't just "find" a ID like that so fast. BS can't just "find" the middle element. If it can find that, then it can just find ID "474577" in a sorted array.
Emergent

*

LOCKSUIT

  • Emerged from nothing
  • Trusty Member
  • *************
  • Transformer
  • *
  • 2183
  • First it wiggles, then it is rewarded.
Re: ANSI charactors
« Reply #17 on: September 14, 2018, 05:53:30 am »
Can anyone explain how Binary Search finds the middle element in 1 read?

Say you have IDs:
1, 2, 3, 4, 5, 6, 7

Does BS look at half of them just to find it, or only 1 read? If 1 read, how!?
Emergent

*

LOCKSUIT

  • Emerged from nothing
  • Trusty Member
  • *************
  • Transformer
  • *
  • 2183
  • First it wiggles, then it is rewarded.
Re: ANSI charactors
« Reply #18 on: September 14, 2018, 06:02:16 am »
Oh sorry, I mean, when BS begins, and wants to compute the middle element just simply so it can start cutting in half the possible IDs, how does it find the middle element in 1 read!?
Emergent

*

LOCKSUIT

  • Emerged from nothing
  • Trusty Member
  • *************
  • Transformer
  • *
  • 2183
  • First it wiggles, then it is rewarded.
Re: ANSI charactors
« Reply #19 on: September 14, 2018, 07:02:43 am »
good thing mine will be sorted

see middle area of this vid:

those 40 or so blocks contains numbers that don't increment by 1 like 1 2 3 4 5 6.....but rather 3 6 13 19 26...

If my IDs are like 1 2 3 4 5 6....i.e. sorted+incremental by 1, then does that mean I can just take 1 read and find ID 464846 instantly and don't need binary search?
Emergent

*

Korrelan

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1115
  • Look into my eyes! WOAH!
    • YouTube
Re: ANSI charactors
« Reply #20 on: September 14, 2018, 09:11:40 am »
If you have an array were each element contains a consecutive number with no gaps then you will not need a binary search... But what's the  point? If you already have the index/ address of the required array element and the element just contains the same number, just use the index.

 :)
It thunk... therefore it is!... my project page.

*

ranch vermin

  • Not much time left.
  • Terminator
  • *********
  • 961
  • Its nearly time!
Re: ANSI charactors
« Reply #21 on: September 14, 2018, 11:18:00 am »
haha sounds like Locksuit is coming up with his own content addressable memory!

Keep going Locky!   ill give you a merit badge at the finish line.  O0

*

8pla.net

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1064
    • 8pla.net
Re: ANSI charactors
« Reply #22 on: September 15, 2018, 03:42:41 am »
Can anyone explain how Binary Search finds the middle element in 1 read?

Say you have IDs:
1, 2, 3, 4, 5, 6, 7


Yes.  Let's look at some simple PHP...

Code: [Select]
<?php

$numbers
=array(1,2,3,4,5,6,7);

echo 
var_export($numbersTRUE);

echo 
"\n\n";

echo 
"Middle element:".floor(sizeof($numbers)/2);

echo 
"\n\n";

?>


array (
  0 => 1,
  1 => 2,
  2 => 3,
  3 => 4,
  4 => 5,
  5 => 6,
  6 => 7,
)

Middle element:3

See? The keys 0 through 6 are automatic.  So, just divide the count by two.
My Very Enormous Monster Just Stopped Using Nine

*

Ultron

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 472
  • There are no strings on me.
Re: ANSI charactors
« Reply #23 on: September 15, 2018, 01:36:41 pm »
I suggest you use a real database engine such as MySQL (or depending on your project you may also use a NoSQL horizontally scalable DB). In the table you would have an ID column with an 'auto-increment' setting and omitting this column will not improve performance.

If you really must use arrays and this is only for temporary memory then I suggest using a simple array ( [item item item item] ) and retrieve each element by referencing it's index and this will only work if you need to find "the element at position x", but if you need to find the "position x of element y" than this will be a bad solution (resort to SQL DB).
As a general guideline, referencing an array element by index is faster than retrieving elements by key-value pairs (although this may not be true for all programming languages).
Software and Hardware developer, and everything in between.

*

8pla.net

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1064
    • 8pla.net
Re: ANSI charactors
« Reply #24 on: September 16, 2018, 02:11:42 am »
Here are two ways to do a binary search:

https://www.geeksforgeeks.org/binary-search-php

The way that uses recursion is interesting.
My Very Enormous Monster Just Stopped Using Nine

*

LOCKSUIT

  • Emerged from nothing
  • Trusty Member
  • *************
  • Transformer
  • *
  • 2183
  • First it wiggles, then it is rewarded.
Re: ANSI charactors
« Reply #25 on: September 16, 2018, 07:20:45 am »
If i want to store in my python script a whole lot a crazy characters lik ! , ' " : [ { + =......won't python think I am talking python?

Like look dude...:

array = 3, 4, 2, 5, 7, %, ',

Also another request, I want that array to look like this because it saves on space: 3,4,2,5,7,%,', else memory WILL grow.

How how how!!?? Do I use a string to do binary search in (or just search as korr agreed if it is sorted and ID incremental ex. 1 2 3)?

I will basically have jumble like this with spaces or commas as the definer of the start of a new ID or "node" if you will:
array/string = H,J.k&,%5,"D L,P H,#$ k.^# ...........<- *notice the spaces* (can be commas)
Emergent

*

8pla.net

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1064
    • 8pla.net
Re: ANSI charactors
« Reply #26 on: September 16, 2018, 12:11:00 pm »
"won't python think I am talking python?", Lock Suit asked.  In friendly response (not sarcastically)... "So what if it does?
Basically suggesting a short Python script be written and executed to test and see what happens.

Python console:

>>>
[Locksuit for Locksuit in "HJk&%5DLP#$k.^#"]

['H', 'J', 'k', '&', '%', '5', 'D', 'L', 'P', '#', '$', 'k', '.', '^', '#']

My Very Enormous Monster Just Stopped Using Nine

*

Korrelan

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1115
  • Look into my eyes! WOAH!
    • YouTube
Re: ANSI charactors
« Reply #27 on: September 16, 2018, 12:21:09 pm »
https://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Make the time and effort to learn programming lock, you will really enjoy it.

 :)
It thunk... therefore it is!... my project page.

*

Ultron

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 472
  • There are no strings on me.
Re: ANSI charactors
« Reply #28 on: September 16, 2018, 03:51:57 pm »
I very much agree with Korrelan. In fact, I don't see a way how anyone would design artificial intelligence if one does not understand the basic principles of programming - unless this person believes a completely new computing model should be designed with completely new programming techniques (which I would agree with) but then one would have to be an adept mathematician, at which point becoming a programmer would represent only a formality.
Software and Hardware developer, and everything in between.

 


Users Online

24 Guests, 1 User
Users active in past 15 minutes:
Data
[Global Moderator]

Most Online Today: 86. Most Online Ever: 208 (August 27, 2008, 09:36:30 am)

Articles