SlideShare a Scribd company logo
1 of 2
Download to read offline
1. Briefly state the Master Theorem.What type of problem is it useful for?
2. What is the balance condition of the AVL tree? Does this balance condition mean that the
depth of the highest and lowest leaves in the tree will be different by at most one?
3. Under what conditions does a BFS algorithm on Graphs work as a single source shortest path
algorithm?
Solution
1) Master Theorem :
A recurrence relation of the following form:
T(n) = c n < c1 = aT(n/b) + (n i ), n c1 Has as its solution:
1) If a > bi then T(n) = (n logb a ) (Work is increasing as we go down the tree, so this is the
number of leaves in the recursion tree).
2) If a = b i then T(n) = (n i logb n) (Work is the same at each level of the tree, so the work is the
height,logb n, times work/level).
3) If a < bi then T(n) = (n i ) (Work is going down as we go down the tree, so dominated by the
initial work at the root).
The Master method is a general method for solving (getting a closed form solution to) recurrence
relations that arise frequently in divide and conquer algorithms, which have the following form:
T(n) = aT(n/b) + f(n) where a 1, b > 1 are constants, and f(n) is function of non-negative integer
n. There are three cases.
(a) If f(n) = O(n logb a ), for some > 0, then T(n) = (n logba ).
(b) If f(n) = (n logb a ), then T(n) = (n logb a log n).
(c) If f(n) = (n logb a+ ) for some > 0, and af(n/b) cf(n), for some c < 1 and for all n greater than
some value n 0, Then T(n) = (f(n)).
2) An AVL tree has a balance condition such that each node stores the maximum depth of nodes
below it. A NULL tree has a level of -1 and a leaf node has a level of 0. A node having 1 or 2
subtrees will have as its own level the maximum of left or right subtree levels +1. Within an
AVL tree, the maximum difference allowed between left and right subtree levels is 1. When an
insertion or deletion operation results in this difference increasing to 2, rearrangements called
rotations are performed to reduce the imbalance for an AVL tree to retain the AVL balance
condition.
True. A heap is derived from an array and new levels to a heap are only added once the leaf level
is already full. As a result, a heap’s leaves are only found in the bottom two levels of the heap
and thus the maximum difference between any two leaves’ depths is 1. A common mistake was
pointing out that a heap could be arbitrarily shaped as long as the heap property (parent greater
than its children in the case of a maxheap) was maintained. This heap is not a valid heap, as there
would be gaps if we tried to express it in array form, heap operations would no longer have
O(log n) running time, and heap sort would fail when using this heap. Another common mistake
was simply justifying this statement by saying a heap is balanced. An AVL tree is also balanced,
but it does not have the property that any two leaves have depths that differ by at most 1.
3)
BFS can only be used to find shortest path in a graph if:
There are no loops
All edges have same weight or no weight.
To find the shortest path, all you have to do is start from the source and perform a breadth first
search and stop when you find your destination Node. The only additional thing you need to do
is have an array previous[n] which will store the previous node for every node visited. The
previous of source can be null.
To print the path, simple loop through the previous[] array from source till you reach destination
and print the nodes. DFS can also be used to find the shortest path in a graph under similar
conditions.
However, if the graph is more complex, containing weighted edges and loops, then we need a
more sophisticated version of BFS, i.e. Dijkstra's algorithm.

More Related Content

Similar to 1. Briefly state the Master Theorem.What type of problem is it usefu.pdf

Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02
Getachew Ganfur
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquer
chidabdu
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
zukun
 
Algorithm chapter 6
Algorithm chapter 6Algorithm chapter 6
Algorithm chapter 6
chidabdu
 

Similar to 1. Briefly state the Master Theorem.What type of problem is it usefu.pdf (20)

Trees in data structure
Trees in data structureTrees in data structure
Trees in data structure
 
Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02Sienna6bst 120411102353-phpapp02
Sienna6bst 120411102353-phpapp02
 
Review session2
Review session2Review session2
Review session2
 
How do you find the order of growth for the following recurrenceT.pdf
How do you find the order of growth for the following recurrenceT.pdfHow do you find the order of growth for the following recurrenceT.pdf
How do you find the order of growth for the following recurrenceT.pdf
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquer
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graph
 
Sorting
SortingSorting
Sorting
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
Q
QQ
Q
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graph
 
Skiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sortingSkiena algorithm 2007 lecture09 linear sorting
Skiena algorithm 2007 lecture09 linear sorting
 
data structures and algorithms Unit 2
data structures and algorithms Unit 2data structures and algorithms Unit 2
data structures and algorithms Unit 2
 
Boolean algebra1
Boolean algebra1Boolean algebra1
Boolean algebra1
 
Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
 
Trees
TreesTrees
Trees
 
(a) There are three ways to traverse a binary tree pre-order, in-or.docx
(a) There are three ways to traverse a binary tree pre-order, in-or.docx(a) There are three ways to traverse a binary tree pre-order, in-or.docx
(a) There are three ways to traverse a binary tree pre-order, in-or.docx
 
