Hello, please help me with this question. I have shared the algorithm which I have seen in the slides so that it can compare with another algorithm approach. Short answer Another approach to the update algorithm is to perform use the delete function for the old value and if it is successful, call the insert function using the new value. Explain in your own words if you think this approach is significantly better, worse, or in the same category as the
Hello, please help me with this question. I have shared the
Short answer
Another approach to the update algorithm is to perform use the delete function for the old value and if it is successful, call the insert function using the new value. Explain in your own words if you think this approach is significantly better, worse, or in the same category as the algorithm discussed in the slides, and why.
I attached the pictures of the algorithm discussed in the slides.
![Sorted Arrays
Code for update (uses binary search function):
else
// newValue is to the right
{
if (recordIndex == 0)
return true;
nextIndex = recordIndex - 1;
while (nextIndex >= 0 && newValue < numbers [nextIndex])
{
numbers [nextIndex+1] = numbers [nextIndex];
nextIndex--;
}
nextIndex++;
numbers [nextIndex] = newValue;
return true;
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5cc38ce6-b814-49a7-adf4-92412b56b3a8%2F47171640-2818-4c23-bd0c-e02337966b06%2F0uotd0s_processed.png&w=3840&q=75)
![Sorted Arrays
Code for update (uses binary search function):
boolean updateBinarySearchMoveAndShift (int oldvalue, int newValue)
{
int recordIndex
binarySearch (oldvalue);
if (recordIndex
-1)
==
return false;
int nextIndex = 0;
if (newValue > oldvalue) // newValue is to the left
{
nextIndex = recordIndex + 1;
if (nextIndex == currentSize)
return true;
while (nextIndex < currentSize &6 newValue > numbers [nextIndex])
{
numbers [nextIndex-1] = numbers [nextIndex];
nextIndex++;
}
nextIndex--;
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5cc38ce6-b814-49a7-adf4-92412b56b3a8%2F47171640-2818-4c23-bd0c-e02337966b06%2Fs7y8czl_processed.png&w=3840&q=75)

Another approach to the update algorithm is to perform use the delete function for the old value and if it is successful, call the insert function using the new value.
Step by step
Solved in 2 steps









