(a)
To show that the values of array and auxiliary values after each iterations of while loop using HOARE-PARTITION.
(a)
Explanation of Solution
Given Information: The array is
Explanation: According to the HOARE-PARTITION,
Consider that
Now the array and auxiliary after each pass through HOARE-PARTITION algorithm will show in below table-
After the iteration
Hence, the HOARE-PARTITION algorithm exit the while loop with the auxiliary values of
(b)
To showthat the indices i and j are such that we never access an element of array A outside the sub-array.
(b)
Explanation of Solution
In the beginning of while loop when
Consider that it has an element k and
If it takes parameter
Hence, it is can be concluded that the indices i and j are such that one never access an element of array A outside the sub-array.
(c)
To explain that when HOARE-PARTITION terminates, it returns a value j such that
(c)
Explanation of Solution
The value of jis decreased after every iteration and at the final iteration of the loop i will equals to 1but greater than r .
Line 11 of HOARE-PARTITION illustrate that
Therefore, the HOARE-PARTITION algorithm terminates and returns
(d)
To explain that the every element of array is less than or equal to every element of
(d)
Explanation of Solution
Consider that it just finished the iteration of the loop in which j went to j1 and j2 and I went to i1 to i2 . The elements of the array
Similarly, the elements of the array
Now putting all the conditions of the array defined in the algorithm it has condition that is
Since at the termination of the algorithm
Therefore, the every element of array
(e)
To rewrite the QUICK-SORT procedure by using HOARE-PARTITION algorithm.
(e)
Explanation of Solution
QUICKSORT(A,p,r). If then q =HOARE-PARTITION(A,p,r). QUICKSORT(A,p,q-1). QUICKSORT(A,q+1,r). End if. HOARE-PARTITION(A,p,r) while TRUE repeat until . repeat . until . if then exchange with . else return j. end if. end while.
The quick sort algorithm is based on recursion. It first sets the parameters and then check the initial condition.
If the initial condition is true then it call the HOARE-PARTITION algorithm with recursion of calling itself again and again until the initial condition becomes false.
Want to see more full solutions like this?
Chapter 7 Solutions
Introduction To Algorithms, Third Edition (international Edition)
- I need help creating the network diagram and then revising it for the modified activity times.arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forwardGiven the following Extended-BNF grammar of the basic mathematical expressions: Show the derivation steps for the expression: ( 2 + 3 ) * 6 – 20 / ( 3 + 1 ) Draw the parsing tree of this expression. SEE IMAGEarrow_forward
- Whentheuserenters!!,themostrecentcommandinthehistoryisexecuted.In the example above, if the user entered the command: Osh> !! The ‘ls -l’ command should be executed and echoed on user’s screen. The command should also be placed in the history buffer as the next command. Whentheuserentersasingle!followedbyanintegerN,theNthcommandin the history is executed. In the example above, if the user entered the command: Osh> ! 3 The ‘ps’ command should be executed and echoed on the user’s screen. The command should also be placed in the history buffer as the next command. Error handling: The program should also manage basic error handling. For example, if there are no commands in the history, entering !! should result in a message “No commands in history.” Also, if there is no command corresponding to the number entered with the single !, the program should output "No such command in history."arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forward2. UNIX Shell and History Feature [20 points] This question consists of designing a C program to serve as a shell interface that accepts user commands and then executes each command in a separate process. A shell interface gives the user a prompt, after which the next command is entered. The example below illustrates the prompt osh> and the user's next command: cat prog.c. The UNIX/Linux cat command displays the contents of the file prog.c on the terminal using the UNIX/Linux cat command and your program needs to do the same. osh> cat prog.c The above can be achieved by running your shell interface as a parent process. Every time a command is entered, you create a child process by using fork(), which then executes the user's command using one of the system calls in the exec() family (as described in Chapter 3). A C program that provides the general operations of a command-line shell can be seen below. #include #include #define MAX LINE 80 /* The maximum length command */ { int…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrCOMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE L