Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q1 By using the Max-Heap data structure to implement a priority queue, some appl

ID: 641671 • Letter: Q

Question

Q1

By using the Max-Heap data structure to implement a priority queue, some applications may need to change the data (priority) of a specific node i. That is, given an index i, change the priority of node i to a new priority t. Please write a pseudocode for this procedure. Max-Heap-update(A, i, t) {

}

_________________________________________

Q2

Given an array A, we try to sort the array using the quicksort algorithm. In this sorting, assume on each recursive step the partition procedure always partition each subarray into n ? 2 to 2 ratio, where n is the size of the subarray.
What

Explanation / Answer

Hope it helps you..

function Dijkstra(Graph, source):
       for each vertex v in Graph:           // Initializations

          dist[v] := infinity               // Unknown distance
                                              // function from source to v
           previous[v] := undefined
      dist[source] := 0                     // Distance from source to source

    Q := copy(Graph)                      // All nodes in the graph
                                              // are unoptimized - thus are in Q
       while Q is not empty:                 // The main loop

         u := extract_min(Q)               // Remove and return best vertex
                                              // from nodes in two given nodes
                                              // we would use a path finding algorithm
                                              // on the new graph,
                                              // such as depth-first search.
          for each neighbor v of u:         // where v has not yet been removed from Q.
         alt = dist[u] + length(u, v)

             if alt < dist[v]              // Relax (u,v)                 dist[v] := alt

                  previous[v] := u
      return previous[]

answer for 2 is:
the running time is O(logn)