Invitation to Computer Science 8th Edition

Published by Cengage Learning
ISBN 10: 1337561916
ISBN 13: 978-1-33756-191-4

Chapter 3 - 3.4 - Analysis of Algorithms - Practice Problems - Page 123: 3

Answer

final list = [2,1, 4, 1], legit =3

Work Step by Step

Converging pointer takes two pointer left and right. Initially left is at 1st element and right is at last element. Left is increased until it reaches a zero element or right. In the given list it will reach 0 at 2nd position so it will copy the value pointed by right at 2nd position and decrease the value of right and legit by 1. Now there are no zero left so left will reach right and the program will end. The above mentioned list will be received at the end and it will have 3 legit elements. final list = [2,1, 4, 1], legit =3
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.