You are on page 1of 5

Kingdom of Saudi Arabia

Ministry of Higher Education ‫اﻟﻣﻣﻠﻛﺔ اﻟﻌرﺑﯾﺔ اﻟﺳﻌودﯾﺔ‬


Jazan University ‫وزارة اﻟﺗﻌﻠﯾم اﻟﻌﺎﻟﻰ‬
College of Computer Science & Information Technology TYPE - A‫ﺟــﺎﻣـﻌــﺔ ﺟـــــﺎزان‬
‫ﻛﻠﯾﺔ اﻟﺣﺎﺳب اﻵﻟﻰ وﺗﻘﻧﯾﺔ اﻟﻣﻌﻠوﻣﺎت‬

ACADEMIC YEAR 2021-22/1442-43 | SPRING SEMESTER


MID TERM EXAM – ANSWER KEY
Course: Algorithms & Data Structures-1 Code: COMP 221 Section:

Student Name__________________________________ Student ID________________________________

Exam Date: Wednesday 23rd March 2022 Time: 11:00 A.M Signature of CT:______________________________
Exam Duration: 1 Hour Max. Marks: 10 Marks awarded:

SECTION – A ( 4 x ½ = 2 Marks)
Answer ALL questions. Each question carries HALF mark

1. Choose the correct answer:

i) Which of the following is a non-linear data structure?

(a) Stack (b) Array (c) Queue (d) Tree

ii) The total number of comparisons required for sorting a list of n elements using selection sort algorithm is
______________.

(a) n2 (b) n (n-1)/2 (c) n(n-1) (d) n

iii) __________________ represents the fewest numbers of steps that an algorithm would require.

(a) Best Case complexity (b) Worst Case Complexity (c) Average Case Complexity (d) All of these

iv) Which of the following is a valid declaration of Java single dimensional array?

(a) int [ ] a = {1,2}; (b) int () a = [1,2]; (c) int a = {1,2}; (d) int a = [1,2];

SECTION – B (4 x 1 = 4 Marks)
Answer any FOUR questions. Each question carries ONE mark

2. Define the term ‘Data Structure’?

A data structure is a particular way of storing and organizing data in a computer memory so that it can be used
efficiently.

COMP 221/Mid Term Exam/1442-43 (Spring Semester)


3. What is the output of the following code?

int [ ] a = {1,2,3,4};

System.out.println(a[3]);

Output: 4

4. Show how selection sort works for the following list of elements?

126 43 25 1

126
1 43 25
126
1 25 43
126
1 25 43

5. What are the two basic structuring mechanisms?

Arrays and References are the two basic structuring mechanisms.

6. What is Circular Linked List?

A Circular linked list is a singly linked list in which the next reference of the tail node is set to refer back to the
head of the list (rather than null).

COMP 221/Mid Term Exam/1442-43 (Spring Semester)


SECTION C ( 1 x 4 = 4 Marks)
Answer ANY ONE Question which carries FOUR Marks

7. Explain the process of inserting an element at the head of a singly linked list with the help of a
suitable example.

• Allocate a new node

• Insert new element

• Have new node point to old head

• Update head to point to new node

COMP 221/Mid Term Exam/1442-43 (Spring Semester)


8. Differentiate between reference types and primitive types in Java with the help of an example
diagram.

Primitive types, such as the int type, are handled “by value.”

Nonprimitive types, such as arrays and classes, are handled “by reference.”

Whereas the variable of a primitive type holds the value of the variable, the variable of a nonprimitive type holds a
reference to the value of the variable.

That is, the variable holds the address where the system can find the value associated with the variable.

When we assign a variable of a primitive type to another


variable of the same type, the latter becomes a copy of the
former.

But, as you can see from figure, this is not the case with
reference types. When we assign Circle c2 to Circle c1, c1
does not become a copy of c2.

Instead, the reference associated with c1 becomes a copy


of the reference associated with c2. As a consequence,
both c1 and c2 now reference the same object.

COMP 221/Mid Term Exam/1442-43 (Spring Semester)


COMP 221/Mid Term Exam/1442-43 (Spring Semester)

You might also like