0% found this document useful (0 votes)
46 views3 pages

CSC 210 Exam: Algorithms & Complexity

The document is an exam paper for an Algorithm and Complexity Analysis course. It contains 6 questions testing students' knowledge of algorithms, data structures, complexity analysis and problem solving. Some of the questions ask students to define terms, analyze time complexities, implement algorithms like quicksort, and explain concepts like graph representations, binary search trees and asymptotic notations.

Uploaded by

seyi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

CSC 210 Exam: Algorithms & Complexity

The document is an exam paper for an Algorithm and Complexity Analysis course. It contains 6 questions testing students' knowledge of algorithms, data structures, complexity analysis and problem solving. Some of the questions ask students to define terms, analyze time complexities, implement algorithms like quicksort, and explain concepts like graph representations, binary search trees and asymptotic notations.

Uploaded by

seyi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

KOLADAISI UNIVERSITY, IBADAN

Faculty of Applied Sciences


Department of Mathematical and Computing Sciences
Second Semester Examination 2019/2020 Session

CSC 210: Algorithm and Complexity Analysis (3 Units) Time: 3 hours


INSTRUCTION: Answer question 1 and ANY other three questions

1. (a) Mention five characteristics of an algorithm (5mks)


(b) What is complexity of an algorithm? (4mks)
(c) Complete the table below (4mks)
Type Size
bool, char, unsigned char, signed char, __int8
__int16, short, unsigned short, wchar_t, __wchar_t
float, __int32, int, unsigned int, long, unsigned long
double, __int64, long double, long long

(d) Give the worst case time, average case time and best case time complexity of heap Sort (3mks)
(e) State the two properties of asymptotic notations (2mks)
(f) Highlight three advantages of sequential search algorithm (3mks)
(g) What is sorting algorithm? (2mks)
(h) Define the term linear probing in hashing technique (2mks)

2. (a) Draw the adjacency matrix for the directed graph given below (5mks)

(b) Mention any four types of an algorithm (4mks)


(c) Explain the three basic primary operations involved in hash table (6mks)
3. (a) When is an algorithm considered to be good (5mks)
(b) Write the missing line for the following program (5mks)
int count = 0
……………………………….
for (int j =0; j<1; j++)
Count ++
. (c) Highlight the two reasons for memory usage during execution of algorithm (5mks)

4. (a) Explain briefly two representations of graph data structure (5mks)


(b) What is big-oh notation in time complexity (5mks)
(c) Complete the following quick sort implementation (5mks)
def partition(arr,low,high):
i = ( low-1 ) # index of smaller element
pivot = arr[high] # pivot
for j in range(low , high):
# If current element is smaller than or
# equal to pivot
if arr[j] <= pivot:
# increment index of smaller element
i = i+1
(……………………………………………)

arr[i+1],arr[high] = arr[high],arr[i+1]
(………………………………………)

5. (a) Differentiate between mini-Heap and max-Heap in binary search tree (BST) (5mks)
(b) Define the following terms used in graph data structure (6mks)
(i) Adjacency (ii) Edge (iii) Vertex
(c) Discuss the two measures used in algorithm complexity (4mks)

6. (a) Explain how the following operations work in binary search tree (BST) (5mks)
(i) Insertion in BST (ii) Deletion in BST
(b) Compute the space complexity for the following expression. (5mks)
{
int z = a + b + c;
Return(z);
}

(c) List the five steps involved in complete running time of an algorithm (5mks)

Common questions

Powered by AI

Heap sort has a worst-case, average-case, and best-case time complexity of O(n log n). This consistency across different cases is due to the nature of the heap data structure, which maintains an efficient logarithmic time complexity during sorting operations .

A good algorithm is one that is correct, efficient (with optimal time and space complexity), well-defined, maintainable, and scalable. These criteria ensure that an algorithm is reliable, executes efficiently across varying inputs, and can be adapted or improved as needed .

A mini-Heap and a max-Heap differ in their priority of element arrangement. In a mini-Heap, the smallest element has the highest priority and is root, whereas in a max-Heap, the largest element is the root. Both maintain heap properties to facilitate efficient retrieval .

Sequential search offers advantages in scenarios where data is unsorted or when no index is available. Its advantages include simplicity, no additional storage requirement, and suitability for small datasets where its linear nature is less of a drawback .

A sorting algorithm arranges data in a particular order, either ascending or descending. Examples include quicksort, mergesort, and heapsort, used in scenarios like organizing data for efficient searches and simplifying data manipulations .

The complexity of an algorithm refers to the computational resources required for running it, primarily time and space. It is crucial for assessing an algorithm's efficiency, predicting performance, and identifying bottlenecks in resource usage .

An algorithm is defined by characteristics including finiteness, definiteness, input, output, and effectiveness. These properties ensure the algorithm completes after a finite number of steps, is clearly defined, can receive inputs and produce outputs, and is feasible for practical execution .

Linear probing handles collisions by placing the collided element in the next available slot in the hash table. When a hash collision occurs, the algorithm checks subsequent indices sequentially until an open spot is found .

The two essential properties of asymptotic notations are transitivity and non-negativity. Transitivity helps in simplifying complexity expressions, while non-negativity ensures that asymptotic comparisons remain meaningful and valid .

The primary operations in hash tables are insertion, deletion, and searching. Insertion involves adding a key-value pair, deletion removes the pair, and searching retrieves a value using the key. These operations depend on the hash function to compute the index in the table .

You might also like