SlideShare a Scribd company logo
1 of 13
1, Write algorithm of queue and find the time complexity …?
Queue Representation
As we now understand that in queue, we access both ends for different reasons.
The following diagram given below tries to explain queue representation as data structure −
As in stacks, a queue can also be implemented using Arrays, Linked-lists, Pointers and Structures. For the
sake of simplicity, we shall implement queues using one-dimensional array.
Cont’ …
 Few more functions are required to make the above-mentioned queue operation efficient. These are −
peek() − Gets the element at the front of the queue without removing it.
isfull() − Checks if the queue is full.
isempty() − Checks if the queue is empty.
In queue, we always dequeue (or access) data, pointed by front pointer and while enqueing (or storing)
data in the queue we take help of rear pointer.
Let's first learn about supportive functions of a queue −
peek()
 This function helps to see the data at the front of the queue. The algorithm of peek() function is as follows −
Algorithm
begin procedure peek
return queue[front]
end procedure
Cont’…
isfull()
 As we are using single dimension array to implement queue, we just check for the rear pointer to reach
at MAXSIZE to determine that the queue is full. In case we maintain the queue in a circular linked-list,
the algorithm will differ. Algorithm of isfull() function −
Algorithm
begin procedure isfull
if rear equals to MAXSIZE
return true
else
return false
endif
end procedure
Cont’…
isempty()
Algorithm of isempty() function −
Algorithm
begin procedure isempty
if front is less than MIN OR front is greater than rear
return true
else
return false
endif
end procedure
If the value of front is less than MIN or 0, it tells that the queue is not yet initialized, hence empty.
2, Write algorithm of quick sort and find the time complexity …?
 Quicksort is a divide-and-conquer algorithm. It works by selecting a 'pivot' element from the
array and partitioning the other elements into two sub-arrays,
according to whether they are less than or greater than the pivot. For this reason, it is sometimes
called partition-exchange sort.
Cont’…
Complexity Analysis
The Best case time complexity of this Quick Sort algorithm is O(nlogn), the Worst case time complexity of
this algorithm is O(nlogn). Analysis of this complexity is described below:
Time Complexity
 Time taken by quicksort, in general, can be written as follows:
T(n)=T(k)+T(n−k−1)+(n)
Here, the first two terms are the two recursive call and the last term is the partition of n elements. The time
taken by this algorithm depends on the input of the array and the partition process.
Best Case Analysis
 The best-case occurs the algorithm is conducted in such a way that always the median element is selected as the
pivot and thus reduces the complexity. The following time is taken for the best case.
 T(n)=2T(n/2)+(n)
The solution of the above recurrence is O(nlogn).
Average Case Analysis
 In average case analysis, we need to consider all possible permutations of an array and calculate the time taken by every
permutation. The average case is obtained by considering the case when partition puts O(n/9) elements in one part and O(9n/10)
elements in other parts. The following time is taken for this:
T(n)=T(n/9)+T(9n/10)+O(n)
Although the worst-case time complexity of Quick Sort is O(n2)
Worst Case Analysis
 The proposed algorithm gives a better running time than a classical quick sort algorithm. The pivot selection procedure is
repeated for each iteration of the quick until the size of the array becomes less than or equal three. In this case, we go for a
manual sort where we compare two elements normally. There might be a situation where a worst-case partitioning will be
required. When the array will be already sorted or sorted in descending order then worst case partitioning will be needed. Thus
mean is calculated and it always comes between extreme values, so, partitioning splits the list into 8-to-2. Thus, the time taken
for the proposed algorithm is
T(n)=T(8n/10)+T(2n/10)+cn
Worst Case Time Complexity [ Big-O ]: O(n )
3, Write Merge sort algorithm and its time complexity …?
 Merge Sort follows the rule of Divide and Conquer to sort a given set of numbers/elements, recursively,
hence consuming less time
 Merge sort , on the other hand, runs in O(n*log n) time in all the cases.
 Divide and Conquer
 If we can break a single big problem into smaller sub-problems, solve the smaller sub-problems and combine
their solutions to find
 the solution for the original big problem, it becomes easier to solve the whole problem.
Complexity Analysis of Merge Sort
 Merge Sort is quite fast, and has a time complexity of O(n*log n) .
 It is also a stable sort, which means the "equal" elements are ordered in the same order in the sorted list.
 Worst Case Time Complexity [ Big-O ]: O(n*log n)
 Best Case Time Complexity [Big-omega]: O(n*log n)
Cont…
4, Write heap sort algorithm and its time complexity …?
 Heap is a special tree-based data structure that satisfies the following special heap properties:
 Shape Property: Heap data structure is always a Complete Binary Tree, which means all levels of
the tree are fully filled.
 Heap Property: All nodes are either greater than or equal to or less than or equal to each of
its children. If the parent nodes are greater than their child nodes, heap is called a Max-Heap, and if
the parent nodes are smaller than their child nodes, heap is called Min-Heap.
Cont…
 Complexity Analysis of Heap Sort
 Worst Case Time Complexity: O(n*log n)
 Best Case Time Complexity: O(n*log n)
 Average Time Complexity: O(n*log n)
 Space Complexity : O(1)
 Heap sort is not a Stable sort, and requires a constant space for sorting a list.
 Heap Sort is very fast and is widely used for sorting

More Related Content

Similar to algorithm assignmenteeeeeee.pptx

Module 1 notes of data warehousing and data
Module 1 notes of data warehousing and dataModule 1 notes of data warehousing and data
Module 1 notes of data warehousing and datavijipersonal2012
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.pptLegesseSamuel
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 
Chp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdfChp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdfSolomonMolla4
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxPJS KUMAR
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematicalbabuk110
 
Tri Merge Sorting Algorithm
Tri Merge Sorting AlgorithmTri Merge Sorting Algorithm
Tri Merge Sorting AlgorithmAshim Sikder
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0BG Java EE Course
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2Kumar
 
DATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxDATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxShivamKrPathak
 
Selection_Sort-CSI (For Sharing and General )
Selection_Sort-CSI (For Sharing and General )Selection_Sort-CSI (For Sharing and General )
Selection_Sort-CSI (For Sharing and General )phukak12345
 

Similar to algorithm assignmenteeeeeee.pptx (20)

Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Module 1 notes of data warehousing and data
Module 1 notes of data warehousing and dataModule 1 notes of data warehousing and data
Module 1 notes of data warehousing and data
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
Sorting
SortingSorting
Sorting
 
Chp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdfChp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdf
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptx
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Tri Merge Sorting Algorithm
Tri Merge Sorting AlgorithmTri Merge Sorting Algorithm
Tri Merge Sorting Algorithm
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
 
DATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxDATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptx
 
Cis435 week04
Cis435 week04Cis435 week04
Cis435 week04
 
Selection_Sort-CSI (For Sharing and General )
Selection_Sort-CSI (For Sharing and General )Selection_Sort-CSI (For Sharing and General )
Selection_Sort-CSI (For Sharing and General )
 
Ada notes
Ada notesAda notes
Ada notes
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Ln liers
Ln liersLn liers
Ln liers
 
test1
test1test1
test1
 

Recently uploaded

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
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 CAPSAnaAcapella
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 

Recently uploaded (20)

OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
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
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 

