Parent note padhne se pehle, usmein use kiya gaya har notation tumhe clear hona chahiye. Ye page har cheez absolute zero se build karta hai — pehle plain words, phir picture, phir kyun is topic ko yeh chahiye. Upar se neeche padho; har block uske upar wale par lean karta hai.
Neeche diya picture dekho. 4 dots (cities) hain jo lines (roads) se jude hain. Red loop ek possible tour hai; aur bhi bahut hain. Hum sabme se sabse sasta loop chahte hain.
Picture: n dots kagaz par. Unhe "Paris, Rome…" ki jagah 0..n−1 naam dena aalas nahi hai — iska matlab hai city ka naam directly ek index hai jo hum array mein seedha daal sakte hain. Yahi aadat code ko chhota rakhti hai.
Why the topic needs it
neeche har loop aur har array size n ke terms mein likha hai.
Yahi trick hai jis par poori technique ka naam hai. Hume ek set of cities ko array index ki tarah use karna hai, aur array indices plain integers hone chahiye. Set ko ek single number mein kaise pack karein?
Why the topic needs it
integer sabse sasta possible array index hai, aur n cities ke liye exactly 2n hote hain — DP table ka doosra index.
Hum mask ko light switches ki ek row jaisa sochtey hain, har city ke liye ek. Ye chaar moves hi hum kabhi use karte hain. Yahan &, |, ~har bit position par independently kaam karte hain.
In operators ko poori generality mein dekhne ke liye Bit Manipulation dekho.
Ab parent ke central definition mein har symbol earn ho chuka hai:
Yahi parent ka mnemonic SET + SPOT hai — do indices, ek kaun si cities ke liye, ek tum kahan ho ke liye. Branch and Bound usi TSP par alag tarike se attack karta hai (pruning se), lekin Held–Karp is table ko exhaustively aur cleverly fill karta hai.
City i se city j jaane ki cost; ek 2-D grid (spreadsheet), diagonal ke paas mirror agar roads do-taraf hain.
Hum visited cities ka set kyun store karte hain, poora path order kyun nahi?
Future cost sirf us par depend karti hai kaun si cities ticked hain aur tumhara current spot kya hai; order dp value ke andar already optimise ho chuka hai, use rakhne se n! wapas aajata.
Visited set {0,2} (n=4 ke saath) ko mask integer mein convert karo.
Bits (3,2,1,0)=0101 = 5.
1≪i kya hai?
Sirf bit i set wala integer, 2i ke barabar.
Teeno edits do: city i ko test / add / remove karo.