Problem 1 In this problem, develop an algorithm that, given an input string, determines if the string is symmetric. A st

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Problem 1 In this problem, develop an algorithm that, given an input string, determines if the string is symmetric. A st

Post by answerhappygod »

Problem 1 In This Problem Develop An Algorithm That Given An Input String Determines If The String Is Symmetric A St 1
Problem 1 In This Problem Develop An Algorithm That Given An Input String Determines If The String Is Symmetric A St 1 (228.29 KiB) Viewed 46 times
Problem 1 In this problem, develop an algorithm that, given an input string, determines if the string is symmetric. A string is symmetric if it reads the same backward as forward, e.g., "a" "aa", "dad", "madam", "that is a si taht". On the other hand, "ab" "random" or "Dad" "this is that" are not symmetric. There are several ways to check symmetry. One approach, for instance, is to create a reverse string and then check if they are the same. Here we refrain from using this approach as it requires extra storage for the reverse string. The algorithm here operates on the input string only. The main idea is to check the characters in the string and see if all the corresponding pair of characters (who are they?) match. Develop flowchart for this algorithm O Give pre-condition and post-condition for your algorithm. O Hint: you will need a loop for checking the characters. You may need two indexes, for the pair of characters to be compared. (What are the initial values of the two indexes and how they proceed?) You can use atr.length to get the number of characters in the string. For accessing characters in string, you can use array notation str For characters comparisons, just use =, same as comparing numerical values The algorithm should stop the loop immediately/early when a mismatch is found. But you cannot say, "go out of loop". Use the approach mentioned in class and lab to stop the loop earlier. The loop should have only one exit point. The algorithm proceeds until a mismatch is found, or, all the corresponding characters are compared (how to determine?) and no mismatch is found. In the former case the algorithm outputs "Not symmetric". In the latter case the algorithm outputs "Symmetric”. O Save the flowchart as img_symmetry.jpg O O O O O
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply