Data Structure
Data Structure
TEST 1
SEMESTER I 2010/2011
CODE OF SUBJECT : SCJ2013, SCK 2243
NAME OF SUBJECT : Data Structure and Algorithm
YEAR / COURSE : 2SCV, 2SCR, 2SCJ, 2SCI, 2SCD, 2SCB
TIME : 8.30 PM 10.30 PM (2 Hours)
DATE : 21 August 2010
VENUE : N24 BK8 & BK9 (Lecture Hall 8 & 9)
INSTRUCTIONS TO THE STUDENTS:
This test book consists of 3 parts:
Part A: 10 True/False Questions 10 marks
Part B: 10 Objective Questions 15 marks
Part C: 5 Structured Questions 75 marks
ANSWER ALL QUESTIONS IN THE SPACES ALLOCATED IN THIS TEST BOOK.
Name
Identity card (or matric) Number:
Name of Lecturer
Subject Code and Section
This examination book consists of 21 printed pages excluding this page.
Test 1 - Data Structure and Algorithm 1
PART A TRUE/FALSE QUESTIONS [10 marks]
[BAHAGIAN A SOALAN BENAR/ SALAH] [10 markah]
There are 10 questions in this section. For each statement given in this section, identify
whether the statement is TRUE/FALSE and write your answer in the space given in page
7. Each question carries 1 mark.
[Bahagian ini terdiri daripada 10 soalan. Bagi setiap kenyataan yang diberi, tentukan
samada BENAR/SALAH dan tuliskan jawapan anda pada ruang yang disediakan di
mukasurat 7. Setiap soalan bernilai 1 markah.]
1. Array and struct are examples of storage structure in structured data types.
[Tatasusunan dan struktur adalah contoh-contoh struktur storan dalam jenis data
berstruktur.]
2. If function void getValue() pass a parameter by reference from class
employee, the correct syntax prototype for this function can be written as:
[Jika fungsi void getValue() menghantar parameter secara rujukan berjenis
kelas employee maka sintaks yang betul bagi prototaip fungsi ini adalah: ]
void getValue(employee &);
3. Similar to constructor, destructor could not have return type but can have
parameters.
[Seperti konstruktor, distruktor tidak boleh mempunyai jenis pulangan, tetapi
boleh mempunyai parameter.]
4. If two programs perform the same task, then the faster program is always better.
[Jika dua atur cara melaksanakan tugas yang sama, maka atur cara yang lebih
pantas perlaksanaannya selalunya adalah atur cara yang lebih baik. ]
5. Retrieving an item at index 10 of an array is an example of a constant function.
[Capaian ke atas elemen pada indeks 10 pada sebuah tatasusunan merupakan
contoh fungsi konstan.]
6. A recursive function cannot call another function.
[Fungsi rekursif tidak boleh memanggil fungsi yang lain.]
7. The efficiency of a sorting algorithm is measured ONLY based on the number of
comparisons done during a sorting process.
[Keberkesanan sesuatu algoritma isihan diukur HANYA berdasarkan bilangan
perbandingan yang berlaku semasa isihan. ]
8. In any case of Selection Sort (worst case, best case or average case), the number
of comparisons between elements is the same.
[Bagi mana-mana kes Isihan Pilihan (kes terburuk, kes terbaik atau kes purata,
bilangan perbandingan di antara elemen adalah sama. ]
Test 1 - Data Structure and Algorithm 2
9. One of the differences between Quick sort and Merge sort is Quick Sort partition
the list based on the pivot value and Merge Sort partition the list by dividing the
list into two balanced list.
[Salah satu perbezaan antara Isihan Cepat dan Isihan Cantum ialah Isihan Cepat
membahagikan senarai berdasarkan nilai pivot dan Isihan Cantum
membahagikan senarai kepada dua senarai yang seimbang.]
10. Quicksort and Mergesort have the same time complexity for average case, which
is O(n * log
2
n) but Quicksort requires more computation space for second array.
[Isihan Cepat dan Isihan Cantum mempunyai masa kerumitan yang sama bagi
kes purata, iaitu O(n * log
2
n) tetapi Isihan Cepat memerlukan lebih ruang
komputasi untuk tatasusunan ke dua.]
PART B OBJECTIVE QUESTIONS [15 marks]
[BAHAGIAN B SOALAN OBJEKTIF] [15 markah]
Part B consists of 10 objective questions. Choose the correct answer, and write your
answer in the answer sheet provided in page 7 Each question carries 1.5 mark.
[Bahagian B mengandungi 10 soalan objektif. Pilih jawapan yang betul, dan jawab pada
kertas jawapan yang disediakan pada mukasurat 7. Setiap soalan bernilai 1.5 markah. ]
1. Given the following statement. Identify the testing level described.
[Diberikan kenyataan berikut. Kenalpasti aras pengujian yang dinyatakan.]
Involves building a system from its components or modules, and testing the system
for problems that arise from component interactions.
A. Unit Testing [Pengujiaan Unit]
B. Integration Testing [Pengujian Integrasi]
C. System Testing [Pengujian Sistem]
D. Accepteance Tesitng [Pengujian Penerimaan]
Question 2 is based on Figure 1 below.
[Soalan 2 adalah berdasarkan pada Rajah 1 berikut.]
Car
CarModel
Registration number
Year
Color
Move()
Brake()
Reverse()
Figure 1. Car [Rajah 1. Kereta]
Test 1 - Data Structure and Algorithm 3
2. Which of the following activity is done in Figure 1?
[Yang mana di antara aktiviti berikut dilakukan dalam Rajah 1?]
A. Encapsulation [Enkapsulasi]
B. Abstraction [Pengabstrakan]
C. Information hiding [Penyembunyian maklumat]
D. C++ class implementation [Implementasi class dalam C++]
3. Which of the following is NOT a structured data type?
[Yang mana di antara berikut BUKAN jenis struktur data?]
A. Storage [Storan]
B. Linked [Pautan]
C. Integral [Integral]
D. State [Keadaan]
Question 4 is based on Program 1.0.
[Soalan 4 adalah berdasarkan kepada Aturcara 1.0.]
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
// Program 1.0
class Info {
int a,b ;
public :
Info (int x,int y);
void function1(Info c);
};
Info::Info(int x,int y) {
a = x;
b = y;
}
void Info:: function1(Info d) {
a+=d.a;
b+=d.b;
}
main() {
Info obj1(2,4);
Info obj2(3,6);
obj1.function1(obj2);
}
4. Given Program 1.0, what is the final value for a and b of object obj1 after execution
of the program ?
[Diberi Program 1.0, apakah nilai terakhir bagi a dan b bagi objek obj1 setelah
aturcara ini dilaksanakan?]
A. a = 2 , b =4 C. a = 3, b = 6
B. a= 5, b= 10 D. a= 2, b=3
Test 1 - Data Structure and Algorithm 4
Question 5 is based on Program 2.0 which consists of constructor declaration for class
Kelas.
[Soalan 4 adalah berdasarkan pada Aturcara 2.0 yang merupakan pengishtiharan
konstruktor bagi kelas Kelas.]
1.
2.
3.
4.
5.
6.
7.
8.
// Program 2.0
class Kelas {
:
public:
Kelas (int, char = A, int = 50);
};
5. Which of the following statement for creating an object is INVALID?
[Yang mana di antara peryataan pengisytiharan objek berikut yang TIDAK SAH?]
A. Kelas dataStructure(C,100);
B. Kelas dataStructure (1);
C. Kelas dataStructure (1,B);
D. Kelas dataStructure (1,C,100);
6. How many times will function showMessage() in Program 3.0 calls itself, if 5 is
passed as the argument?
[Berapa kali kah fungsi showMessage() dalam Atur cara 3.0 memanggil dirinya
sendiri, jika nilai 5 dihantar sebagai argumen?]
1.
2.
3.
4.
5.
6.
7.
8.
9.
// Program 3.0
void showMessage(int n)
{ if (n > 0)
{
cout << "Good day!" << endl;
showMessage(n - 1);
}
}
A. 4
B. 5
C. 6
D. An infinite number of times
[Bilangan yang tak terhingga.]
Test 1 - Data Structure and Algorithm 5
Question 7 and 8 is based on Table 1.
[Soalan 7 dan 8 adalah berdasarkan kepada Jadual 1.]
Table 1 : Running Time [Jadual 1: Masa Larian]
Algorithm Running Time
Input Size O(n
2
) O(nlog
2
n) O(n)
n = 10 0.000004 0.000006 0.000003
n = 100 0.000109 0.000045 0.000006
n = 1000 0.010203 0.000485 0.000031
n = 10,000 1.2329 0.005712 0.000317
7. Which of the following is NOT represented by Table 1:
[Yang mana di antara berikut yang TIDAK diwakili oleh Jadual 1.]
A. The running time of 3 algorithms based on the growth rate of the input size.
[Masa larian bagi 3 algoritma berdasarkan kadar perkembangan dan saiz
input.]
B. The growth rate of the input size based on the running time.
[Kadar perkembangan bagi saiz input berdasarkan kepada masa larian.]
C. The running time for the algorithms increase as the problem size increase.
[Masa larian bagi semua algoritma bertambah apabila saiz masalah
bertambah.]
D. The complexity of 3 algorithms based on the input size.
[Kerumitan bagi 3 algoritma berdasarkan saiz input.]
8. Which of the following tell the efficiency of the algorithms in Table 1?
[Yang mana di antara berikut menerangkan keberkesanan bagi semua algoritma
dalam Jadual 1? ]
A. O(n) algorithm is the most efficient compare to the other algorithms.
[Algoritma O(n) merupakan yang paling berkesan berbanding algoritma yang
lain.]
B. O(n
2
) algorithm is more efficient compare to O(nlog
2
n) algorithms.
[Algoritma O(n
2
) paling berkesan berbanding algoritma O(nlog
2
n).]
C. O(nlog
2
n) algorithm is the most efficient compare to other algorithms.
[Algoritma O(nlog
2
n ) paling berkesan berbanding algoritma yang lain.]
D. It is hard to identify the efficiency of the algorithms from the data in the Table
1.
[Agak sukar untuk mengenalpasti keberkesanan algoritma-algoritma
berdasarkan data pada Jadual 1.]
Test 1 - Data Structure and Algorithm 6