HeapSort
HeapSortHeapSort
HeapSort
 
Algorithm chapter 6
Algorithm chapter 6Algorithm chapter 6
Algorithm chapter 6
 
Answers withexplanations
Answers withexplanationsAnswers withexplanations
Answers withexplanations
 

More from sales98

Genetic evidence supports which of the following explanations for the.pdf
Genetic evidence supports which of the following explanations for the.pdfGenetic evidence supports which of the following explanations for the.pdf
Genetic evidence supports which of the following explanations for the.pdf
sales98
 
Evolution is driven by environmental that put selection pressure on o.pdf
Evolution is driven by environmental that put selection pressure on o.pdfEvolution is driven by environmental that put selection pressure on o.pdf
Evolution is driven by environmental that put selection pressure on o.pdf
sales98
 
e) As a practical matter, trade-offs of qualitative characteristics o.pdf
e) As a practical matter, trade-offs of qualitative characteristics o.pdfe) As a practical matter, trade-offs of qualitative characteristics o.pdf
e) As a practical matter, trade-offs of qualitative characteristics o.pdf
sales98
 
Define the role of the entrepreneur in the U.S. economy and describe.pdf
Define the role of the entrepreneur in the U.S. economy and describe.pdfDefine the role of the entrepreneur in the U.S. economy and describe.pdf
Define the role of the entrepreneur in the U.S. economy and describe.pdf
sales98
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
sales98
 
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdfalter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
sales98
 
2)Are enterprise information portals making executive information sy.pdf
2)Are enterprise information portals making executive information sy.pdf2)Are enterprise information portals making executive information sy.pdf
2)Are enterprise information portals making executive information sy.pdf
sales98
 
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdf
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdfWrite Java FX code for this pseudocode of the void initilizaHistoryL.pdf
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdf
sales98
 
Why is it that ozone is not desirable at the surface of earth, but i.pdf
Why is it that ozone is not desirable at the surface of earth, but i.pdfWhy is it that ozone is not desirable at the surface of earth, but i.pdf
Why is it that ozone is not desirable at the surface of earth, but i.pdf
sales98
 
Write a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdfWrite a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdf
sales98
 
What are the limitations of an expert systemSolutionLIMITATIO.pdf
What are the limitations of an expert systemSolutionLIMITATIO.pdfWhat are the limitations of an expert systemSolutionLIMITATIO.pdf
What are the limitations of an expert systemSolutionLIMITATIO.pdf
sales98
 

More from sales98 (20)

Genetic evidence supports which of the following explanations for the.pdf
Genetic evidence supports which of the following explanations for the.pdfGenetic evidence supports which of the following explanations for the.pdf
Genetic evidence supports which of the following explanations for the.pdf
 
Complete the following table for InvestmentsFair value method(s).pdf
Complete the following table for InvestmentsFair value method(s).pdfComplete the following table for InvestmentsFair value method(s).pdf
Complete the following table for InvestmentsFair value method(s).pdf
 
Find the values of the trigonometric functions of from the informat.pdf
Find the values of the trigonometric functions of  from the informat.pdfFind the values of the trigonometric functions of  from the informat.pdf
Find the values of the trigonometric functions of from the informat.pdf
 
Evolution is driven by environmental that put selection pressure on o.pdf
Evolution is driven by environmental that put selection pressure on o.pdfEvolution is driven by environmental that put selection pressure on o.pdf
Evolution is driven by environmental that put selection pressure on o.pdf
 
e) As a practical matter, trade-offs of qualitative characteristics o.pdf
e) As a practical matter, trade-offs of qualitative characteristics o.pdfe) As a practical matter, trade-offs of qualitative characteristics o.pdf
e) As a practical matter, trade-offs of qualitative characteristics o.pdf
 
Determine whether the relation defines y as a function of x. Give the.pdf
Determine whether the relation defines y as a function of x. Give the.pdfDetermine whether the relation defines y as a function of x. Give the.pdf
Determine whether the relation defines y as a function of x. Give the.pdf
 
Connor and his wife are guests at the hotel, having reserved a room .pdf
Connor and his wife are guests at the hotel, having reserved a room .pdfConnor and his wife are guests at the hotel, having reserved a room .pdf
Connor and his wife are guests at the hotel, having reserved a room .pdf
 
Define the role of the entrepreneur in the U.S. economy and describe.pdf
Define the role of the entrepreneur in the U.S. economy and describe.pdfDefine the role of the entrepreneur in the U.S. economy and describe.pdf
Define the role of the entrepreneur in the U.S. economy and describe.pdf
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
 
8. You may have heard that drinking soda or acid is bad for your teet.pdf
8. You may have heard that drinking soda or acid is bad for your teet.pdf8. You may have heard that drinking soda or acid is bad for your teet.pdf
8. You may have heard that drinking soda or acid is bad for your teet.pdf
 
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdfalter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
 
2)Are enterprise information portals making executive information sy.pdf
2)Are enterprise information portals making executive information sy.pdf2)Are enterprise information portals making executive information sy.pdf
2)Are enterprise information portals making executive information sy.pdf
 