algorithm assignmenteeeeeee.pptx

  • 1.
  • 2. 1, Write algorithm of queue and find the time complexity …? Queue Representation As we now understand that in queue, we access both ends for different reasons. The following diagram given below tries to explain queue representation as data structure − As in stacks, a queue can also be implemented using Arrays, Linked-lists, Pointers and Structures. For the sake of simplicity, we shall implement queues using one-dimensional array.
  • 3. Cont’ …  Few more functions are required to make the above-mentioned queue operation efficient. These are − peek() − Gets the element at the front of the queue without removing it. isfull() − Checks if the queue is full. isempty() − Checks if the queue is empty. In queue, we always dequeue (or access) data, pointed by front pointer and while enqueing (or storing) data in the queue we take help of rear pointer. Let's first learn about supportive functions of a queue − peek()  This function helps to see the data at the front of the queue. The algorithm of peek() function is as follows − Algorithm begin procedure peek return queue[front] end procedure
  • 4. Cont’… isfull()  As we are using single dimension array to implement queue, we just check for the rear pointer to reach at MAXSIZE to determine that the queue is full. In case we maintain the queue in a circular linked-list, the algorithm will differ. Algorithm of isfull() function − Algorithm begin procedure isfull if rear equals to MAXSIZE return true else return false endif end procedure
  • 5. Cont’… isempty() Algorithm of isempty() function − Algorithm begin procedure isempty if front is less than MIN OR front is greater than rear return true else return false endif end procedure If the value of front is less than MIN or 0, it tells that the queue is not yet initialized, hence empty.
  • 6. 2, Write algorithm of quick sort and find the time complexity …?  Quicksort is a divide-and-conquer algorithm. It works by selecting a 'pivot' element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. For this reason, it is sometimes called partition-exchange sort.
  • 7. Cont’… Complexity Analysis The Best case time complexity of this Quick Sort algorithm is O(nlogn), the Worst case time complexity of this algorithm is O(nlogn). Analysis of this complexity is described below: Time Complexity  Time taken by quicksort, in general, can be written as follows: T(n)=T(k)+T(n−k−1)+(n) Here, the first two terms are the two recursive call and the last term is the partition of n elements. The time taken by this algorithm depends on the input of the array and the partition process. Best Case Analysis  The best-case occurs the algorithm is conducted in such a way that always the median element is selected as the pivot and thus reduces the complexity. The following time is taken for the best case.  T(n)=2T(n/2)+(n) The solution of the above recurrence is O(nlogn).
  • 8. Average Case Analysis  In average case analysis, we need to consider all possible permutations of an array and calculate the time taken by every permutation. The average case is obtained by considering the case when partition puts O(n/9) elements in one part and O(9n/10) elements in other parts. The following time is taken for this: T(n)=T(n/9)+T(9n/10)+O(n) Although the worst-case time complexity of Quick Sort is O(n2) Worst Case Analysis  The proposed algorithm gives a better running time than a classical quick sort algorithm. The pivot selection procedure is repeated for each iteration of the quick until the size of the array becomes less than or equal three. In this case, we go for a manual sort where we compare two elements normally. There might be a situation where a worst-case partitioning will be required. When the array will be already sorted or sorted in descending order then worst case partitioning will be needed. Thus mean is calculated and it always comes between extreme values, so, partitioning splits the list into 8-to-2. Thus, the time taken for the proposed algorithm is T(n)=T(8n/10)+T(2n/10)+cn Worst Case Time Complexity [ Big-O ]: O(n )
  • 9. 3, Write Merge sort algorithm and its time complexity …?  Merge Sort follows the rule of Divide and Conquer to sort a given set of numbers/elements, recursively, hence consuming less time  Merge sort , on the other hand, runs in O(n*log n) time in all the cases.  Divide and Conquer  If we can break a single big problem into smaller sub-problems, solve the smaller sub-problems and combine their solutions to find  the solution for the original big problem, it becomes easier to solve the whole problem. Complexity Analysis of Merge Sort  Merge Sort is quite fast, and has a time complexity of O(n*log n) .  It is also a stable sort, which means the "equal" elements are ordered in the same order in the sorted list.  Worst Case Time Complexity [ Big-O ]: O(n*log n)  Best Case Time Complexity [Big-omega]: O(n*log n)
  • 11. 4, Write heap sort algorithm and its time complexity …?  Heap is a special tree-based data structure that satisfies the following special heap properties:  Shape Property: Heap data structure is always a Complete Binary Tree, which means all levels of the tree are fully filled.  Heap Property: All nodes are either greater than or equal to or less than or equal to each of its children. If the parent nodes are greater than their child nodes, heap is called a Max-Heap, and if the parent nodes are smaller than their child nodes, heap is called Min-Heap.
  • 12.
  • 13. Cont…  Complexity Analysis of Heap Sort  Worst Case Time Complexity: O(n*log n)  Best Case Time Complexity: O(n*log n)  Average Time Complexity: O(n*log n)  Space Complexity : O(1)  Heap sort is not a Stable sort, and requires a constant space for sorting a list.  Heap Sort is very fast and is widely used for sorting