0% found this document useful (0 votes)
66 views8 pages

Greedy Method Approach

1. Kruskal's algorithm is a greedy algorithm used to find the minimum spanning tree of a connected, weighted graph. It finds the MST by adding edges in order of increasing weight, skipping edges that would cause cycles. 2. The document provides a multiple choice quiz on algorithms including Huffman coding, Kruskal's algorithm, and other graph algorithms. It provides explanations for each answer. 3. The questions cover topics like time complexity of algorithms, applications of different approaches like greedy and divide-and-conquer, and determining optimal solutions from graph representations.

Uploaded by

Bhavin Vaghela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views8 pages

Greedy Method Approach

1. Kruskal's algorithm is a greedy algorithm used to find the minimum spanning tree of a connected, weighted graph. It finds the MST by adding edges in order of increasing weight, skipping edges that would cause cycles. 2. The document provides a multiple choice quiz on algorithms including Huffman coding, Kruskal's algorithm, and other graph algorithms. It provides explanations for each answer. 3. The questions cover topics like time complexity of algorithms, applications of different approaches like greedy and divide-and-conquer, and determining optimal solutions from graph representations.

Uploaded by

Bhavin Vaghela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Download our App for Study Materials and Placement Preparation 📝✅ | Click Here 

(https://play.google.com/store/apps/details?id=co.jones.cjzgt)

Get Latest Exam Updates, Free Study materials and Tips


Your Name
(https://lastmomenttu
Your Branch
itions.com/)
Year Of Engineering

[MCQ] Analysis Of Algorithms

Introduction (#1617622154105-59ec4c41-97a6)

Divide and Conquer Approach (#1617622154112-c1392ccd-f510)

Greedy Method Approach (#1617629753056-e13c69b7-cef6)

 Module 3

1. Which of the following algorithms is the best approach for solving Huffman codes?
a) exhaustive search
b) greedy algorithm
c) brute force algorithm
d) divide and conquer algorithm
Answer: b
Explanation: Greedy algorithm is the best approach for solving the Huffman codes problem since it greedily searches for an optimal solution.

2. How many printable characters does the ASCII character set consists of?
a) 120
b) 128
c) 100
d) 98
Answer: c
Explanation: Out of 128 characters in an ASCII set, roughly, only 100 characters are printable while the rest are non-printable.

3. Which bit is reserved as a parity bit in an ASCII set?


a) first
b) seventh
c) eighth
d) tenth
Answer: c
Explanation: In an ASCII character set, seven bits are reserved for character representation while the eighth bit is a parity bit.

4. How many bits are needed for standard encoding if the size of the character set is X?
a) log X
b) X+1
c) 2X
d) X2
Answer: a
Explanation: If the size of the character set is X, then [log X] bits are needed for representation in a standard encoding.
5. The code length does not depend on the frequency of occurrence of characters.
a) true
b) false
Answer: b
Explanation: The code length depends on the frequency of occurrence of characters. The more frequent the character occurs, the less is the length
of the code.

Crack Job Placement Aptitude in First Attempt

Prepare for Aptitude with 50+ Videos Lectures and Handmade Notes
Click Here! (https://lastmomenttuitions.com/aptitude/?ref=42057)

6. In Huffman coding, data in a tree always occur?


a) roots
b) leaves
c) left sub trees
d) right sub trees
Answer: b
Explanation: In Huffman encoding, data is always stored at the leaves of a tree inorder to compute the codeword effectively.

7. From the following given tree, what is the code word for the character ‘a’?

a) 011
b) 010
c) 100
d) 101
Answer: a
Explanation: By recording the path of the node from root to leaf, the code word for character ‘a’ is found to be 011.

8. From the following given tree, what is the computed codeword for ‘c’?

a) 111
b) 101
c) 110
d) 011
Answer: c
Explanation: By recording the path of the node from root to leaf, assigning left branch as 0 and right branch as 1, the codeword for c is 110.

