You are on page 1of 22

Hawassa University

IoT,
Faculty of Informatics

Data Structures and Algorithms-


CoSc2083

Wogene Alemayehu( MSc in computer Science)


Email- Happy.alex1@gmail.com
Course content
Chapter 1: Introduction to Data Structures
1.1 Introduction
1.2 Abstract Data Type and Abstraction
Chapter 2 – Algorithm and Algorithm Analysis
2.1 Properties of Algorithm
2.2 Analysis of Algorithm
Chapter 3: Simple Sorting and Searching Algorithms
3.1 Sorting
3.1.1 Selection Sort
3.1.2 Bubble Sort
3.1.3 Insertion Sort
3.1.4 Pointer Sort

2 Mr.Wogene A. 11/1/2018
3.2 Searching
3.2.1 Linear/Sequential Searching
3.2.2 Binary Searching
Chapter 4: Linked Lists
4.1 Review on Pointer, Dynamic Memory allocation and De-allocation
4.2 Singly Linked Lists
4.3 Doubly Linked Lists
4.4 Implementation of Linked Lists
Chapter 5: Stacks and Queues
5.1 Basic Stack Operations
5.2 Basic Queue Operations
5.3 Implementation of Stacks and queues

3 Mr.Wogene A. 11/1/2018
Chapter 6: Tree Structures
6.1 Binary Trees and Binary Search Trees
6.2 Basic Tree Operations
6.3 Traversing in a Binary Tree
6.4 Graphs
6.5 General Trees and Their Implementations
Chapter 7: Advanced Sorting and Searching
7.1 Sorting
7.1.1 Heap Sort
7.1.2 Quick Sort
7.1.3 Merge Sort
7.1.4 Shell Sort
7.2 Advanced Searching
7.2.1 Hashing

4 Mr.Wogene A. 11/1/2018
 Reference book: Algorithms and Data Structures: The Science of
Computing by Baldwin/Scragg. Charles River Media. 2004.
Course Evaluation Includes:
 Quizzes
 Assignments
 Projects
 Tests
 Attendance
 Final Exam

5 Mr.Wogene A. 11/1/2018
Chapter one
Introduction to Data Structures and Algorithms Analysis
 What is data structure?
The way data are organized in a computers memory
 What is algorithm?
sequence of computational steps to solve a problem

In the world 80 % of the data is not organized. So it is difficult to go through it.

Therefore, there must be a mechanism which helps the user to delete,

search, update, Insert a data easily. To do so implementing data structure

plays a grate role.

6 Mr.Wogene A. 11/1/2018
The advantage of studying data structure?

Q. Which one is the shortest of all?


After comparison you can get the result.

7 Mr.Wogene A. 11/1/2018
But look at this one

They are sorted, so you can get the result


easily.
8 Mr.Wogene A. 11/1/2018
Given a problem, the first step to solve the problem is obtaining
ones own abstract view, or model, of the problem. This process
of modeling is called abstraction

9 Mr.Wogene A. 11/1/2018
Abstract Data Types
 An ADT consists of an abstract data structure and operations. Put
in other terms, an ADT is an abstraction of a data structure.
The ADT specifies:-
 What can be stored in the Abstract Data Type
 What operations can be done on/by the Abstract Data Type.
For example, if we are going to model employees of an organization:
 This ADT stores employees with their relevant attributes and
discarding irrelevant attributes.
 This ADT supports hiring, firing, retiring, ….. operations.

10 Mr.Wogene A. 11/1/2018
 There are lots of formalized and standard Abstract data types such
as Stacks, Queues, Trees, etc.
 
Do all characteristics need to be modeled? Not at all
 It depends on the scope of the model
 It depends on the reason for developing the model
Abstraction: is a process of classifying characteristics as relevant and
irrelevant for the particular purpose at hand and ignoring the
irrelevant ones

11 Mr.Wogene A. 11/1/2018
Algorithms
 is a well-defined computational procedure that takes some value or a
set of values as input and produces some value or a set of values as
output.
 Data structures model the static part of the world. They are unchanging
while the world is changing.
 In order to model the dynamic part of the world we need to work with
algorithms. Algorithms are the dynamic part of a program’s world model.
 An algorithm transforms data structures from one state to another state
in two ways:
 An algorithm may change the value held by a data structure
 An algorithm may change the data structure itself

