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

Group Assignment - Theory of Algorithms

The document provides instructions for a group assignment for a Theory of Algorithms course. It lists the group members, their student IDs, sections, years, and departments. It instructs students to submit their answers to 5 questions in MS Word or PDF format via Telegram by June 25, 2020. Late submissions within 2 days will be penalized 1% per day. The questions ask students to briefly discuss different types of algorithm analysis methods and needs, algorithm complexity examples, sorting techniques examples, linked list types examples, and tree traversal applications.

Uploaded by

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

Group Assignment - Theory of Algorithms

The document provides instructions for a group assignment for a Theory of Algorithms course. It lists the group members, their student IDs, sections, years, and departments. It instructs students to submit their answers to 5 questions in MS Word or PDF format via Telegram by June 25, 2020. Late submissions within 2 days will be penalized 1% per day. The questions ask students to briefly discuss different types of algorithm analysis methods and needs, algorithm complexity examples, sorting techniques examples, linked list types examples, and tree traversal applications.

Uploaded by

hak adv
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ADMAS UNIVERSITY BISHOFTU CAMPUS

Course Title -Theory of Algorithms


TITLE: GROUP ASSIGNMENT I

GROUP MEMBERS
S.No NAME ID SECTION YEAR DEPT.

1 HABTAMU H/MICHAEL 0500/17 1 3RD CoSc

2 GADISA NEGASO 0194/17 1 3RD CoSc

3 KASSAHUN TAFESE 0192/17 1 3RD CoSc

4 SEFELEGE TEREFE 0211/17 1 3RD CoSc

Submitted to Instructor: Fikre T.


June 02, 2020 G.C.
INSTRUCTIONS
NB: Read duly the following instructions and act as per requirements.
o This is a group assignment. Thus, copy and paste from other groups will result in
zero values.
o You must use either MS-word or PDF format for your answers. Other forms may not
to be welcomed. In particular images using cell phone be considered at your risk.
o You must send your work using telegram via cell phone: 0911-79-85-14 only using
private telegram account for telegram users are welcomed. You cannot send via your
(students) group telegram.
o Otherwise non- telegram user may submit in person using hardcopy to your
respective department. Those who are willing to submit with hardcopy should make
sure that their handwriting is legible. Please any other way of submission is not
welcomed.
o Your final submission date is on June 25/06/2020. You can submit before the due
date. I highly value your punctuality as part of your assignment. Thus, late
submission may result in 1% punishment per delay for each day. But the submission
date by no means extends beyond June 27/06/2020.
o Neatness and clarity have its own value!

Stay Safe!

QUESTIONS:

1. Briefly discuss the different types of methods and needs for algorithm analysis?
2. Briefly discuss the different types of algorithm complexity with example?
3. Briefly discuss the different sorting techniques with example?
4. Briefly explain the different types of linked lists with example?
5. Briefly discuss about tree traversals and the different applications?
1. Briefly discuss the different types of methods and
needs for algorithm analysis
Analysis of Algorithm
• is the process of analyzing the problem-solving capability of the
algorithm in terms of the time and size required (the size of memory for
storage while implementation)? However, the main concern of analysis of
algorithms is the required time or performance. Types of algorithm

Types of Analysis:

✓ Worst-case: The maximum number of steps taken on any instance of size


a.
✓ Best-case: The minimum number of steps taken on any instance of size a.
✓ Average case: An average number of steps taken on any instance of size
a.

2. Briefly discuss the different types of algorithm


complexity with example?
Time Complexity
• an algorithm represents the amount of time required by the algorithm to
run to completion. Time requirements can be defined as a numerical
function T(n), where T(n) can be measured as the number of steps,
provided each step consumes constant time.
✓ For example, addition of two n-bit integers takes n steps.
Consequently, the total computational time is T(n) = c*n, where c
is the time taken for addition of two bits. Here, we observe that
T(n) grows linearly as input size increases SPACE COMPLEXITY

