Algorithms - Algorithm Design Techniques

Common Data for Q. 16 & Q. 17

We are given 9 tasks T1, T2… T9. The execution of each task requires one unit of time. We can execute one task at a time. Ti has a profit Pi and a deadline di profit Pi is earned if the task is completed before the end of the dith unit of time.
 TaskT1T2T3T4T5T6T7T8T9
 Profit152030181810231625
 Deadline725345273

16. To implement Dijkstra's shortest path algorithm on unweighted graphs so that it runs in linear time, then data structure to be used is

  • Option : C
  • Explanation :
    In order to find minimum size of X capable of storing any kind of binary tree, the worst case size of the tree has to be taken.
    In the worst case size of the tree has to be taken. In the worst case only a single node will contain the data at each level of the tree.
    For example, for 4 data items, the worst case binary tree will be as follows

    Generalizing the concept, for n vertices, the levels of tree that are required will be n.
    Memory required at each level (starting from root) will be 20, 21, 22, .... 2n-1
    ∴ Minimum size = 20 + 21 + 22, .... 2n-1
    = 20(2n-1)/(2-1) = 2n-1
Cancel reply
Cancel reply

17. Dijkstra's single source shortest path algorithm when run from vertex a in the below graph, computes the corrects shortest path distance to

  • Option : D
  • Explanation :
    Dijkstra’s single source shortest path in not gives the guarantee to work on negative weight edges graph.
    But in this graph it gives the correct shootest path for all vertex.
    Shortest path for
    B → 1
    e → –2
    F → O
    g → 3
    h → –2
    d → 6
    C → 3
Cancel reply
Cancel reply

20. What is the weight of a minimum spanning tree of the following graph?

  • Option : B
  • Explanation :
    Minimum Spanning tree is

    Total sum = 1 + 2 + 2 + 2 + 3 + 4 + 4 + 5 + 8 = 31
Cancel reply
Cancel reply