Computational Thinking, Quiz 1
doSomething is a procedure that accepts a list of integers as input.
S = doSomething(L)Procedure doSomething(L) if (length(L) ≤ 1) { return(0) } else { return(last(L)-first(L) + doSomething(rest(init(L)))) }End doSomethingBased on the above data, answer the given subquestions.
What will be the value of S at the end of execution when L = [3, 2, 1, 0, 1, 2, 3]?
**doSomething** is a procedure that accepts a list of integers as input. S = doSomething(L) Procedure doSomething(L) if (length(L) ≤ 1) { return(0) } else { return(last(L)-first(L) + doSomething(rest(init(L)))) } End doSomething Based on the above data, answer the given subquestions. What will be the value of **S** at the end of execution when **L** = \[3, 2, 1, 0, 1, 2, 3\]? **doSomething** is a procedure that accepts a list of integers as input. S = doSomething(L) Procedure doSomething(L) if (length(L) ≤ 1) { return(0) } else { return(last(L)-first(L) + doSomething(rest(init(L)))) } End doSomething Based on the above data, answer the given subquestions. What will be the value of **S** at the end of execution when **L** = \[-3, -2, -1, 0, 1, 2, 3\]? The following pseudocode constructs a graph from the “Words” dataset. Each word position (Seq_No) is a node. The matrix **M** represents the graph. $\mathbf{M[i][j]} = 1$ if there is an edge from node **i** to node **j**. A = { } while (Table 1 has more rows) { Read the first row X in Table 1 A[X.Seq_No] = [X.LetterCount, X.PartOfSpeech] Move X to Table 2 } n = length(keys(A)) M = createMatrix(n, n) foreach i in keys(A) { foreach j in keys(A) { if ((last(A[i]) == last(A[j])) and isCompatible(A[i], A[j])) { M[i][j] = 1 } } } Procedure isCompatible(P, Q) if ((first(P) - first(Q)) == 1) { return (True) } else { return (False) } End isCompatible Study the pseudocode given above and answer the given subquestions. There will be an edge between word **i** and word **j** if and only if: