Data Structure and Algorithm 7 | Divide and Conquer

0_QXrDY4nVmhZ1umbX

1. Divide-and-Conquer Algorithm

(1) Definition

The divide-and-conquer algorithm recursively breaks down a problem two or more sub-problems of the same or related type, until these become simple enough to be solved directly. The solutions to the sub-problems are then combined to give a solution to the original problem.

(2) Pseudocode

(3) Review: Merge Sort

Time complexity .

Leetcode 912.

(4) Review: Quick Sort

Time complexity .

Leetcode 912.

(5) Valid BST

Given the root of a tree, return if it is a BST.

Leetcode 98.

(6) Search Matrix I

Search a target element in a sorted matrix. This is a binary search problem.

Leetcode 240.

(7) Search Matrix II

Search a target element in a matrix with both sorted columns and sorted rows. The idea is to device the matrix into smaller ones

Leetcode 240.