Question: 7. Complete the following dynamic programming implementation of the longest increasing subsequence problem:<div class="hk1_style-wrap4"><div class="hk1_style-wrap3"><div class="hk1_style-wrap2"><div class="hk1_style-wrap"><div class="hk1_style"><div class="c"><pre class="de1"><span class="co2">#include&lt;stdio.h&gt;</span> <span class="kw4">int</span> longest_inc_sub<span class="br0">(</span><span class="kw4">int</span> <span class="sy0">*</span>arr<span class="sy0">,</span> <span class="kw4">int</span> len<span class="br0">)</span> <span class="br0">{</span> <span class="kw4">int</span> i<span class="sy0">,</span> j<span class="sy0">,</span> tmp_max<span class="sy0">;</span> <span class="kw4">int</span> LIS<span class="br0">[</span>len<span class="br0">]</span><span class="sy0">;</span> <span class="co1">// array to store the lengths of the longest increasing subsequence </span> LIS<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span><span class="sy0">=</span><span class="nu0">1</span><span class="sy0">;</span> <span class="kw1">for</span><span class="br0">(</span>i <span class="sy0">=</span> <span class="nu0">1</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> len<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">)</span> <span class="br0">{</span> tmp_max <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="kw1">for</span><span class="br0">(</span>j <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> j <span class="sy0">&lt;</span> i<span class="sy0">;</span> j<span class="sy0">++</span><span class="br0">)</span> <span class="br0">{</span> <span class="kw1">if</span><span class="br0">(</span>arr<span class="br0">[</span>j<span class="br0">]</span> <span class="sy0">&lt;</span> arr<span class="br0">[</span>i<span class="br0">]</span><span class="br0">)</span> <span class="br0">{</span> <span class="kw1">if</span><span class="br0">(</span>LIS<span class="br0">[</span>j<span class="br0">]</span> <span class="sy0">&gt;</span> tmp_max<span class="br0">)</span> ___________<span class="sy0">;</span> <span class="br0">}</span> <span class="br0">}</span> LIS<span class="br0">[</span>i<span class="br0">]</span> <span class="sy0">=</span> tmp_max <span class="sy0">+</span> <span class="nu0">1</span><span class="sy0">;</span> <span class="br0">}</span> <span class="kw4">int</span> max <span class="sy0">=</span> LIS<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span><span class="sy0">;</span> <span class="kw1">for</span><span class="br0">(</span>i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> len<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">)</span> <span class="kw1">if</span><span class="br0">(</span>LIS<span class="br0">[</span>i<span class="br0">]</span> <span class="sy0">&gt;</span> max<span class="br0">)</span> max <span class="sy0">=</span> LIS<span class="br0">[</span>i<span class="br0">]</span><span class="sy0">;</span> <span class="kw1">return</span> max<span class="sy0">;</span> <span class="br0">}</span> <span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span> <span class="kw4">int</span> arr<span class="br0">[</span><span class="br0">]</span> <span class="sy0">=</span> <span class="br0">{</span><span class="nu0">10</span><span class="sy0">,</span><span class="nu0">22</span><span class="sy0">,</span><span class="nu0">9</span><span class="sy0">,</span><span class="nu0">33</span><span class="sy0">,</span><span class="nu0">21</span><span class="sy0">,</span><span class="nu0">50</span><span class="sy0">,</span><span class="nu0">41</span><span class="sy0">,</span><span class="nu0">60</span><span class="sy0">,</span><span class="nu0">80</span><span class="br0">}</span><span class="sy0">,</span> len <span class="sy0">=</span> <span class="nu0">9</span><span class="sy0">;</span> <span class="kw4">int</span> ans <span class="sy0">=</span> longest_inc_sub<span class="br0">(</span>arr<span class="sy0">,</span> len<span class="br0">)</span><span class="sy0">;</span> <span class="kw3">printf</span><span class="br0">(</span><span class="st0">"%d"</span><span class="sy0">,</span>ans<span class="br0">)</span><span class="sy0">;</span> <span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span> <span class="br0">}</span></pre></div></div></div></div></div></div>
Options:
tmp_max = LIS[j]
LIS[i] = LIS[j]
LIS[j] = tmp_max
tmp_max = LIS[i]
Answer: D