Self Studies

Algorithms Test 4

Result Self Studies

Algorithms Test 4
  • Score

    -

    out of -
  • Rank

    -

    out of -
TIME Taken - -
Self Studies

SHARING IS CARING

If our Website helped you a little, then kindly spread our voice using Social Networks. Spread our word to your readers, friends, teachers, students & all those close ones who deserve to know what you know now.

Self Studies Self Studies
Weekly Quiz Competition
  • Question 1
    1 / -0

    Let String x be of length m and String y be of length n. What is the time complexity to find the longest common subsequence of the String x and y using Dynamic programming?

    Solution

    Concepts:

    for i = 0 to m

    {

    for j = 0 to n

    {

    If there is match, A[i, j] = A[i – 1, j  – 1] + 1

    If not match: max(A[i – 1, j], A[i, j – 1])

    }

    }

    Let x = ‘10010101 and y = ‘010110110’

    Table of longest common subsequence:

     

    x

    1

    0

    0

    1

    0

    1

    0

    1

    y

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    1

    1

    1

    1

    1

    1

    1

    1

    0

    1

    1

    1

    2

    2

    2

    2

    2

    0

    0

    1

    2

    2

    2

    3

    3

    3

    3

    1

    0

    1

    2

    2

    3

    3

    4

    4

    4

    1

    0

    1

    2

    2

    3

    3

    4

    4

    5

    0

    0

    1

    2

    3

    3

    4

    4

    5

    5

    1

    0

    1

    2

    3

    4

    4

    5

    5

    6

    1

    0

    1

    2

    3

    4

    4

    5

    5

    6

    0

    0

    1

    2

    3

    4

    5

    5

    6

    6

     

    The time complexity to fill this 2D array is O(m × n).

  • Question 2
    1 / -0

    Consider the following table:

     Algorithms

     Design Paradigms

     (A) Minimum spanning tree

     (I) Divide and Conquer

     (B) Binary Search

     (II) Greedy

     (C) Fibonacci numbers

     (III) Dynamic Programming

     

    Choose the appropriate algorithms to the design paradigms they are based on.
    Solution
    • Minimum spanning tree uses Greedy approach to solve the problem
    • Binary Search is an efficient searching algorithm that uses a divide-and-conquer approach to search ements in an sorted array.
    • Dynamic Programming is used in Fibonacci numbers
  • Question 3
    1 / -0
    Let ‘m’ and ‘n’ be the number of edges and vertices in a graph G, respectively. Which of the following is the time complexity of the Kruskal’s algorithm to find minimum spanning tree of G?
    Solution

    Kruskal’s algorithm is one of the algorithms used to find a minimum spanning tree of a graph G. Following are the steps for it.

    1. Sort all the edges according to their weight in non-decreasing order. Sorting of edges takes O(mLogm) time
    2. Pick the smallest edge. This step is called find-union algorithm and it takes O(mLogn) time
      1. If it forms a cycle with the spanning tree formed so far, skip it and move on to the next edge in the order.
      2. If cycle is not formed, include this edge.
    3. Repeat step no 2 until there are (V-1) edges in the spanning tree.


    So overall complexity is O(mLogm + mLogn) time. The value of m can be atmost O(n2), so O(Logn) and O(Logm) are same. Therefore, overall time complexity is O(mlogm) or O(mlogn).

  • Question 4
    1 / -0
    Let A1, A2, A3, and A4 be four matrices of dimensions 10 × 5, 5 × 20, 20 × 10, and 10 × 5, respectively. The minimum number of scalar multiplications required to find the product A1A2A3A4 using the basic matrix multiplication method is ______.
    Solution

    Concept:

    If we multiply two matrices of order l × m and m × n,

    then number of scalar multiplications required = l × m × n

    Data:

    A1 = 10 × 5, A2 = 5× 20, A3 = 20 × 10, A4 = 10 × 5

    Calculation:

    There are 5 ways in which we can multiply these 4 matrices.

    (A1A2)(A3A4) , A1A2(A3A4), A1 ((A2A3) A4) , (A1(A2A3))A4, ((A1A2)A3)A4

    Minimum number of scalar multiplication can be find out using A1 ((A2A3)A4)

    For A2A3 (order will become 5 ×10) = 5 × 20 × 10 = 1000

    For (A2A3)A4 (order will become 5 × 5) = 5 × 10 × 5 = 250

    For A1 ((A2A3)A4) [Order will become 10 × 5] = 10×  5 × 5 = 250

    Minimum number of scalar multiplication required = 1000 + 250 + 250 = 1500

    In all other cases, scalar multiplication are more than 1500.
  • Question 5
    1 / -0
    Consider a graph G(V, E) in which the V is the total number of vertices and E is the total number of edges in the graph. What is the total number of spanning tree of G in which V = 7 and E = 21?
    Solution

    Concept:

    A spanning tree is a subset of Graph G, which has all the vertices covered with a minimum possible number of edges. Spanning tree doesn’t have cycles and it cannot be disconnected.

    Formula:

    in a completed graph, number of spanning trees possible with V vertices = VV-2

    Calculation:

    number of vertices is 7

    In a complete graph

    \(|E| = \frac{V(V-1)}{2} = \frac{7(7-1)}{2} = 21\)

    Therefore G is a complete graph K7

    So, number of spanning trees possible = 77-2 = 75 = 16
  • Question 6
    1 / -0

    Consider two sequences A and B:

    A = <0,1,2,1,3,0,1 >

    B = <1,3,2,0,1,0 >

    If the length of the longest common subsequence x and number of longest common subsequence is y then the value of x3 + y3 + 3x2y + 3xy2 is _____ 
    Solution

    Concepts:

    If there is match, A[i, j] = A[i – 1, j  – 1] + 1

    If not match: max(A[i – 1, j], A[i, j – 1])

    Table of longest common subsequence:

     

    A

    0

    1

    2

    1

    3

    0

    1

    B

    0

    0

    0

    0

    0

    0

    0

    0

    1

    0

    0

    1

    1

    1

    1

    1

    1

    3

    0

    0

    1

    1

    1

    2

    2

    2

    2

    0

    0

    1

    2

    2

    2

    2

    2

    0

    0

    1

    1

    2

    2

    2

    3

    3

    1

    0

    1

    2

    2

    3

    3

    3

    4

    0

    0

    1

    2

    2

    3

    3

    4

    4

     

    Length of longest common subsequence = x = 4

    Possible longest common subsequence = 1301, 1201 and 1210

    ∴ y = 3

    x3 + y3 + 3x2y + 3xy2 = (x + y)3 = (4 + 3)3 = 343

  • Question 7
    1 / -0
    Consider a person having 1 rupee coin, 4 rupee coin, 5 rupee coin, 10 rupee coin, and 20 rupee coin. Assume a person have an infinite number of all such coins. What is the absolute difference between the minimum number of coins needed to take the sum of 78 using the Greedy method and Dynamic Programming?
    Solution

    Using Dynamic programming:

    20 rupee coin = 3 = 60 Rs

    10 rupee coin = 1 = 10 Rs

    4 rupee coin = 2 = 8 Rs

    Total coin = 3 + 1 + 2 = 6

    Using greedy approach

    20 rupee coin = 3 = 60 Rs

    10 rupee coin = 1 = 10 Rs

    5 rupee coin = 1 = 5 Rs

    1 rupee coin = 3 = 3 Rs

    Total coins = 8

    |8 - 6| = 2

Self Studies
User
Question Analysis
  • Correct -

  • Wrong -

  • Skipped -

My Perfomance
  • Score

    -

    out of -
  • Rank

    -

    out of -
Re-Attempt Weekly Quiz Competition
Selfstudy
Selfstudy
Self Studies Get latest Exam Updates
& Study Material Alerts!
No, Thanks
Self Studies
Click on Allow to receive notifications
Allow Notification
Self Studies
Self Studies Self Studies
To enable notifications follow this 2 steps:
  • First Click on Secure Icon Self Studies
  • Second click on the toggle icon
Allow Notification
Get latest Exam Updates & FREE Study Material Alerts!
Self Studies ×
Open Now