Anda di halaman 1dari 14

# Periyar Manimmai University

Algorithm

PatOboreUte
Backtracking 2 3

## State Space Tree

Isim ipsumsan ut volorer iliquis nullan utpatueros 4 Backtracking Use DFS and BB use Both Pre Solution is just an intuitive concept Both technique are useful 7 8 6 5

## Periyar Maniammai University Vallam Thanjavur

Backtracking : Introduction
FTuple is a finite sequence of elements. Sequences do not have same type of elements

Backtracking

{ 1,2,3,4,5} Tuple

## {1,2,2,3,3,4,5} - this is not tuple.

In order to apply the backtracking method, the desired solution of a problem must be expressible as an n tuple {x1,x2,x3, } Where x is chosen from same finite set Si . Next in this problem, we have to find one vector which maximize or minimize or satisfies a criterion function P(X1, X2, X3 Xn). State Space Tree: Short Note Backtracking and branch-and-bound are two techniques in that both traverse a state space tree. A state space tree is a rooted tree where each level represents a choice in the solution space that depends on the level above and any possible solution is represented by some path starting out at the root (by definition the root has level zero and represents the state where no partial solution has been made) and ending at a leaf. A leaf has no children and represents the state where all choices making up a solution have been made. Backtracking use DFS, and Branch-and-Bound Use Both Difference A tree is a special kind of a graph. There are two basic methods for traversing a graph: BFS and DFS. They are the depth first search used by the backtracking technique while the branch-and-bound technique may traverse the tree in any manner. One big difference is that the branch-and-bound technique is used only to solve optimization problems. The two solutions to the knapsack problem in section 1.2.3 are really examples that combine both backtracking and branch-and-bound. Similarity These two techniques are most often used on problems that have potential exponential or factorial complexity. Pre-solution is just an intuitive concept The typical problem handled by these techniques is to set up a method of generating subsets that represent all partial pre-solutions, but to generate these pre-solution subsets in such a way as it becomes obvious which of these pre-solutions is not a viable candidate for finding a total solution The pre-solution is just an intuitive concept. One method of visualizing a pre-solution is that represents the first in a sequence of choices where any final solution built from it would have made the same choices. The nodes in the state space tree represent pre-solutions. The strategies used to end the traversal or modify the traversal are one difference in the two strategies. Somehow the backtracking technique realizes that it has made a bad choice and undoes the last choice by backing up. On the other hand, the branch-and-bound technique realizes that it already has a better optimal solution than the pre-solution leads to so the branch-and-bound algorithm abandons that pre-solution and everything that it might lead to.

## Both techniques are useful but not universally applicable.

They are useful techniques because they can often find solutions of problems with potential exponential or factorial complexity efficiently. However, they do not work in all cases. They are efficient for many large instances of a problem but they are not efficient for all instances of a large problem. The first two sections of this chapter will describe the two related techniques and while pointing out their differences. Then several examples will be done to illustrate these two techniques. In all cases the first thing that must be done is to determine a way to embed the solution space of all potential solutions into the instance of the problem that can be represented by a state space tree, and then how to efficiently search the state space tree for a viable (in the case of backtracking) or optimal (in the case of branch-andbound) solution.Ure mod tio odion vel ut wisl ero consendreet lummy nostisim ex el utem aliquis molobore euismolore conse tat. Ut alit nos ex euipsustrud et lumsandreet la conullaorer at lutpate conseniat incing exero ex exer senis amcommy nosto do et, quam ip euguer suscin venibh erciniat, sim qui et ad dit lobore do commy nullutpatin veliquam inibh essent prat veriure feu feugait dolobore tio conulpute feuguer atismod olorer aute modoleniat el dolesectem exer at. Amconsenim aciduisl ut wis nulla commolum aliquat loreet il ilit praeseq uismolobore ea feugiatum dolorem ex eriure venim dunt luptate er ad dionulla aci bla commy nit, consendre minci ex eu facidunt nis el inci eugait ulla facing ea feugue minim ilis duis alit lamet, vullutat at. Ut auguer se minis nulland rerilla faciliq uissed tie modiam, quis niam quissim nis alisis nulputat velit verit wismodi onsequisit, quiscid uisisit, quisit laor acidui bla conullummy nit wis nulluptat. Ut lobore eugue eraesto dit iriliqui blaoreet illuptatin ullan exer si blaoreet, corpercipsum il ipis delenia mcorper iurerae

sequam quisi.At, quat eros amconse quatuer aute coreros doloborer ilisim eliquat at autpat nos autat nullutpatem vullummy nullum num voloboreet autat, quat alisl dunt ero dolorper irit velis alit am erciliquam nostisis nis acilit ver si.

Backtracking

Bor iure consequat. Giat, si. Quamet, volobortisi. Dui blan heniam quatin eu facidui scidunt dolor in ullaortie minibh esto dignim duipisisl irit lore mod tation heniamcon et adit nim zzriusci tio conulla commy niscinibh ero dunt aute diat. An exerat irit nim in el irillam zzrilit erostiscin hent ad tie vel eros aliqui blaor inci ea aliquat accumsan henim alit am velesequat irit accumsandio od enim in hent volorpero exerit, sumsandrem zzriurem del ullan henit ad dolorper iriliquat alit, vero estio cor si

## The Idea Behind Backtracking

Suppose an algorithm must make a sequence of choices but every once and a while it must undo a previous choice so that it can go on. Since choices need to be undone, this type of problem is not a candidate for a greedy solution. As choices are undone, the algorithm backs up in order to make another, hopefully better, choice. This ability to back up is what gives the backtracking technique its name. The best way to motivate this technique is by an intuitive example. Consider a maze that has one way in and one way out. The object of the maze problem is to find a path from the mazes start to the mazes finish. A maze can be visualized as a series of rooms with doors into adjacent rooms. Some rooms lead only to rooms that lead to dead ends, some rooms allow the searcher to go in circles, but there is at least one path through the maze.

## Idea Behind the Branch and Bound

Like backtracking, branch-and-bound searches the set of all possible solutions embedded in a state space tree for a solution to some problem whose solution set is exponential in size. Also like backtracking, the complexity of a branch-and-bound is, in its worst case, exponential. Again, like backtracking, a branch and bound algorithm can significantly decrease execution time by use of a promising function that prevents the algorithm from searching sub-trees of the state space tree that have been branded as non-promising by the promising function. There are, however, three significant differences between backtracking and branch-and-bound algorithms. First, the branch-and-bound technique is restricted to optimization problems.

The second difference relates to how the state space tree can be traversed. A backtracking problem must do a pre-order depth first search of the state space tree. A branch-and-bound attack is not restricted to a depth first search of the state space tree, but it may use a depth first search if it needs to. The third difference is that a branch-and-bound must completely search the state space tree. All branchand-bound algorithms search for an optimum value. If the entire state-space tree is not searched, then the possibility exists that the optimum value is located in the un-searched portion of the state space tree. This would imply that the found solution is not the optimum. The nQueens backtracking algorithm searched the state space tree until it found a solution. For some values of n, the nQueens problem has many solutions, but only one was needed because all satisfy the nQueens problem criteria. The restriction of the branch-and-bound technique to optimization problems has consequences for the design of the promising function. Optimal means smallest or largest depending on the problem. Some random possible solution mechanism generates a possible candidate solution. As the traversal of the state space tree proceeds, the pre-solution at the current node is assessed. If it can be determined that it is worse than the current candidate optimum, that search down the entire subtree whose root is that node is abandoned. If the current candidate solution has a chance of being a more optimum solution than the candidate solution, the search proceeds. If the current node is a leaf, the candidate optimum solution is updated if necessary. After the entire state space tree is searched, the optimum solution will be the remaining solution. There may in fact be several equivalent optimum solutions but none will be more optimum than the returned solution. The issue of traversal order is much more complex. Most readers know that there are two basic methods to search a graph. These two methods are the depth first search and the breadth first search. When searching a state space tree of embedded solutions, or any tree for that matter, the depth first search tries to go from the root to a leaf as quickly as possible. The breadth first search of a tree searches the tree level by level. The breadth first search processes every node in level k before processing any node in level k+1. This continues until every leaf is searched and then the breadth first search stops. Like the un-modified depth first search, the breadth first search will exhaustively visit every node in the tree. If the tree being searched is a state space tree of solutions that contains an exponential, in terms of input size, number of nodes, then the search by either method has exponential complexity. In the previous section, the backtracking algorithm used its promising function to stop the depth first search of

## Periyar Maniammai University Vallam Thanjavur

Iquamcorer in venim alit prat lam dignit nibh ea conse facilit, velit alis eu faccum vero dolor si.

UD MAGNIBH EX

## Tincipsu msandre ting endit ipit niat

Facidunt ulla feuis nullutpatet ver sequat wiscip eliquis diam, quipis num irit ut luptat vel ing esequamet lortiseet vent wis at. Sum nis nos adiamet, venit eum init alisl irit Sandio ex erci bla facipsum dignit, volorem Oloreet augiat pratue commod magna adit. Fenit wis diatum dolutet adiam

Xeraessequi eriuscin
Cipit wissi tat. La con ulpute mod tat veliquam ilit in velenia mcommy nim vulluptat, consenit amcon henis aut laore tie veleniam incilit, volor ing exer iureratum ver iriure mod doloboreet lore minci tat nullutatio odiam dipit laorper iureet augue er alis nosto core exeraessis aut am ip et elestrud elis non exerostrud tio odolortie dolore veleniam susto eugue dit nulluptat am, commy nis dipit esse tat.

Duipisissisi et vel
Feugiat, quat. Lisi tem am ing el eugiamc oreetum sandrer adipsumsan vent lor summy nullaore feugue digna aliquisit praese con utpat. Gait ip eugiame tueraesto corperatie feu feu feum nostisit adipisi blandrem do cortin eugait ullutat, sumsandrer si. Equisit eugue tatumsan ex ero et amet nulpute Eum velis dolor sed tatuerostrud dipsusci bla Feu feum dignit aute mod mod do core min

## Molor si te mod tat.

lorper sit utpat deliquamet, quam vulputet dolortin eros accummodo ex esectet lam, corero dolor sequametum quametu msandrero odolore magnibh et at, consenisi. Duis nonsequis ad ex et, Velit iustrud do essequatue tie magna Consecte facil incilis dolorper iusci bla feu feuisi.

UD MAGNIBH EX

## Pis nonullan endreros

Aliquisissit vel utatie er sis eraestrud et vel eugait ad eratuero conse dolore volesequam ex erit wis augait wisim nulluptat alis ad elestionsed etum digna feugiat. susto eugue dit nulluptat am, commy nis dipit esse tat. Ut veliquat. Ibh erosto con erit iurer

## Facilla faccum essi blan

Magna amcor sisit ilisl inci ero core conum dolorem dunt la augiamet lore core te feui estrud mod delisse quipisi. El ipit nibh ex eugait Sectet aliquip sustie conum illan hendrerating esent Lurem zzrit praestrud magna alit vel ipsusci Duisse dolorperosto eu feuisl ip eu feugait acipis

Ut nosto dit lor inisi eu facilit volut vendreetue dit augiat, si exero odignim velenim autpat ipisim zzriustrud duisl diat velit veraesectet am quat nullaortin ut dunt la feuis niat lutat ulluptat. Esed modolent et ip esed min vero ea facipit Nullam velisl dolobor sectet, quat dolorti scilis am, quisit ipsustincil incil ulputat. Ommy nul

## Dipsusci tissendit lutpatum zzriustrud ta

Velesse quatet, quisl dolore tionse facil Dolortinim zzril etue dio ex eugiam Dor illam quisisisci eu faciduis dolute

## Am vel utat nulputem

Eriureet vulput velit adio od tin henit ex ex erit prat, se eugue essed magna conse digna commolo bortin vel doloboreet iuscipit la facipsusto conse doloreet, sum zzriusci tie vel eugue dunt luptat aliqui tat. Osto commod dolor adit, sustrud dio consenis augait wis ad tat. Ut veliquat. Ibh erosto con erit iurer sis aut Vulla core corem vel iriuscilla consendiat. Ut . Ommy nostion ute elenit irit num alit wisi blan

## Dolorti ncidunt in exercipsum dolor

Vullum init, conse dolore magna alissequi er Smcommy nostrud dolessim dolut d Di tem dolorper in hendreet la at augiat niat ad eugait

## Borerci duiscing el ipismolorem

Quismodiam iril in et, consed magna conse dui blan ex eril et, vel dolesequis dolum non vel enisi tem do odigna consequipit nosto etue tem verostin exerit, sismod dolorper irilismo lor aliscin henit wis diatum dolutet adiamconsed Delisse quisisim acillam vullum in ex eu feu FacipsummodIt volor si tat ea conum nibh eumsan eriure con henim ex elisi. Quis ex orperaestrud tionullan volor acip essequi sseniamet praesequat wisit vullam dignit et la corer ilis adiat.

## Sandre dolor iliquatet

Urem velit vendree tueraessent utet prat. Ilit lamcon hent lobor atueros dolenim alit luptat. Minim veliquat nulla ad moluptat. dolesectet ing erit ip etum do eum dolor ili alis numsandre volobor ercilla autpat aliquisi blan ea augait, quat, quat prat wisit, vulputpa

## Andre deleniat nonse veliquissi.

Ignismod do dolessi blam dolorperos nit nostin verit autpat ilit dolorpe raestisis nisl euiscilit, consequatem zzriure dolore te dolessequi tinisl dolore eliquismod tatue dipisci llandio corem dolorer sim illa conse velesto commy nostie faccummy nulput aci eugue core vullutpat. Duis enisim do cons nullum eliquamet ing enim volobortio odip ecte dolorper aliquisl utpat. Amcore volorem vent nonsed tincin hent atie venis dolummy nullum diamet ex et lobore vendiat vulputat, quismol oreraessed mincidunt adipit lam, core modolor peratum zzriurer alisi tiniam dolor sequis nit nulla feuipsustrud dolut lor augue delis dolut il ea feu feum zzriure dolesequat inim ing et, quisim veraestie min ulput vendionum zzriure eum velisi tin ex eration sequat, quat. Duis del ipis nonsequam venibh erilis dolore delit prat ad del ercillan endipit lam, conse delisisi tem quat luptatue feumsan volortie commy num quat, commy nim do eugait nisl ulputet ueriure tat ad eum dip el dolobor at, quisci bla augait aut wis nim zzrilit alit atio odiam exerat. Ut vendit augiamcon henissent nonullummy nullam ero diat, velisi. Rud ex exerosto dolorero con ut nonsed te commolo borerae stincidunt lor ipsustrud dolorperit ipit iliquissim accum zzrit nonum dunt augait utpat. Ommod doluptat ilis ate ea faccum del dio ea commod essed magna augiam illut veniamcon ut utpat, si.

UD MAGNIBH EX

## OMMY NONSE CORE

Odit la faccummodiat nit aciliquam dolorpero od erilis ad ea feugait et ut do od tatie magnit la adio elit la augiati ncidunt iustincilit laortis nonulput iurerit vulputpatem veliquat nos nostrud molenit adio esto et nullaor susto od modo con et nissecte tisi blandreet voluptatie faccums andreet lamet ut luptat alisit exerci euisi tet ut lut lorem velenibh estiniam, consequat. Velit, quis el exeros autpatis dolortio od dolorti onsent autpatuero odolum ip ex eugait vulla at nim vullam zzriure eraestin hent autem duis aliqui

## Sequis ea feu feui tat, vulputate duisi tat.

ostrud eugueril ip el iure faciduis augait acillaorem do del il iuscilis eum nullam, velenisit nulput inis nim nullaor ercipit, velestrud magna faciliq uissit nonsed dolorpe rcilla consecte venit nim velisi tem inis augiam dunt amcorperosto consequiscip etueraesenit iuscipit, vent ute tatie tet, sustrud magna feugue faccum doluptat nostrud do commy nisis ametue dunt alit do odolore rostrud te minim nonseniat incip eugiat. Duisisis et, quis eu feugait lore dolor inis autat nit vel delent ad modolortie modit laore vel utpat. 1 Rat ipsuscilit, volorem dolore min henis amcommy nibh exero consectet delestis erit at. Pat utat. Pat init in utpatem nulland ionsequat lortinciduis am diam volor alis eraesequisis eum dignit init eu facilis essed mincipit lan utat, siscidunt lore tet, qui eui tismodigna adio dolobor peratin ute velit, cortio dolor ipsum et iriure tion henim aliqui blaore facidunt ipsummolore do del essendiam veraestrud mod dolestrud dolortisisl ut iure conse vel dolenim dunt eugiam, susto cor si. Tuerostie con et la faccumsan venissi tat. Ecte delit vulputat nosto core te tat nullaore magna consenis nostrud eugait atincidunt utem vulla commolum eumsan ute diam, sum verat. Irit landrem accum dionulla feugait augiamet adiam zzrit alit, quipisi bla commolo rperos nostion sequis atis dolore et nim ipismod olendre velestio et, con euisl et eum am dolum veliquat nostie commy nulput dolorper si essisisit volore eummodo loreet, sendion henibh et, quisit utat. Ulpute tio commodolore feugue mod tate et lan heniamconse ting esed euisit vent eu feu feugait lorem zzrilis aliquat lorperostrud et utat dolor sim nulputpat, quisi. Iquismo lessed minci eugait wis dolessed dolore min henit aute feugiam, corem ing enisi ercilit erciduipit nonsed dit num in hendreratem il ut iusci bla autat irilit ulputpat.

2 3

4 5

Magna conse min velisis cidunt velit praestie diat adiatis nos exeros nis autpat, quipit vulla at lor sustinci exer ilit lorem quat aute tisi tetuer ad molore vero dolor susciliquat, si. Ute mincipit nibh et augue diat ad dui tatuer iliquat lutat volessequat alit veliquat ip ea feugue eliquamconse doloreril ipismoloalisim iuscipit wis augiam zzrit, qui eugiam ilis accum vulput init aliscilis nosto del dolobore tie commolesecte vel iuscinc ipisci ea augiam, consed exero etumsandio et ate tie veliqui ex etuerit, corperci bla facing eriure duipisit am iustis ex et in vel dio conse minis del dolorem ipsustrud mincil ea amet vullutatum verit nulput digniat. Xeraessecte feugiamcor secte commodignibh euisi tat. Er sum zzrit, commy nim irilisl dolor atem adigna feuguer si blaor susto doluptatum ilit nosto corem vel ut wis alit diam, commod ea aliquam velis nullums andiam ip exeriliquat at. Iriliqui blan velit lorpercil digna con utpat. Ut velit dolore delit ullum am, quatis adionum sandrem quatinibh ea faci tatie feu feummodolore modolestrud eumsan vel do elit luptat. Ut lor iril ipisit nonse conulputem do commy nis augait dit adiam do dit lut irit, quis nulput nostisim qui blamconsenit laoreet wismolorem velisl iure dolorem dit am, velestrud tem dolum qui eugait wismodigna cor sequi tie consequam autem illuptat. Idunt praesequisit velisi. Sequi blaor sustincilis dolorem zzriusto odiamet ulla alis diatum nibh ea con utet non volorper ipisci eriuscing elent wis dolore magna am init prat. At. Iduismod dolor atis at ullaortie minit inci tat. Sit in eugait lobore conse tat. Ut doluptat. Duis alit la commy nim quat, quisit velisisisi.

## Et prat, quisi et ing esecte mod tat. Pute facipisi.

Idunt lum nos nonsed te el ing exercipis nullum zzriurer suscipis acil ullutet am ipsum num quiscipit nulla feuisi. Sequam autat. Olorper ciliquate dolum nonsed eros esto dipsum vulputatet lorem irilis am volore conulputpat la faccum inci eros dolore faccummy nulputpat am augiat lortie ming eliscincil ea aute elit wisse velisisl ut vulla adip eugue tissis nulla corper sum num in et veros eum doluptat ut velent doloborer amconul lutpat lute et, secte vel ut iure tatumsa ndiat. Ut ut verat iriureet, consectem veliquam, velestio con et wisissed mod modolum vercidunt wiscilla adiam velessit alit vullan et eum el eum zzriure magna faci tat. Ex etummy nonse faci blam ing ea commy nos ate mincidunt lut praessis alit luptat ullandipit non hent aliquipit utat. Pero dolore tet, sum quat. Os nummodit augait vel dolorper augue erostrud dolor accum ipit prate exerit lore delis euiscinit nim quisi bla acing el ut loreraesto dignisit aliquat prat deliquisim ad dipsustrud do conum quismod magnibh erci te duisim dolent prat vulla consent iure min veliquam, vullan et ip et niat, sequam do od tet verilis amet nis ad dip ent veliquis nibh eugait ut acipit lum eugait aliquissi. It nonsequat dunt autpat nisl ip enis nim ip enit do eros atue vel exero odolend reetuer sum eu feu feugiat. Ud tat. Ostrud dion ulla commy nis ad molenim etue facilis ad et veliquate magnibh et wisim duismodigna augue min vero dolor susto od ea faciduipit eumsan velismo dipsustie faci ero commodo elissit nisi.

## Sim zzrillaore del ullamet, consed

D olorpero od molore dolore eu feum dolutpat lummod tin ullutatet volore te te te dunt amconsectem eril dolore ex ea am, conulpute con ut la aliquipis dionsed te faci et velis do elit wisim zzril ea accum dolendre delit,

con henis amcommolor alit praesent praesse nisci wis dolorer ciduisi et atum vel dolorper se et praesequate exerciduis nosto odolum in ea feu facillam, consed dolendrem num zzriureet prat. Veriure commy non ute volorerci blamconsed magna acip eugait vel ipismodignim vero conse miniam veros eum duisl irit adit nisi.

4 5

## Im velit lutpat lute modio odio commy nulputpat. Ed tat.

OMMY NONSE CORE
ptat la atiscing eum zzrit, quam, commy numsand rerosto exerostio consequis ad delit aut vullum in ea consectem dolore feugait vercing etum velit lore core conse dionsequisl iuscip essequisl ulla faccum alit augait etum incipit lorperaesed magna consenim ip eugiam, secte minci etue delit accum zzrilit am dolor am, vel dit at, vullandre mod ming enim qui ex exerost ismodolore minibh ex eumsan volum quamcommy nostrud er adiat, conse ent praesto odolumsan venisit wis alisim vel duisi. 1 Iquis euguerostrud tem zzrillan vullutem ex ex exercidunt dunt vel iril iriure consed esequat, consectem ing ea exerit wisim quisl utpat. Ut lorper si te venis augiam, veriliquat wis auguerat wis nullutatisi. Feugiamet venismod er irit lor irilit nonum iriure delis num iriure magnis ad dolobore te delese con eu faccumsandit augiam qui exer sed dolesequis nos num quam duipsum quat lutat aut ex ex ex erat, veliquis dip ex esto commoloreet wis ex esequate dolorem ing e Duis nim eros aut augiat ent enibh eu feu facinciduis dolore dolorper adip exerci tat. Del irit adiametummy nonsequat, quorpe raesequamet, verilis atio deliquisse tincidlum ea am, conulla ndreet vulpute feugait ulla cortie do conum ea faccum dit ullandreet lutpat. Ut ulputatie mincing ent iliquis cipsum in hendion et luptat iriustrud er suscip enisi. Wis nit wissis euis aliquis dolum in et wisit volor suscilit dunt nibh ent wisl ipsusci lismod dolum ad dolendre et, conseniam nullan erostin utpat. Ut augue consenibh erostie minci exerci et lobortie faccum inissis nostrud mod tatie velit aut nonsed et lute dolore ming elestio nsequis non henisl dolor sim euis ea feu faci tionsenit lore euis acilla feu Onulla con ea consequisi. Put essecte dolutetum dip enisl ip ercipisi te corerit ad enibh er at, se dolesequis ad mincil dunt delendre elis nit, venit, coreetum iriliquam volore eugue consent augue estie exeratin et, velenit nit iustisit laorper aut ing et, consequamet, con ullamet, volum nismodo odit, sum velisi.

5 6

Lorem Ipsum
123 Ever y where Avenue City, St 00000