Space Complexities
➢ Space complexity of an algorithm represents the amount of memory
space required by the algorithm in its life cycle. Space required by an
algorithm is equal to the sum of the following two components
▪ A fixed part that is a space required to store certain data
and variables that are independent of the size of the
problem. For example, simple variables & constant used,
program size etc.
▪ A variable part is a space required by variables; whose size
depends on the size of the problem. For example, dynamic
memory allocation, recursion stacks space etc. Space
complexity S(P) of any algorithm P is S(P) = C + SP(I)
Where C is the fixed part and S(I) is the variable part of the
algorithm which depends on instance characteristic I
For example
✓ Algorithm: SUM (A, B)
✓ Step 1 - START
✓ Step 2 - C ← A + B + 10
✓ Step 3 - Stop
3. Briefly discuss the different sorting techniques with
example?
Sorting Techniques
➢ Sorting refers to arranging data in a particular format. Sorting algorithm
specifies the way to arrange data in a particular order. Most common
orders are in numerical or lexicographical order. The importance of
sorting lies in the fact that data searching can be optimized to a very
high level, if data is stored in a sorted manner. Sorting is also used to
represent data in more readable formats.
Sorting Techniques with example
➢ Selection sort
▪ sorting algorithm which works as follows.
o Find the minimum value in the list
o Swap it with the value in the first position
o Repeat the steps above for remainder of the list (starting at the
second position)

✓ Examples
• 26 33 43 100 46 88 52 17 53 77
• 17 | 33 43 100 46 88 52 26 53 77
• 17 26 | 43 100 46 88 52 33 53 77
• 17 26 33 | 100 46 88 52 43 53 77
• 17 26 33 43 | 46 88 52 100 53 77
• 17 26 33 43 46 | 88 52 100 53 77
• 17 26 33 43 46 52 | 88 100 53 77
• 17 26 33 43 46 52 53 | 100 88 77
• 17 26 33 43 46 52 53 77 | 88 100
• 17 26 33 43 46 52 53 77 88 | 100

➢ Insertion Sort
▪ each successive element in the array to be sorted is inserted into its proper
place with respect to the other, already sorted elements.
o We divide our array in a sorted and an unsorted array
o Initially the sorted portion contains only one element: the first
element in the array.
o We take the second element in the array, and put it into its
correct place

✓ Examples
• 99 | 55 4 66 28 31 36 52 38 72
• 55 99 | 4 66 28 31 36 52 38 72
• 4 55 99 | 66 28 31 36 52 38 72
• 4 55 66 99 | 28 31 36 52 38 72
• 4 28 55 66 99 | 31 36 52 38 72
• 4 28 31 55 66 99 | 36 52 38 72
• 4 28 31 36 55 66 99 | 52 38 72
• 4 28 31 36 52 55 66 99 | 38 72
• 4 28 31 36 38 52 55 66 99 | 72
• 4 28 31 36 38 52 55 66 72 99 |

➢ Bubble sort
▪ is similar to selection sort in the sense that it repeatedly finds the
largest/smallest value in the unprocessed portion of the array and puts it back.
o However, finding the largest value is not done by selection this
time.
o We "bubble" up the largest value instead.
o Compares adjacent items and exchanges them if they are out of
order.
o Comprises of several passes.
o In one pass, the largest value has been “bubbled” to its proper
position.
o In second pass, the last value does not need to be compared.

✓ Examples
1 2 3 4 5 6

42 35 12 77 5 101

1 2 3 4 5 6

35 12 42 5 77 101

1 2 3 4 5 6

12 35 5 42 77 101

1 2 3 4 5 6

12 5 35 42 77 101

1 2 3 4 5 6

