I need help with this question 28 How many passes are made through the outer for
ID: 3735324 • Letter: I
Question
I need help with this question 28 How many passes are made through the outer for loop and after the first pass through the inner for loop, what is the value of index ? var names = new Array("Marie", "Jose", "Zack", "Patty", "Ivan", "Tasha"); var N = 5; for (var k = 0; k <= N; k++) { var min = names[k]; var index = k; for (var j = (k + 1); j < N; j++) { if (names[j] < min) { min = names[j]; index = j; } } if (k != index) { var temp = names[k]; names[k] = names[index]; names[index] = temp; } }
Explanation / Answer
Answer : 6
Explanation : The first for loop is running from 0 (k=0) to 5 (k<=N, where N = 5). i.e., K's values will be [0, 1, 2, 3, 4, 5] and then the outer for loop will exit.
Answer : 4