9. What will be the cost of the code if character ci is at depth di and occurs at frequency fi?
a) cifi
b) ∫cifi
c) ∑fidi
d) fidi
Answer: c
Explanation: If character ci is at depth di and occurs at frequency fi, the cost of the codeword obtained is ∑fidi.
10. An optimal code will always be present in a full tree.
a) true
b) false
Answer: a
Explanation: An optimal tree will always have the property that all nodes are either leaves or have two children. Otherwise, nodes with one child
could move up a level.

Crack Job Placement Aptitude in First Attempt

Prepare for Aptitude with 50+ Videos Lectures and Handmade Notes
Click Here! (https://lastmomenttuitions.com/aptitude/?ref=42057)

11. The type of encoding where no character code is the prefix of another character code is called?
a) optimal encoding
b) prefix encoding
c) frequency encoding
d) trie encoding
Answer: b
Explanation: Even if the character codes are of different lengths, the encoding where no character code is the prefix of another character code is
called prefix encoding.

12. What is the running time of the Huffman encoding algorithm?


a) O(C)
b) O(log C)
c) O(C log C)
d) O( N log C)
Answer: c
Explanation: If we maintain the trees in a priority queue, ordered by weight, then the running time is given by O(C log C).

13. What is the running time of the Huffman algorithm, if its implementation of the priority queue is done using linked lists?
a) O(C)
b) O(log C)
c) O(C log C)
d) O(C2)
Answer: d
Explanation: If the implementation of the priority queue is done using linked lists, the running time of Huffman algorithm is O(C2).

14. Kruskal’s algorithm is used to ______


a) find minimum spanning tree
b) find single-source shortest path
c) find all pair shortest path algorithm
d) traverse the graph
Answer: a
Explanation: Kruskal’s algorithm is used to find the minimum spanning tree of the connected graph. It constructs the MST by finding the edge
having the least possible weight that connects two trees in the forest.

15. Kruskal’s algorithm is a ______


a) divide and conquer algorithm
b) dynamic programming algorithm
c) greedy algorithm
d) approximation algorithm
Answer: c
Explanation: Kruskal’s algorithm uses a greedy algorithm approach to find the MST of the connected weighted graph. In the greedy method, we
attempt to find an optimal solution in stages.

Python Programming for Complete Beginners

Start your Programming Journey with Python Programming which is Easy to Learn and Highly in Demand
Click Here! (https://lastmomenttuitions.com/complete-python-bootcamp/?ref=42057)

16.Consider the given graph.


What is the weight of the minimum spanning tree using the Kruskal’s algorithm?
a) 24
b) 23
c) 15
d) 19
Answer: d
Explanation: Kruskal’s algorithm constructs the minimum spanning tree by constructing by adding the edges to spanning tree one-one by one. The
MST for the given graph is,
Kruskal’s-algorithm-questions-answers-q3a

So, the weight of the MST is 19.

17. What is the time complexity of Kruskal’s algorithm?


a) O(log V)
b) O(E log V)
c) O(E2)
d) O(V log E)
Answer: b
Explanation: Kruskal’s algorithm involves sorting of the edges, which takes O(E logE) time, where E is a number of edges in graph and V is the
number of vertices. After sorting, all edges are iterated and union-find algorithm is applied. union-find algorithm requires O(logV) time. So, overall
Kruskal’s algorithm requires O(E log V) time.

18. Consider the following graph. Using Kruskal’s algorithm, which edge will be selected first?

a) GF
b) DE
c) BE
d) BG
Answer: c
Explanation: In Krsuskal’s algorithm the edges are selected and added to the spanning tree in increasing order of their weights. Therefore, the first
edge selected will be the minimal one. So, correct option is BE.

19. Which of the following edges form minimum spanning tree on the graph using kruskals algorithm?

Kruskal’s-algorithm-questions-answers-q5
a) (B-E)(G-E)(E-F)(D-F)
b) (B-E)(G-E)(E-F)(B-G)(D-F)
c) (B-E)(G-E)(E-F)(D-E)
d) (B-E)(G-E)(E-F)(D-F)(D-G)
Answer: a
Explanation: Using Krushkal’s algorithm on the given graph, the generated minimum spanning tree is shown below.
kruskals-algorithm-questions-answers-q6

So, the edges in the MST are, (B-E)(G-E)(E-F)(D-F).

20. Which of the following is true?


a) Prim’s algorithm can also be used for disconnected graphs
b) Kruskal’s algorithm can also run on the disconnected graphs
c) Prim’s algorithm is simpler than Kruskal’s algorithm
d) In Kruskal’s sort edges are added to MST in decreasing order of their weights
Answer: b
Explanation: Prim’s algorithm iterates from one node to another, so it can not be applied for disconnected graph. Kruskal’s algorithm can be
applied to the disconnected graphs to construct the minimum cost forest. Kruskal’s algorithm is comparatively easier and simpler than prim’s
algorithm.

Crack Job Placement Aptitude in First Attempt

Prepare for Aptitude with 50+ Videos Lectures and Handmade Notes
Click Here! (https://lastmomenttuitions.com/aptitude/?ref=42057)

21. Which of the following is false about Kruskal’s algorithm?


a) It is a greedy algorithm
b) It constructs MST by selecting edges in increasing order of their weights
c) It can accept cycles in the MST
d) It uses a union-find data structure
Answer: c
Explanation: Kruskal’s algorithm is a greedy algorithm to construct the MST of the given graph. It constructs the MST by selecting edges in
increasing order of their weights and rejects an edge if it may form the cycle. So, using Kruskal’s algorithm is never formed.

22. Kruskal’s algorithm is best suited for dense graphs than the prim’s algorithm.
a) True
b) False
Answer: b
Explanation: Prim’s algorithm outperforms the Kruskal’s algorithm in case of the dense graphs. It is significantly faster if graph has more edges
than the Kruskal’s algorithm.

23. Consider the following statements.


S1. Kruskal’s algorithm might produce a non-minimal spanning tree.
S2. Kruskal’s algorithm can efficiently implemented using the disjoint-set data structure.
a) S1 is true but S2 is false
b) Both S1 and S2 are false
c) Both S1 and S2 are true
d) S2 is true but S1 is false
Answer: d
Explanation: In Kruskal’s algorithm, the disjoint-set data structure efficiently identifies the components containing a vertex and adds the new
edges. And Kruskal’s algorithm always finds the MST for the connected graph.

24. Fractional knapsack problem is also known as __________


a) 0/1 knapsack problem
b) Continuous knapsack problem
c) Divisible knapsack problem
d) Non continuous knapsack problem
Answer: b
Explanation: Fractional knapsack problem is also called continuous knapsack problem. Fractional knapsack is solved using dynamic programming.
25. Fractional knapsack problem is solved most efficiently by which of the following algorithm?
a) Divide and conquer
b) Dynamic programming
c) Greedy algorithm
d) Backtracking
Answer: c
Explanation: Greedy algorithm is used to solve this problem. We first sort items according to their value/weight ratio and then add item with
highest ratio until we cannot add the next item as a whole. At the end, we add the next item as much as we can.

Python Programming for Complete Beginners

Start your Programming Journey with Python Programming which is Easy to Learn and Highly in Demand
Click Here! (https://lastmomenttuitions.com/complete-python-bootcamp/?ref=42057)

26. What is the objective of the knapsack problem?


a) To get maximum total value in the knapsack
b) To get minimum total value in the knapsack
c) To get maximum weight in the knapsack
d) To get minimum weight in the knapsack
Answer: a
Explanation: The objective is to fill the knapsack of some given volume with different materials such that the value of selected items is maximized.

27. Which of the following statement about 0/1 knapsack and fractional knapsack problem is correct?
a) In 0/1 knapsack problem items are divisible and in fractional knapsack items are indivisible
b) Both are the same
c) 0/1 knapsack is solved using a greedy algorithm and fractional knapsack is solved using dynamic programming
d) In 0/1 knapsack problem items are indivisible and in fractional knapsack items are divisible
Answer: d
Explanation: In fractional knapsack problem we can partially include an item into the knapsack whereas in 0/1 knapsack we have to either include
or exclude the item wholly.

28. Time complexity of fractional knapsack problem is ____________


a) O(n log n)
b) O(n)
c) O(n2)
d) O(nW)
Answer: a
Explanation: As the main time taking a step is of sorting so it defines the time complexity of our code. So the time complexity will be O(n log n) if
we use quick sort for sorting.

29. Fractional knapsack problem can be solved in time O(n).


a) True
b) False
Answer: a
Explanation: It is possible to solve the problem in O(n) time by adapting the algorithm for finding weighted medians.

30. Given items as {value,weight} pairs {{40,20},{30,10},{20,5}}. The capacity of knapsack=20. Find the maximum value output assuming
items to be divisible.
a) 60
b) 80
c) 100
d) 40
Answer: a
Explanation: The value/weight ratio are-{2,3,4}. So we include the second and third items wholly into the knapsack. This leaves only 5 units of
volume for the first item. So we include the first item partially.
Final value = 20+30+(40/4)=60.
Crack Job Placement Aptitude in First Attempt

Prepare for Aptitude with 50+ Videos Lectures and Handmade Notes
Click Here! (https://lastmomenttuitions.com/aptitude/?ref=42057)

31. The result of the fractional knapsack is greater than or equal to 0/1 knapsack.
a) True
b) False
Answer: a
Explanation: As fractional knapsack gives extra liberty to include the object partially which is not possible with 0/1 knapsack, thus we get better
results with a fractional knapsack.

32. The main time taking step in fractional knapsack problem is ___________
a) Breaking items into a fraction
b) Adding items into a knapsack
c) Sorting
d) Looping through sorted items
Answer: c
Explanation: The main time taking a step is to sort the items according to their value/weight ratio. It defines the time complexity of the code.

33. Given items as {value,weight} pairs {{60,20},{50,25},{20,5}}. The capacity of knapsack=40. Find the maximum value output assuming
items to be divisible and nondivisible respectively.
a) 100, 80
b) 110, 70
c) 130, 110
d) 110, 80
Answer: d
Explanation: Assuming items to be divisible-
The value/weight ratio are {3, 2, 4}.So we include the third and first items wholly. So, now only 15 units of volume are left for the second item. So
we include it partially.
Final volume = 20+60+50x(15/25)=80+30=110
Assuming items to be indivisible- In this case, we will have to leave one item due to insufficient capacity.
Final volume = 60 + 20 = 80.

Learn Machine Learning with Python from Scratch

Start your Machine learning & Data Science journey with Complete Hands-on Learning & doubt solving Support
Click Here! (https://lastmomenttuitions.com/python-with-machine-learning/?ref=42057)

Dynamic Programming Approach (#1617632450818-4e763a5a-bfbe)

Backtracking and Branch and bound (#1617635582320-a3acc518-42aa)

String Matching Algorithms (#1617638004246-75673406-edcf)


Prepare For Your Placements: https://lastmomenttuitions.com/courses/placement-preparation/ (https://lastmomenttuitions.com/courses/placement-
preparation/)
(https://lastmomenttuitions.com/course/python-zero-to-hero-covering-web-development-and-machine-learning-capstone-project-from-scratch-

included-mentorship/youtube-2/)

/ Youtube Channel: https://www.youtube.com/channel/UCGFNZxMqKLsqWERX_N2f08Q


(https://www.youtube.com/channel/UCGFNZxMqKLsqWERX_N2f08Q)

Follow For Latest Updates, Study Tips & More Content!

(https://lastmomenttuitions.com/course/python-zero-to-hero-covering-web-development-and-machine-learning-capstone-project-from-scratch-
included-mentorship/insta-1/)/lastmomenttuition (https://www.instagram.com/lastmomenttuition/)

(https://lastmomenttuitions.com/course/python-zero-to-hero-covering-web-development-and-machine-learning-capstone-project-from-scratch-
included-mentorship/link/)/ Last Moment Tuitions (https://in.linkedin.com/company/last-moment-
tuitions#:~:text=Last%20Moment%20Tuitions%20(LMT)%20is,others%20is%20its%20teaching%20methodology.)
(https://lastmomenttuitions.com/course/python-zero-to-hero-covering-web-development-and-machine-learning-capstone-project-from-scratch-
included-mentorship/twittrwer/)/ lastmomentdost (https://twitter.com/lastmomentdost)

You might also like