Top Banner
Transform & Conquer Replacing One Problem With Another Saadiq Moolla
18

Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Dec 17, 2015

Download

Documents

Raymond Rose
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Transform & Conquer

Replacing One Problem With

Another

Saadiq Moolla

Page 2: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Introduction

• Two Stage Solution−Transform into Another Problem−Solve New Problem

• Three Variations−Instance Simplification−Representation Change−Problem Reduction

Initial Problem

New Representati

on

Solution

Page 3: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Instance Simplification

• Reducing the Problem to a Simpler

One

• Techniques:−Presorting−Gaussian Elimination−Search Trees

Page 4: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Presorting

• Example: Given a random list of

numbers, determine if there are any

duplicates.

• Brute Force: Compare Every Pair

• Transform and Conquer:−Sort the List−Compare A [i] with A [i + 1] i

A

Page 5: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Presorting (Analysis)

• Old Idea, Many Different Ways

• Efficiency Dependant on Algorithm

• Compare Benefits vs Time Required

• Useful if Operation Repeated

Page 6: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Gaussian Eliminationa11x + a12x + … + a1nx = b1

a21x + a22x + … + a2nx = b2…

an1x + an2x + … + annx = b1

a’11x + a’12x + … + a’1nx = b’1

a’22x + … + a’2nx = b2…a’nnx = b1

Page 7: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Binary Search Trees8

415

7 91

5

Page 8: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Binary Search Trees (Analysis)• Time Efficiency

• Slow

• Methods to Balance

• Special Trees:−AVL Trees−B-trees

Page 9: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Heaps

• Type of Binary Tree

• Requirements:−Essentially Complete−Parental Dominance

9

5 7

4 2 1

Page 10: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Properties of Heaps

• Height is log2n

• Root is largest element

• Node + Descendents = Heap

• Stored in Array:−Children of A [i] are A [2i] and A [2i +

1]

Page 11: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Heap Insertion9

5 7

4 2 1 8

9

5

74 2 1

8

Page 12: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Heaps (Analysis)

• Sorting

• Priority Queue

• O (n log n)

Page 13: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Representation Change

• Change One Problem Into Another

• Steps:−Identify−Transform−Solve

• Mathematical Modeling

Page 14: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Problem Reduction

• Reduce to a Known Problem

• Use Known Algorithms:−Dijkstra’s algorithm−Horner’s Rule−Karp – Rabin algorithm−etc.

Page 15: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Horner’s Rule

• Used to Evaluate Polynomials

• 5x^2 – 3x + 8 » (5x + 3)x + 8

• 7x^3 + x^2 – 9x – 2 » ((7x + 1)x –

9)x – 2

• Linear

Page 16: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Horner’s Algorithmalgorithm Horner (x, P [])

// Evaluates a polynomial with coefficients P [] at xfor i ← n – 1 downto 0 do

v ← x * v + P [i]return v

Page 17: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Fast Exponentiation

• Evaluate x^n

• 2^10 = 2^10102 = 2^8 * 2^2

Page 18: Transform & Conquer Replacing One Problem With Another Saadiq Moolla.

Fast Exponentiation Algorithm

Algorithm FastExp (x, n)// Returns x^nterm ← xproduct ← 1while n > 0 do

if n mod 2 = 1 thenproduct ← product * term

term ← term * termn ← └ n/2 ┘

return product