Group Work 1
CSC2101 – Data Structures & Algorithms
Semester 2, 2015/2016 Due date: 3 March 2016 during class
Instruction: Answer ALL questions in a group of either 3 or 4 persons.
1. Determine the output of the following C++ codes, if input is 24.
2. Suppose a programming language allocates 4-bits space to store a signed integer value
and 16-bits for floating (where the ratio of sign-exponent-fraction is defined as 1-5-10).
If possible, determine the corresponding binary representation of the following
numbers. Otherwise, explain your answers.
a. -8
b. 8
c. 0.3125
#include <iostream>
using namespace std;
int func1(const int data[], int first, int last, int value);
int main() {
const int array_size = 8;
int list[array_size]={ 1, 2, 4, 7, 24, 42, 45, 101};
int input;
cout << "Enter search value: ";
cin >> input;
cout << func1(list,0,array_size-1,input)
<< endl;
return 0;
}
int func1(const int data[], int first, int last, int value) {
int middle = (first + last) / 2;
if (data[middle] == value)
return middle;
else if (first >= last)
return -1;
else if (value < data[middle])
return func1(data, first, middle-1, value);
else
return func1(data, middle+1, last, value);
}
3. For (a) through (c), circle the right properties that describe array as a data structure.
Explain your answer.
Properties Explanation
a. Basic/Compound
b. Static/Dynamic
c. Linear/Non-linear
4. A 3-dimensional array, myArray, with dimensions of 2x2x3 is stored as [1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12] based on the column-wise manner.
a. Calculate the address of array element myArray[2, 2, 2] based on the
column-wise arrangement when the base address (B) is 123, size of each
element (W) is 2, and the lowest index of each dimension is 1.
b. Write the sequence of elements in myArray based on row-wise arrangement.
c. BONUS: Write programs that store elements in myArray based on row-wise
and column-wise arrangements.
 Extra points from the BONUS question will be transferred to your written Quiz 1.

Group p1

  • 1.
    Group Work 1 CSC2101– Data Structures & Algorithms Semester 2, 2015/2016 Due date: 3 March 2016 during class Instruction: Answer ALL questions in a group of either 3 or 4 persons. 1. Determine the output of the following C++ codes, if input is 24. 2. Suppose a programming language allocates 4-bits space to store a signed integer value and 16-bits for floating (where the ratio of sign-exponent-fraction is defined as 1-5-10). If possible, determine the corresponding binary representation of the following numbers. Otherwise, explain your answers. a. -8 b. 8 c. 0.3125 #include <iostream> using namespace std; int func1(const int data[], int first, int last, int value); int main() { const int array_size = 8; int list[array_size]={ 1, 2, 4, 7, 24, 42, 45, 101}; int input; cout << "Enter search value: "; cin >> input; cout << func1(list,0,array_size-1,input) << endl; return 0; } int func1(const int data[], int first, int last, int value) { int middle = (first + last) / 2; if (data[middle] == value) return middle; else if (first >= last) return -1; else if (value < data[middle]) return func1(data, first, middle-1, value); else return func1(data, middle+1, last, value); } 3. For (a) through (c), circle the right properties that describe array as a data structure. Explain your answer. Properties Explanation a. Basic/Compound b. Static/Dynamic c. Linear/Non-linear 4. A 3-dimensional array, myArray, with dimensions of 2x2x3 is stored as [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] based on the column-wise manner. a. Calculate the address of array element myArray[2, 2, 2] based on the column-wise arrangement when the base address (B) is 123, size of each element (W) is 2, and the lowest index of each dimension is 1. b. Write the sequence of elements in myArray based on row-wise arrangement. c. BONUS: Write programs that store elements in myArray based on row-wise and column-wise arrangements.  Extra points from the BONUS question will be transferred to your written Quiz 1.