Session 1
Session 1
Data-Structures and
Algorithms
SESSION 1
OBJECTIVES
• Understand what algorithms are and the
important properties they must have
• Understand the role of algorithms in programming
• Understand what data structures are
• Understand the role of data structures and
Algorithms in computing
• Be familiar with problem solving
• Be able to select appropriate data structures and
algorithms for given problems
Introduction
• What are algorithms?
• Why is the study of algorithms worthwhile?
• What is the role of algorithms relative to other
technologies used in computers?
• What are data structures?
• In this lesson we will answer these questions
Problems
• In our everyday lives we are faced with a
number of problem.
• By problem we mean a task to be performed.
• Examples of problems could include:
• Baking a cake
• Solving an equation (quadratic equation)
• Sorting out a number of books according the year of
publishing…etc.
Focus however will be on what we call
computational problems (to be solved by
a computer)
Computational problems
• A computational problem specifies an input-output relationship
that values to be processed (input)must be determined
the expected outcome (output )of the
computation/processing should be known
• Examples of computational problems:
• Input: An integer number of a given value n
• Output: Response whether it is a prime
• Input: A list of names of students enrolled in the BIT250
course
• Output: The same list with the names sorted in alphabetic
order
• Input: A picture in digital format
• Output: An English description of what the picture shows
The Problem-solving Process
1. Problem analysis
Problem
specification 2. Design
Algorithm
3. Implementation
Program
Solution
(Executable) 4. Compilation
The problem-solving process
NB: In this course there is emphasis on good software
development practice:
Good documentation
Self-documenting code
Algorithms
• Informally, an algorithm is any well-defined
computational procedure that takes some value, or
set of values, as input and produces some value, or
set of values, as output.
• An algorithm is thus a sequence of computational
steps that transform the input into the output.
• We can also view an algorithm as a tool for solving a
well-specified computational problem.
• The statement of the problem specifies in general
terms the desired input/output relationship.
• The algorithm describes a specific computational
procedure for achieving that input/output
relationship.
Algorithms
A finite set of instructions which accomplish a particular task
A method or process to solve a problem
Transforms input of a problem to output
5. It must terminate.
Linked List
Queue Stack
Tree
HOWEVER!!
Design Issue:
select and design appropriate data types
(This is the main motivation to learn and understand data
structures)
Data Structure Operations
(Demonstrate using class room example!)
Traversing
Accessing each data element exactly once so that certain
items in the data may be processed
Searching
Finding the location of the data element (key) in the
structure
Insertion
Adding a new data element to the structure
Data Structure Operations
(cont.)
Deletion
Removing a data element from the structure
Sorting
Arrange the data elements in a logical order
(ascending/descending)
Merging
Combining data elements from two or more data structures
into one
Data Structures
• Efficient programs are as a result of the use of the
correct resources in terms of data structure.