5. How the tax system changes the distribution of income among capita.pdf
5. How the tax system changes the distribution of income among capita.pdf5. How the tax system changes the distribution of income among capita.pdf
5. How the tax system changes the distribution of income among capita.pdf
 
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdf
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdfWrite Java FX code for this pseudocode of the void initilizaHistoryL.pdf
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdf
 
Your name Date Explanation of Program -Modifying the first .pdf
Your name Date  Explanation of Program -Modifying the first .pdfYour name Date  Explanation of Program -Modifying the first .pdf
Your name Date Explanation of Program -Modifying the first .pdf
 
Why is it that ozone is not desirable at the surface of earth, but i.pdf
Why is it that ozone is not desirable at the surface of earth, but i.pdfWhy is it that ozone is not desirable at the surface of earth, but i.pdf
Why is it that ozone is not desirable at the surface of earth, but i.pdf
 
Write a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdfWrite a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdf
 
Which ape has been known to make territory patrols and wage war o.pdf
Which ape has been known to make territory patrols and wage war o.pdfWhich ape has been known to make territory patrols and wage war o.pdf
Which ape has been known to make territory patrols and wage war o.pdf
 
What are the limitations of an expert systemSolutionLIMITATIO.pdf
What are the limitations of an expert systemSolutionLIMITATIO.pdfWhat are the limitations of an expert systemSolutionLIMITATIO.pdf
What are the limitations of an expert systemSolutionLIMITATIO.pdf
 
Using the scenario provided in the Milestone One Guidelines and Rubr.pdf
Using the scenario provided in the Milestone One Guidelines and Rubr.pdfUsing the scenario provided in the Milestone One Guidelines and Rubr.pdf
Using the scenario provided in the Milestone One Guidelines and Rubr.pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 

Recently uploaded (20)

Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 

1. Briefly state the Master Theorem.What type of problem is it usefu.pdf

  • 1. 1. Briefly state the Master Theorem.What type of problem is it useful for? 2. What is the balance condition of the AVL tree? Does this balance condition mean that the depth of the highest and lowest leaves in the tree will be different by at most one? 3. Under what conditions does a BFS algorithm on Graphs work as a single source shortest path algorithm? Solution 1) Master Theorem : A recurrence relation of the following form: T(n) = c n < c1 = aT(n/b) + (n i ), n c1 Has as its solution: 1) If a > bi then T(n) = (n logb a ) (Work is increasing as we go down the tree, so this is the number of leaves in the recursion tree). 2) If a = b i then T(n) = (n i logb n) (Work is the same at each level of the tree, so the work is the height,logb n, times work/level). 3) If a < bi then T(n) = (n i ) (Work is going down as we go down the tree, so dominated by the initial work at the root). The Master method is a general method for solving (getting a closed form solution to) recurrence relations that arise frequently in divide and conquer algorithms, which have the following form: T(n) = aT(n/b) + f(n) where a 1, b > 1 are constants, and f(n) is function of non-negative integer n. There are three cases. (a) If f(n) = O(n logb a ), for some > 0, then T(n) = (n logba ). (b) If f(n) = (n logb a ), then T(n) = (n logb a log n). (c) If f(n) = (n logb a+ ) for some > 0, and af(n/b) cf(n), for some c < 1 and for all n greater than some value n 0, Then T(n) = (f(n)). 2) An AVL tree has a balance condition such that each node stores the maximum depth of nodes below it. A NULL tree has a level of -1 and a leaf node has a level of 0. A node having 1 or 2 subtrees will have as its own level the maximum of left or right subtree levels +1. Within an AVL tree, the maximum difference allowed between left and right subtree levels is 1. When an insertion or deletion operation results in this difference increasing to 2, rearrangements called rotations are performed to reduce the imbalance for an AVL tree to retain the AVL balance condition. True. A heap is derived from an array and new levels to a heap are only added once the leaf level is already full. As a result, a heap’s leaves are only found in the bottom two levels of the heap and thus the maximum difference between any two leaves’ depths is 1. A common mistake was
  • 2. pointing out that a heap could be arbitrarily shaped as long as the heap property (parent greater than its children in the case of a maxheap) was maintained. This heap is not a valid heap, as there would be gaps if we tried to express it in array form, heap operations would no longer have O(log n) running time, and heap sort would fail when using this heap. Another common mistake was simply justifying this statement by saying a heap is balanced. An AVL tree is also balanced, but it does not have the property that any two leaves have depths that differ by at most 1. 3) BFS can only be used to find shortest path in a graph if: There are no loops All edges have same weight or no weight. To find the shortest path, all you have to do is start from the source and perform a breadth first search and stop when you find your destination Node. The only additional thing you need to do is have an array previous[n] which will store the previous node for every node visited. The previous of source can be null. To print the path, simple loop through the previous[] array from source till you reach destination and print the nodes. DFS can also be used to find the shortest path in a graph under similar conditions. However, if the graph is more complex, containing weighted edges and loops, then we need a more sophisticated version of BFS, i.e. Dijkstra's algorithm.