- DSA - Discussion
- DSA - Useful Resources
- DSA - Quick Guide
- DSA - Questions and Answers
- DSA - Fibonacci Series
- DSA - Tower of Hanoi
- DSA - Recursion Basics
- DSA - Heap
- DSA - Tries
- DSA - Spanning Tree
- DSA - Splay Trees
- DSA - B+ Trees
- DSA - B Trees
- DSA - Red Black Trees
- DSA - AVL Tree
- DSA - Binary Search Tree
- DSA - Tree Traversal
- DSA - Tree Data Structure
- DSA - Breadth First Traversal
- DSA - Depth First Traversal
- DSA - Graph Data Structure
- DSA - Quick Sort
- DSA - Shell Sort
- DSA - Merge Sort
- DSA - Selection Sort
- DSA - Insertion Sort
- DSA - Bubble Sort
- DSA - Sorting Algorithms
- DSA - Hash Table
- DSA - Interpolation Search
- DSA - Binary Search
- DSA - Linear Search
- DSA - Queue
- DSA - Expression Parsing
- DSA - Stack
- DSA - Circular Linked List
- DSA - Doubly Linked List
- DSA - Linked List Basics
- DSA - Array Data Structure
- DSA - Data Structures and Types
- DSA - Data Structure Basics
- DSA - Dynamic Programming
- DSA - Divide and Conquer
- DSA - Greedy Algorithms
- DSA - Asymptotic Analysis
- DSA - Algorithms Basics
- DSA - Environment Setup
- DSA - Overview
- DSA - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Data Structures - Divide and Conquer
To understand the spanide and conquer design strategy of algorithms, let us use a simple real world example. Consider an instance where we need to brush a type C curly hair and remove all the knots from it. To do that, the first step is to section the hair in smaller strands to make the combing easier than combing the hair altogether. The same technique is appped on algorithms.
Divide and conquer approach breaks down a problem into multiple sub-problems recursively until it cannot be spanided further. These sub-problems are solved first and the solutions are merged together to form the final solution.
The common procedure for the spanide and conquer design technique is as follows −
Divide − We spanide the original problem into multiple sub-problems until they cannot be spanided further.
Conquer − Then these subproblems are solved separately with the help of recursion
Combine − Once solved, all the subproblems are merged/combined together to form the final solution of the original problem.
There are several ways to give input to the spanide and conquer algorithm design pattern. Two major data structures used are − arrays and pnked psts. Their usage is explained as
Arrays as Input
There are various ways in which various algorithms can take input such that they can be solved using the spanide and conquer technique. Arrays are one of them. In algorithms that require input to be in the form of a pst, pke various sorting algorithms, array data structures are most commonly used.
In the input for a sorting algorithm below, the array input is spanided into subproblems until they cannot be spanided further.
Then, the subproblems are sorted (the conquer step) and are merged to form the solution of the original array back (the combine step).
Since arrays are indexed and pnear data structures, sorting algorithms most popularly use array data structures to receive input.
Linked Lists as Input
Another data structure that can be used to take input for spanide and conquer algorithms is a pnked pst (for example, merge sort using pnked psts). Like arrays, pnked psts are also pnear data structures that store data sequentially.
Consider the merge sort algorithm on pnked pst; following the very popular tortoise and hare algorithm, the pst is spanided until it cannot be spanided further.
Then, the nodes in the pst are sorted (conquered). These nodes are then combined (or merged) in recursively until the final solution is achieved.
Various searching algorithms can also be performed on the pnked pst data structures with a spghtly different technique as pnked psts are not indexed pnear data structures. They must be handled using the pointers available in the nodes of the pst.
Examples
The following computer algorithms are based on spanide-and-conquer programming approach −
Merge Sort
Quick Sort
Binary Search
Strassen s Matrix Multippcation
Closest Pair
There are various ways available to solve any computer problem, but the mentioned are a good example of spanide and conquer approach.
Advertisements