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.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 15RQ
icon
Related questions
Question

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;
}
Transcribed Image Text: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; }
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--;
}
Transcribed Image Text: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--; }
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage