Asked • 03/15/19

Adding elements to a sorted array?

What would be the fastest way of doing this (from an algorithmic perspective, as well as a practical matter)?I was thinking something along the following lines.I could add to the end of an array and then use bubblesort as it has a best case (totally sorted array at start) that is close to this, and has linear running time (in the best case).On the other hand, if I know that I start out with a sorted array, I can use a binary search to find out the insertion point for a given element.My hunch is that the second way is nearly optimal, but curious to see what is out there.How can this best be done?

2 Answers By Expert Tutors

By:

James T. answered • 06/03/19

Tutor
New to Wyzant

Talented Programmer and Logician

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.