Question: Answer the questions in full detail! Explain the process in a step-by-step procedure and remember that the content is highly based on zybook chapters for

Answer the questions in full detail! Explain the process in a step-by-step procedure and remember that the content is highly based on zybook chapters for algorithms and data structures. The question is self explanatory as how the answer should be. Will rate afterwards accordingly!

Answer the questions in full detail! Explain the process in a step-by-step

procedure and remember that the content is highly based on zybook chapters

for algorithms and data structures. The question is self explanatory as howThe algorithm has been included in the two images above!

2. (10 pts) Recall the O(n Ig n)-time algorithm given in class that on an input array A of integers and a given integer intVal, finds two indices i and j, where A[i] + A[j] = intVal. Show how the algorithm can be modified in order to find indices i andj, where A[i] - A[j] = intVal instead. Analyze the running time of the modified algorithm. Input: (AT...n-1)), array of integers ,ko-Z. Output: i osisjen-s, when AG) + Auj] = 1 for lint i=o, ich, i++) folint jo.jen, jtt) y Aci ] + A13] =k+ - reearnli 15. return "not found" won th 1 1 total running time: (+1+) xnxn +1 = 3n+1=0(5) AGJt Arj]t Better also: Vi kang O(nlyn) 1. Morgesut A. Acil=k-AE) a for lintizo; isn, itt) ? Ollow xn 162. Val = K-Atid: 11., Do a Binary Search for val to) +1 Better algo: Acast AEG II Vi kang Olnlyn) 1 . Merge sut A. A[j] = K-A1 a for lint ico; ish, i++) - 7 Ollon) xn | 16 D. val= K-A ti]. honor ... Do a Binery Search for was I tolgo)+1 Chapter 3 Page 30 1 ton) +1 I 1E . bign) F4 I 1 5 h Do a Binery Search forval in A. to find j, whe A[i]=val- If such aj is found, return (i, j) return "not found". 16 6. total: = o (nen) + nx Olgn) + 1 0 Ingus 2. (10 pts) Recall the O(n Ig n)-time algorithm given in class that on an input array A of integers and a given integer intVal, finds two indices i and j, where A[i] + A[j] = intVal. Show how the algorithm can be modified in order to find indices i andj, where A[i] - A[j] = intVal instead. Analyze the running time of the modified algorithm. Input: (AT...n-1)), array of integers ,ko-Z. Output: i osisjen-s, when AG) + Auj] = 1 for lint i=o, ich, i++) folint jo.jen, jtt) y Aci ] + A13] =k+ - reearnli 15. return "not found" won th 1 1 total running time: (+1+) xnxn +1 = 3n+1=0(5) AGJt Arj]t Better also: Vi kang O(nlyn) 1. Morgesut A. Acil=k-AE) a for lintizo; isn, itt) ? Ollow xn 162. Val = K-Atid: 11., Do a Binary Search for val to) +1 Better algo: Acast AEG II Vi kang Olnlyn) 1 . Merge sut A. A[j] = K-A1 a for lint ico; ish, i++) - 7 Ollon) xn | 16 D. val= K-A ti]. honor ... Do a Binery Search for was I tolgo)+1 Chapter 3 Page 30 1 ton) +1 I 1E . bign) F4 I 1 5 h Do a Binery Search forval in A. to find j, whe A[i]=val- If such aj is found, return (i, j) return "not found". 16 6. total: = o (nen) + nx Olgn) + 1 0 Ingus

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!