Problem Statement: Consider an input string PAL of letters ‘P’, ‘A’, and ‘L’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called PAL_TAB. The number of each of these letters is unknown. We have a function, called SWAP(PAL, i, j), which places the ith letter in the jth entry of string PAL and the jth letter in the ith entry of PAL. Note that SWAP(PAL, i, j) is defined for all integers i and j between 0 and length(PAL) – 1, where length(PAL) is the number of letters of PAL. 1. Using our algorithmic language, write an algorithm, called Sort_PAL, which sorts the letters in the array PAL_TAB in a way that all P’s appear first, followed by all A’s, and followed by all L’s. The algorithm Sort_PAL should have one parameter: The array PAL_TAB. Also, your solution is correct only if the four constraints below are satisfied: - Constraint 1: Each letter (‘A’, ‘L’, or ‘P’) is evaluated only once. - Constraint 2: The function SWAP(PAL, i, j) is used only when it is necessary. - Constraint 3: No extra space can be used by the algorithm Sort_PAL. In other words, only the array PAL_TAB can be used to sort the ‘A’, ‘L’, or ‘P’. - Constraint 4: You cannot count the number of each letter ‘A’, ‘L’, or ‘P’. 2. Show that the algorithm Sort_PAL is correct using an informal proof (i.e., discussion). 3. Give a program corresponding to Sort_PAL using your favorite programming language. Deliverables: Students may choose to work in team of up to two members. You should turn in a report explaining all the design decisions and your code should be commented appropriately for readability and understanding. More precisely, a report should include the problem statement, proposed approach/solution along with a detailed discussion, algorithm (high-level description of all the design parts along with some details when necessary), commented code, tests (input given by the user and output generated by your program execution), and lessons learned from such an implementation experience.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Problem Statement: Consider an input string PAL of letters ‘P’, ‘A’, and ‘L’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called PAL_TAB. The number of each of these letters is unknown. We have a function, called SWAP(PAL, i, j), which places the ith letter in the jth entry of string PAL and the jth letter in the ith entry of PAL. Note that SWAP(PAL, i, j) is defined for all integers i and j between 0 and length(PAL) – 1, where length(PAL) is the number of letters of PAL. 1. Using our algorithmic language, write an algorithm, called Sort_PAL, which sorts the letters in the array PAL_TAB in a way that all P’s appear first, followed by all A’s, and followed by all L’s. The algorithm Sort_PAL should have one parameter: The array PAL_TAB. Also, your solution is correct only if the four constraints below are satisfied: - Constraint 1: Each letter (‘A’, ‘L’, or ‘P’) is evaluated only once. - Constraint 2: The function SWAP(PAL, i, j) is used only when it is necessary. - Constraint 3: No extra space can be used by the algorithm Sort_PAL. In other words, only the array PAL_TAB can be used to sort the ‘A’, ‘L’, or ‘P’. - Constraint 4: You cannot count the number of each letter ‘A’, ‘L’, or ‘P’. 2. Show that the algorithm Sort_PAL is correct using an informal proof (i.e., discussion). 3. Give a program corresponding to Sort_PAL using your favorite programming language. Deliverables: Students may choose to work in team of up to two members. You should turn in a report explaining all the design decisions and your code should be commented appropriately for readability and understanding. More precisely, a report should include the problem statement, proposed approach/solution along with a detailed discussion, algorithm (high-level description of all the design parts along with some details when necessary), commented code, tests (input given by the user and output generated by your program execution), and lessons learned from such an implementation experience.
Problem Statement: Consider an input string PAL of letters 'P', 'A', and 'L'. This string, which
is given by the user, ends with '#'. It should be stored in a table (or array), called PAL_TAB. The
number of each of these letters is unknown. We have a function, called SWAP(PAL, i, j), which
places the ith letter in the jth entry of string PAL and the jth letter in the ith entry of PAL. Note that
SWAP(PAL, i, j) is defined for all integers i and j between 0 and length(PAL) 1, where
length(PAL) is the number of letters of PAL.
1. Using our algorithmic language, write an algorithm, called Sort_PAL, which sorts the
letters in the array PAL_TAB in a way that all P's appear first, followed by all A's, and
followed by all L's. The algorithm Sort_PAL should have one parameter: The array
PAL_TAB. Also, your solution is correct only if the four constraints below are satisfied:
- Constraint 1: Each letter ('A', 'L', or 'P') is evaluated only once.
- Constraint 2: The function SWAP(PAL, i, j) is used only when it is necessary.
- Constraint 3: No extra space can be used by the algorithm Sort_PAL. In other words,
only the array PAL_TAB can be used to sort the 'A', 'L', or 'P'.
- Constraint 4: You cannot count the number of each letter 'A', 'L', or 'P'.
2. Show that the algorithm Sort_PAL is correct using an informal proof (i.e., discussion).
3. Give a program corresponding to Sort_PAL using your favorite programming language.
Deliverables: Students may choose to work in team of up to two members. You should turn in a
report explaining all the design decisions and your code should be commented appropriately for
readability and understanding. More precisely, a report should include the problem statement,
proposed approach/solution along with a detailed discussion, algorithm (high-level description of
all the design parts along with some details when necessary), commented code, tests (input given
by the user and output generated by your program execution), and lessons learned from such an
implementation experience.
Transcribed Image Text:Problem Statement: Consider an input string PAL of letters 'P', 'A', and 'L'. This string, which is given by the user, ends with '#'. It should be stored in a table (or array), called PAL_TAB. The number of each of these letters is unknown. We have a function, called SWAP(PAL, i, j), which places the ith letter in the jth entry of string PAL and the jth letter in the ith entry of PAL. Note that SWAP(PAL, i, j) is defined for all integers i and j between 0 and length(PAL) 1, where length(PAL) is the number of letters of PAL. 1. Using our algorithmic language, write an algorithm, called Sort_PAL, which sorts the letters in the array PAL_TAB in a way that all P's appear first, followed by all A's, and followed by all L's. The algorithm Sort_PAL should have one parameter: The array PAL_TAB. Also, your solution is correct only if the four constraints below are satisfied: - Constraint 1: Each letter ('A', 'L', or 'P') is evaluated only once. - Constraint 2: The function SWAP(PAL, i, j) is used only when it is necessary. - Constraint 3: No extra space can be used by the algorithm Sort_PAL. In other words, only the array PAL_TAB can be used to sort the 'A', 'L', or 'P'. - Constraint 4: You cannot count the number of each letter 'A', 'L', or 'P'. 2. Show that the algorithm Sort_PAL is correct using an informal proof (i.e., discussion). 3. Give a program corresponding to Sort_PAL using your favorite programming language. Deliverables: Students may choose to work in team of up to two members. You should turn in a report explaining all the design decisions and your code should be commented appropriately for readability and understanding. More precisely, a report should include the problem statement, proposed approach/solution along with a detailed discussion, algorithm (high-level description of all the design parts along with some details when necessary), commented code, tests (input given by the user and output generated by your program execution), and lessons learned from such an implementation experience.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education