Hey i am doing a Dynamic Array List and im wondering how to do a Linear and Binary Search for the Array List and what are the pro’s and con’s of these searches.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Guessing that you are implementing these as an expanding array in that when you run out of room you reallocate the new array and then copy the elements over.
In this case your question comes down to how to implement a linear and binary search over this array?
In that case there are plenty of articles, samples, found online.
The advantage of linear search is the fact that for small arrays there is no speed different, and it will work on an unsorted array always, as long as the item you are looking for is in the array.
This is in contrast to the binary search of which is very fast for large arrays, but for small sized ones there is no real performance benefit over a linear search. This speed up comes at the cost of it having to be sorted to get this advantage.