5 12 35 42 77 101
➢ Merge sort
▪ Merge-sort applies the divide-and-conquer technique to the sorting problem,
where, for the sake of generality, let us consider the sorting problem to take a
sequence, S, of objects as input, which could be represented with either a list or
an array, and returns S in sorted order. For the problem of sorting a sequence S
with n elements, the three divide-and conquer steps are as follows:
o Divide: If S has zero or one element, return S immediately; it is already
sorted. Otherwise (S has at least two elements), put the elements of S into
two sequences, S1 and S2, each containing about half of the elements of S;
that is, S1 contains the first [n/2] elements of S, and S2 contains the
remaining n/2 elements.
o Recur: Recursively sort the sequences S1 and S2.
o Conquer: Put back the elements into S by merging the sorted sequences S1
and S2 into a sorted sequence.
We can visualize an execution of the merge-sort algorithm using a binary tree T, called
the merge-sort tree.
✓ Examples
98 23 45 14 6 67 33 42

98 23 45 14 6 67 33 42

98 23 45 14 6 67 33 42

98 23 45 14 6 67 33 42

23 98 14 45 6 67 33 42

14 23 45 98 6 33 42 67

6 14 23 33 42 45 67 98
➢ Quick sort
▪ is a divide and conquer algorithm.
▪ Quick sort first divides a large list into two smaller sub-lists: the low elements
and the high elements. Quick sort can then recursively sort the sub-lists.

The steps are:

o Pick an element, called a pivot, from the list.


o Reorder the list so that all elements with values less than the pivot come before
the pivot, while all elements with values greater than the pivot come after it
(equal values can go either way). After this partitioning, the pivot is in its final
position. This is called the partition operation.
o Recursively apply the above steps to the sub-list of elements with smaller values
and separately the sub-list of elements with greater values.
➢ Example

• 549718326
• 413259786
• 132457869
• 132456789
• 123456789
• 123456789

4. Briefly explain the different types of linked lists with


example?

Types of Linked List


➢ Following are the types of linked list

➢ Singly Linked List.

✓ Doubly Linked List.


✓ Circular Linked List

❖ Singly Linked List


➢ A Singly-linked list is a collection of nodes linked together in a sequential way
where each node of the singly linked list contains a data field and an address
field that contains the reference of the next node.
➢ Example

❖ Doubly Linked List


➢ A Doubly Linked List contains an extra memory to store the address of the
previous node, together with the address of the next node and data which are
there in the singly linked list. So, here we are storing the address of the next as
well as the previous nodes.

➢ Example

❖ Circular Linked List


➢ A circular linked list is either a singly or doubly linked list in which there are
no NULL values. Here, we can implement the Circular Linked List by making
the use of Singly or Doubly Linked List. In the case of a singly linked list, the
next of the last node contains the address of the first node and in case of a
doubly-linked list, the next of last node contains the address of the first node
and prev of the first node contains the address of the last node.
✓ Example

5. Briefly discuss about tree traversals and the different


applications?
➢ Traversal is a process to visit all the nodes of a tree and may print their values
too. Because, all nodes are connected via edges (links) we always start from the
root (head) node. That is, we cannot randomly access a node in a tree. hat is, we
cannot randomly access a node in a tree. There are three ways which we use to
traverse a tree −

• In-order Traversal
• Pre-order Traversal
• Post-order Traversal

❖ In-order Traversal
In this traversal method, the left subtree is visited first, then the root and later the right
sub-tree. We should always remember that every node may represent a subtree itself.
If a binary tree is traversed in-order, the output will produce sorted key values in an
ascending order.
We start from A, and following in-order traversal, we move to its left subtree B. B is
also traversed in-order. The process goes on until all the nodes are visited. The output
of inorder traversal of this tree will be −
D→B→E→A→F→C→G
❖ Pre-order Traversal
In this traversal method, the root node is visited first, then the left subtree and finally
the right subtree.

We start from A, and following pre-order traversal, we first visit A itself and then move
to its left subtree B. B is also traversed pre-order. The process goes on until all the
nodes are visited. The output of pre-order traversal of this tree will be −
A→B→D→E→C→F→G

❖ Post-order Traversal
In this traversal method, the root node is visited last, hence the name. First we traverse
the left subtree, then the right subtree and finally the root node.
We start from A, and following Post-order traversal, we first visit the left
subtree B. B is also traversed post-order. The process goes on until all the nodes are
visited. The output of post-order traversal of this tree will be −
D→E→B→F→G→C→A

You might also like