Question: a. Let A[1..n] and B[1..m] be two arrays, where n ? m ? 1. Use pseudocode to write an algorithm which prints TRUE if the

a. Let A[1..n] and B[1..m] be two arrays, where n ? m ? 1. Use pseudocode to write an algorithm which prints TRUE if the array A contains the sequence B, and FALSE otherwise. The elements from B must appear in order, but they do not have to occur as a contiguous sequence in A. The running time of the algorithm must be O(n).

Here are some examples:

- if A = <10, 3, 21, 5, 6, 14, 17, 9, 5, 6, 8, 11, 12> and B = <5, 6, 8> then the algorithm prints TRUE.

- if A = <10, 3, 21, 5, 6, 14, 17, 9, 5, 6, 8, 11, 12> and B = <3, 14, 11, 12>, then the algorithm prints TRUE

- if A = <10, 3, 21, 5, 6, 14, 17, 9, 5, 6, 8, 11, 12> and B = < 6, 5, 14>, then the algorithm prints FALSE

b. Consider the array A = <18, 10, 14, 3, 5, 7, 15, 12, 25, 80>.

1) (5 points) write A after calling the function BUILD-MAX-HEAP(A)

2) (5 points) write A after calling the function HEAP-INCREASE-KEY(A,9,50).

3) (5 points) write A after calling the function HEAP-EXTRACT-MAX(A)

Part 2) uses the array A resulted from part 1). Part 3) uses the array A resulted from part 2).

* Note that HEAP-INCREASE-KEY and HEAP-EXTRACT-MAX operationsare implemented in the Priority Queue.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!