12 Mr.Wogene A. 11/1/2018
Properties of an algorithm
1. Finiteness: Algorithm must complete after a finite number of
steps.
2. Definiteness: Each step must be clearly defined, having one and
only one interpretation. At each point in computation, one
should be able to tell exactly what happens next.
3. Sequence: Each step must have a unique defined preceding and
succeeding step. The first step (start step) and last step (halt
step) must be clearly noted.
4. Feasibility: It must be possible to perform each instruction.
5. Correctness: It must compute correct answer for all possible
legal inputs.

13 Mr.Wogene A. 11/1/2018
6. Language Independence: It must not depend on any one
programming language.
7. Completeness: It must solve the problem completely.
8. Effectiveness: It must be possible to perform each step exactly and
in a finite amount of time.
9. Efficiency: It must solve with the least amount of computational
resources such as time and space.
10. Generality: Algorithm should be valid on all possible inputs.
11. Input/Output: There must be a specified number of input values,
and one or more result values.

14 Mr.Wogene A. 11/1/2018
Algorithm Analysis Concepts
 Algorithm analysis refers to the process of determining the amount of
computing time and storage space required by different algorithms
 it’s a process of predicting the resource requirement of algorithms in a
given environment.
 The ways of analyzing algorithm is in terms of resource requirement. The
main resources are:
 Running Time
 Memory Usage
 Communication Bandwidth
 There are two approaches to measure the efficiency of algorithms:
Empirical: Programming competing algorithms and trying them on different
instances.
Theoretical: Determining the quantity of resources required mathematically
(Execution time, memory space, etc.) needed by each algorithm.

15 Mr.Wogene A. 11/1/2018
However, it is difficult to use actual clock-time as a consistent
measure of an algorithm’s efficiency, because clock-time can
vary based on many things. For example,
 Specific processor speed
 Current processor load
 Specific data for a particular run of the program
 Input Size
 Input Properties
 Operating Environment

16 Mr.Wogene A. 11/1/2018
Complexity Analysis
 Complexity Analysis is the systematic study of the cost of
computation, measured either in time units or in operations
performed, or in the amount of storage space required.
 There are two things to consider:
Time Complexity: Determine the approximate number of operations
required to solve a problem of size n.
Space Complexity: Determine the approximate memory required to solve
a problem of size n

17 Mr.Wogene A. 11/1/2018
Analysis Rules:

18 Mr.Wogene A. 11/1/2018
Examples:
Time Units to Compute
1. int count(){ -------------------------------------------------
int k=0; 1 for the assignment statement: int k=0
1 for the output statement.
cout<< “Enter an integer”; 1 for the input statement.
cin>>n; In the for loop:
1 assignment, n+1 tests, and n increments.
for (i=0;i<n;i++) n loops of 2 units for an assignment, and an
k=k+1; addition.
1 for the return statement.
return 0;} -------------------------------------------------------------------
T (n)= 1+1+1+(1+n+1+n)+2n+1 = 4n+6 = O(n)

19 Mr.Wogene A. 11/1/2018
2. int total(int n) Time Units to Compute
-------------------------------------------------
{ 1 for the assignment statement: int sum=0
int sum=0; In the for loop:
for (int i=1;i<=n;i++) 1 assignment, n+1 tests, and n increments.
n loops of 2 units for an assignment, and an
sum=sum+1;
addition.
return sum; 1 for the return statement.
} -------------------------------------------------------------------
T (n)= 1+ (1+n+1+n)+2n+1 = 4n+4 = O(n)

20 Mr.Wogene A. 11/1/2018
Measures of Times
 In order to determine the running time of an algorithm it is
possible to define three functions.
 Average Case (Tavg): The amount of time the algorithm takes on an "
average" set of inputs.
 Worst Case (Tworst): The amount of time the algorithm takes on
the worst possible set of inputs.
 Best Case (Tbest): The amount of time the algorithm takes on the
smallest possible set of inputs.
 We are interested in the worst-case time, since it provides a bound
for all input – this is called the “Big-Oh” estimate.

21 Mr.Wogene A. 11/1/2018
Asymptotic Analysis
 Asymptotic analysis is concerned with how the running time of an
algorithm increases with the size of the input in the limit, as the size
of the input increases without bound.
There are five notations used to describe a running time function.
These are:
 Big-Oh Notation (O)
 Big-Omega Notation ()
 Theta Notation ()
 Little-o Notation (o)
 Little-Omega Notation ()

22 Mr.Wogene A. 11/1/2018

You might also like