2,100
15
Essay, 1 pages (250 words)

Analyze code 3

Choose one algorithm that was created and posted by another to solve the same problem, and analyze the differences between the effectiveness of the two algorithms. Post the result of the analysis, and improvements.
DQ1: CK, ML, JL, AL, KSem
Code 1
The following optimizations have been used:
1)      To verify if a number is divisible by three it is enough to make sure the sum of the numbers digits is divisible by three. A counter ModSoFar is kept to see what the mod of the sum of the digits is in the currently tested string. This optimization helps contain the very large division that occurs on all of the tests to a mod of a number that is 11 at most. This might be optimized even further by changing the mod to an if and specifying if the ModSoFar is equal to 0, 3, 6 or 9 then… but that depends on the efficiency of the CPU and whether four comparisons is faster than one mod. Similar shortcuts are available for all of the numbers under 10 (Magness, Sinnot & Ward, 2004)
2)      In order to save going over the Digits to find the sub string that is needed for printing, the program keeps the growing string in a variable adding and additional characters as needed.
As a side note, according to Brookshear (2007) the indentation rules require an else to be directly under the indented “ then” of an “ if” which is confusing when there is an “ if” with no “ else” inside an “ if” with one (see lines 16 and 19 where the “ else” actually belongs to the “ if” on line 13).
Procedure SubStrMod3(Digits)
StartChar

Thank's for Your Vote!
Analyze code 3. Page 1
Analyze code 3. Page 2

This work, titled "Analyze code 3" was written and willingly shared by a fellow student. This sample can be utilized as a research and reference resource to aid in the writing of your own work. Any use of the work that does not include an appropriate citation is banned.

If you are the owner of this work and don’t want it to be published on AssignBuster, request its removal.

Request Removal
Cite this Essay

References

AssignBuster. (2021) 'Analyze code 3'. 17 November.

Reference

AssignBuster. (2021, November 17). Analyze code 3. Retrieved from https://assignbuster.com/analyze-code-3/

References

AssignBuster. 2021. "Analyze code 3." November 17, 2021. https://assignbuster.com/analyze-code-3/.

1. AssignBuster. "Analyze code 3." November 17, 2021. https://assignbuster.com/analyze-code-3/.


Bibliography


AssignBuster. "Analyze code 3." November 17, 2021. https://assignbuster.com/analyze-code-3/.

Work Cited

"Analyze code 3." AssignBuster, 17 Nov. 2021, assignbuster.com/analyze-code-3/.

Get in Touch

Please, let us know if you have any ideas on improving Analyze code 3, or our service. We will be happy to hear what you think: [email protected]