Problem 3 Develop algorithms to determine the lexicographical (alphabetical) order of two input strings. If a string strl lexicographically precedes another string str2, we can say strl < str2, and it means strl should appear earlier in dictionary than str2. If strl lexicographically follows str2, we can say strl > str2, and it means strl should appear later in dictionary. In general, the algorithm compares the two strings character by character, comparing the alphabetical order of the corresponding characters, based on the ASCII values of the characters (for example, character 'a' has value 97 and 'd' has value 100. "A' has value 65 and 'D' has value "68'). If the two corresponding characters are the same, continue with the next corresponding characters. The comparison stops when corresponding characters are different, or, end of the string is reached. Problem 3A (easier) In this version, assume the two input strings are of same length. The function starts by comparing the first character of each string. If they are equal, it continues with the following pairs until the characters differ, or, reaches the ends of the stings. If the first character that does not match has a lowe alphabetical order in strl than that in str2 (for example, 'a' in strl has lower ASCII value than 'd' in str2), then strl is deemed lexicographically precedes str2. The algorithm stops immediately and outputs " strl < str2". If the first character that does not match has a higher alphabetical order in strl than that in str2 (for example, 'e' in strl has larger ASCII value than 'B' in str2), then strl lexicographically follows str2 and the algorithm outputs "strl > str2". If no mismatch is detected until the end string, the two strings have the same content and the algorithm outputs "stri - str2". As an example, given first input string "jkle" and second input string "jkqc", comparison starts off by comparing the first character from the two strings. i.e7 from "jkl" and y" from "jkm". Since they are equal, the next two characters are compared, i.e k'from "jkl" and k' from "jkm". Since they are also equal, the next two characters are compared i.e, 'f from "jkl" and 'q' from "jkm". Since ASCII value of T is smaller than that of 'q', we conclude that the first string lexicographically precedes the second string and the algorithm will output "jklc< jiqc". Note that the algorithm stops immediately and will not compare the rest of characters.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
More examples (convince yourself about the lexicographic orders):
Second input string
First input string
Expected output
"abc"
"abe"
"abc < abe"
"cue"
"bat"
"cue > bat"
"apple"
"apple < beast"
"beast"
"еxit"
"exam"
"ехam"
"exam"
"exit > exam"
"ехam"
"exam > Exam"
"exam" ==
"еxam"
"Exam"
Develop flowchart for this algorithm,
o For characters comparisons, just use < >==, as numerical values
o Should stop the searching loop immediately 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.
o Save the flowchart as img_03A.jpg
Implement the algorithm using JavaScript
o Use prompt to ask users for two input strings
o For characters comparisons, just use <>=, as numerical values
o You should stop loop immediately when a mismatch is found. But you cannot use break. Use
the approach mentioned in class and used in lab to stop the loop earlier. The loop should only
have one exit point.
Sample input/output
helloworld > helloWorld
problem y
protlem-ayt nplace)
problend-vay arch
pralema--ngmpare (same leng
prlem mpr
Transcribed Image Text:More examples (convince yourself about the lexicographic orders): Second input string First input string Expected output "abc" "abe" "abc < abe" "cue" "bat" "cue > bat" "apple" "apple < beast" "beast" "еxit" "exam" "ехam" "exam" "exit > exam" "ехam" "exam > Exam" "exam" == "еxam" "Exam" Develop flowchart for this algorithm, o For characters comparisons, just use < >==, as numerical values o Should stop the searching loop immediately 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. o Save the flowchart as img_03A.jpg Implement the algorithm using JavaScript o Use prompt to ask users for two input strings o For characters comparisons, just use <>=, as numerical values o You should stop loop immediately when a mismatch is found. But you cannot use break. Use the approach mentioned in class and used in lab to stop the loop earlier. The loop should only have one exit point. Sample input/output helloworld > helloWorld problem y protlem-ayt nplace) problend-vay arch pralema--ngmpare (same leng prlem mpr
Problem 3
Develop algorithms to determine the lexicographical (alphabetical) order of two input strings. If a string strl
lexicographically precedes another string str2, we can say strl < str2, and it means strl should appear earlier in
dictionary than str2. If strl lexicographically follows str2, we can say strl > str2, and it means strl should appear
later in dictionary.
In general, the algorithm compares the two strings character by character, comparing the alphabetical order of the
corresponding characters, based on the ASCII values of the characters (for example, character 'a' has value 97 and
'd' has value 100. *A' has value 65 and 'D' has value *68'). If the two corresponding characters are the same,
continue with the next corresponding characters. The comparison stops when corresponding characters are different,
or, end of the string is reached.
Problem 3A (easier)
In this version, assume the two input strings are of same length.
The function starts by comparing the first character of each string. If they are equal, it continues with the following
pairs until the characters differ, or, reaches the ends of the stings. If the first character that does not match has a lower
alphabetical order in strl than that in str2 (for example, 'a' in strl has lower ASCII value than 'd' in str2), then strl
is deemed lexicographically precedes str2. The algorithm stops immediately and outputs “ strl < str2". If the first
character that does not match has a higher alphabetical order in strl than that in str2 (for example, 'c' in strl has
larger ASCII value than 'B' in str2), then strl lexicographically follows str2 and the algorithm outputs "strl > str2".
If no mismatch is detected until the end string, the two strings have the same content and the algorithm outputs “strl
= str2".
As an example, given first input string "jkle" and second input string "jkqc", comparison starts off by comparing the
first character from the two strings. i.e '7 from "jkl" and 'y from "jkm". Since they are equal, the next two characters
are compared, i.e k'from "jkl" and k' from "jkm". Since they are also equal, the next two characters are compared
i.e, 'T from "jkl" and 'q' from "jkm". Since ASCII value of " is smaller than that of 'q', we conclude that the first
string lexicographically precedes the second string and the algorithm will output "jkle< jiqc". Note that the
algorithm stops immediately and will not compare the rest of characters.
Transcribed Image Text:Problem 3 Develop algorithms to determine the lexicographical (alphabetical) order of two input strings. If a string strl lexicographically precedes another string str2, we can say strl < str2, and it means strl should appear earlier in dictionary than str2. If strl lexicographically follows str2, we can say strl > str2, and it means strl should appear later in dictionary. In general, the algorithm compares the two strings character by character, comparing the alphabetical order of the corresponding characters, based on the ASCII values of the characters (for example, character 'a' has value 97 and 'd' has value 100. *A' has value 65 and 'D' has value *68'). If the two corresponding characters are the same, continue with the next corresponding characters. The comparison stops when corresponding characters are different, or, end of the string is reached. Problem 3A (easier) In this version, assume the two input strings are of same length. The function starts by comparing the first character of each string. If they are equal, it continues with the following pairs until the characters differ, or, reaches the ends of the stings. If the first character that does not match has a lower alphabetical order in strl than that in str2 (for example, 'a' in strl has lower ASCII value than 'd' in str2), then strl is deemed lexicographically precedes str2. The algorithm stops immediately and outputs “ strl < str2". If the first character that does not match has a higher alphabetical order in strl than that in str2 (for example, 'c' in strl has larger ASCII value than 'B' in str2), then strl lexicographically follows str2 and the algorithm outputs "strl > str2". If no mismatch is detected until the end string, the two strings have the same content and the algorithm outputs “strl = str2". As an example, given first input string "jkle" and second input string "jkqc", comparison starts off by comparing the first character from the two strings. i.e '7 from "jkl" and 'y from "jkm". Since they are equal, the next two characters are compared, i.e k'from "jkl" and k' from "jkm". Since they are also equal, the next two characters are compared i.e, 'T from "jkl" and 'q' from "jkm". Since ASCII value of " is smaller than that of 'q', we conclude that the first string lexicographically precedes the second string and the algorithm will output "jkle< jiqc". Note that the algorithm stops immediately and will not compare the rest of characters.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY