0% found this document useful (0 votes)
2 views

data structures and algorithms

This document is an assignment for a Bachelors of Commerce in Information Systems program, focusing on data structures and algorithms. It includes descriptions of various binary tree types, an explanation of Fibonacci search, a comparison of sorting algorithms, and examples of sorting using Quick sort, Merge sort, and Radix sort. Additionally, it provides a pseudocode for the Insertion Sort algorithm.

Uploaded by

charternenyasha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

data structures and algorithms

This document is an assignment for a Bachelors of Commerce in Information Systems program, focusing on data structures and algorithms. It includes descriptions of various binary tree types, an explanation of Fibonacci search, a comparison of sorting algorithms, and examples of sorting using Quick sort, Merge sort, and Radix sort. Additionally, it provides a pseudocode for the Insertion Sort algorithm.

Uploaded by

charternenyasha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

TRUST ACADEMY

In collaboration with
MIDLANDS STATE UNIVERSITY
BMIS (BSc Management of Information Systems Hons)

NAME : TIRIVAVI TSITSI


PROGRAM : Bachelors of Commerce In Information Systems

REG NUMBER : MIA189 / R245495B

MODULE : DATA STRUCTURES AND ALGORITHMS


LECTURER : MR. DEVE

ASSIGNMENT : 2

OVERALL
MARK

Comments:
QUESTION 1

Question 2

Brief descriptions of the binary tree variants:

a. Extended Binary Tree: A binary tree with additional nodes to represent empty subtrees.

b. Complete Binary Tree: A binary tree where every level is fully filled, except possibly the
last level.

c. Full Binary Tree: A binary tree where every node has two children.

d. Skewed Binary Tree: A binary tree where every node has only one child.

e. Strictly Binary Tree: A binary tree where every node has two children, and all leaf nodes
are at the same level.

f. Expression Binary Tree: A binary tree representing an expression, where operators are
internal nodes and operands are leaf nodes.

g. Binary Search Tree: A binary tree where each node's value is greater than its left child and
less than its right child.

Fibonacci Search

Fibonacci search is a divide-and-conquer algorithm for searching an ordered list. It uses


Fibonacci numbers to divide the list into smaller segments.

Example:

Suppose we have the list: 2, 4, 6, 8, 10, 12, 14, 16, 18

We want to search for the element 10.

1. Divide the list into two segments using Fibonacci numbers: 2-4-6-8 (Fibonacci number 5)
and 10-12-14-16-18 (Fibonacci number 8)
2. Compare the middle element of the first segment (6) with the target element (10). Since
10 is greater, we search in the second segment.
3. Divide the second segment into two smaller segments: 10-12 (Fibonacci number 3) and
14-16-18 (Fibonacci number 5)
4. Compare the middle element of the first segment (11) with the target element (10). Since
10 is less, we search in the left segment.
5. The target element 10 is found.

Question 3
Table comparing the time complexities of 6 sorting algorithms:

| Algorithm | Best-case | Average-case | Worst-case |

| Bubble sort | O(n) | O(n^2) | O(n^2) |


| Selection sort | O(n^2) | O(n^2) | O(n^2) |
| Insertion sort | O(n) | O(n^2) | O(n^2) |
| Merge sort | O(n log n) | O(n log n) | O(n log n) |
| Quick sort | O(n log n) | O(n log n) | O(n^2) |
| Radix sort | O(nk) | O(nk) | O(nk) |

Question 4

The sorted lists using Quick sort, Merge sort, and Radix sort up to 5 passes:

a. Quick sort:

Pass 1: 20, 11, 5, 89, 75, 62, 95, 98, 4


Pass 2: 11, 5, 20, 89, 75, 62, 95, 98, 4
Pass 3: 5, 11, 20, 89, 75, 62, 95, 98, 4
Pass 4: 4, 5, 11, 20, 89, 75, 62, 95, 98
Pass 5: 4, 5, 11, 20, 62, 75, 89, 95, 98

b. Merge sort:

Pass 1: 20, 11, 5, 89, 75, 62, 95, 98, 4


Pass 2: 11, 20, 5, 89, 62, 75, 95, 98, 4
Pass 3: 5, 11, 20, 62, 89, 75, 95, 98, 4
Pass 4: 4, 5, 11, 20, 62, 75, 89, 95, 98
Pass 5: 4, 5, 11, 20, 62, 75, 89, 95, 98

c. Radix sort:

Pass 1: 4, 5, 11, 20, 62, 75, 89, 95, 98


Pass 2: 4, 5, 11, 20, 62, 75, 89, 95, 98
Pass 3: 4, 5, 11, 20, 62, 75, 89, 95, 98
Pass 4: 4, 5, 11, 20, 62, 75, 89, 95, 98
Pass 5: 4, 5, 11, 20, 62, 75, 89, 95, 98
Procedure InsertionSort(arr)
for i from 1 to length(arr) - 1
key = arr[i]
j=i-1
while j >= 0 and arr[j] > key
arr[j + 1] = arr[j]
j=j-1
arr[j + 1] = key
end for
End Procedure

You might also like