Binary search in php over list of strings -


i have file containing 30k songs names. have use list automatic text suggestion ajax. of names start numbers. question can binary search on list ? if yes, how ?

first of sort list;

suppose, first letter user has typed "a";

start high = 0 , low = number of strings -1;

then can define high , low index high last index starts "a" , low first index has string starts "a". 2 binary searches can achieved.

so if next letter typed "b" make binary search in range high , low defined above , adjust high , low again 2 binary searches. make sure search second character of strings between high , low matched "b" , on :)

note: i'd suggest use database so, queried if there's way use binary search, i'm answering way :)

simple sql query: select column_name table_name column_name 'prefix%' select strings start 'prefix' stored in column 'column_name' of 'table_name' table


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -