DSA CS Lecture01 Introduction T18 R00
DSA CS Lecture01 Introduction T18 R00
DSA CS Lecture01 Introduction T18 R00
Algorithms with C#
Ahmed Mohyeldin
Lecture #1
INTRODUCTION
Problem Algorithm Flowchart/Pseudocode
Program Solution
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 2
Computers – What is Computer?
A Computer is a tool for solving problems with
data!
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 6
Programs – How to Write a Program?
If you really wanted to tell a computer what to do
directly, you'd have to talk to it in binary, giving it
coded sequences of 1s and 0s that tell it which
machine instructions to execute.
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 7
Programs – How to Write a Program? (…cont’d)
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 8
Solving Problems with Computers
ALGORITHMS
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 9
Algorithms – The word Algorithm?
As a word “algorithm” has a long history; its
origin can be traced to the Arabic mathematician
El-Khawarizmi.
In general, common usage of the word would suggest
the meaning of “rule”, “procedure”, “method”,
“technique”, or “strategy”.
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 10
Algorithms – Simple Algorithm Example?
Describe the way to find words in a dictionary?
11. Determine the first letter of the word.
22. Find the page of the dictionary where this letter first
appears.
33. Determine the next letter of the word.
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 11
Algorithms – What is an Algorithm?
An Algorithm is a finite set of unambiguous
instructions which provides a solution to a
particular class of problems.
The creation of an algorithm may be viewed as an
intermediate step in writing a computer program for solving a
problem.
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 12
Algorithms – The Properties of Algorithms?
The five characteristics of a good algorithm in a
computing environment:
1 Precision – The instructions used must be precise.
It must use well-defined instructions set to perform.
2 Finiteness – It must reach a solution in finite time.
It must occupy limited space and take limited time to perform.
3 Generality – It must solve a whole class of problems.
It must not be designed to solve only a single specific
problem.
4 Effectiveness – It must perform efficiently.
It must solve the problem for which it is proposed in an
efficient manner measured in the number of steps to perform.
5 Consistency – It must be uniquely-defined.
There must not be two or more conflicting behaviors.
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 13
Algorithms – The Problem-Solving Process?
Generally, the evolution from problem to
program solution includes:
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 14
Algorithms – Representation of Algorithms?
Algorithms can be represented in several
different ways.
Commonly-used Techniques:
Flowcharts – is basically a pictorial view for illustrating
algorithms.
Pseudo Code – is a kind of structured English for
describing algorithms.
Other techniques:
Decision Tables
Data Flow Diagrams (DFDs).
Hierarchy Plus Input Output (HIPO).
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 15
Designing Algorithms using
FLOWCHARTS
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 16
Flowcharts – What is a Flowchart?
A Flowchart is a way of describing and
expressing an algorithm in a pictorial
representation.
It illustrates the actions to be carried out for solving
the problem through the interconnection of
specialized symbols with flow lines.
Flowchart Standards:
There are a standard set of symbols established by
the ANSI.
Also, other commonly-used conventions are there
such as: Gaddis, IBM, SDL, etc.
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 17
Flowcharts – Flowgorithm Flowcharting Tool
For demonstrating the use flowcharts to design
algorithms, a simple but powerful flowcharting
tool called Flowgorithm will be used here.
What does Flowgorithm can do for me?
Flowgorithm is a free application that helps you create
programs using simple flowcharts.
Flowgorithm supports all commonly used flowchart
standards.
Flowgorithm allows you to run and test your algorithm to
verify its correctness.
Flowgorithm can convert flowcharts to C++, C#, Java,
Python, Visual Basic.NET code as well as Gaddis
Pseudocode - used in the book “Starting out with
Programming Logic and Design" by Tony Gaddis.
Download URL: http://www.flowgorithm.org/index.htm
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 18
Flowcharts – Flowgorithm Flowchart Symbols
Everything in a flowchart is represented by a
specific shape as follows:
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 19
Flowcharts – Flowgorithm Live Demo
Think Design Draw Test
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 20
Designing Algorithms using
PSEUDOCODE
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 21
Pseudocode – What is a Pseudocode?
A Pseudocode is an informal high-level
description of the logic of an algorithm in a
program-like statements written in plain English.
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 22
Pseudocode – Pseudocode Example
C-Style Pseudo Code Example:
1 void function ShowOddEven
2 for (i = 1; i <= 100; i++) {
3 If i is divisible by 2
4 print i & " is EVEN NUMBER" & a newline;
5 else
6 print i & " is ODD NUMBER" & a newline;
7 }
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 24
Implementing Algorithms using
PROGRAMMING LANGUAGES
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 25
Computer Languages – What is a Language?
A Programming Language is a language
developed to express programs.
Machine Language: Native code, No compilation is needed!
All computers have a native programming language that they
understand, commonly referred to as machine code. However,
machine code is a difficult language for us to follow:
It is typically expressed in the binary number system, and
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 26
Translation Schemes – Why it is needed?
010101010101101101
011000111101010101
011011101010110100
011011101010110100
Compile-Time Run-Time
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 30
Translation Schemes – Hybrid Scheme
Hybrid (Mixed) Translation: is the combination of
both Interpreted and Compiled schemes.
// HelloWorld.cs 0100: 101101111
using System; 1002: 010111001
class Program { 1004: 001011110
static int main(void) 1006: 011011110
{ Console.Write( 1008: 101000010
"Hello, C# Prog. 100A: 111111000
…… World!\n"); It to intermediate Code 100B: 010110101
return 0; 100C: 101111110
} 100D: 000110100
} 100E: 000110100
LARGE
Pure Compiler
FAST
Implementation
Examples: Fortran, Pascal, C, C++
Executable Size
Execution Speed
Hybrid Pseudo-Code
Implementation
Examples: Java, Microsoft C# .NET
Pure Interpreter
SMALL
SLOW
Implementation
Examples: BASIC
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 32
Programming Languages – Evolution Process
Classification Levels of Programming Languages:
HUAMN LANGUAGE
HIGH LEVEL
LOW LEVEL
BINARY
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 33
Programming Paradigms – Evolution Process
The Program Design Philosophy Evolution
Process:
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 34
Programming Paradigms – Linear
Linear
Program
Skelton
Examples:
BASIC, Fortran
Advantages
Suitable for small programs.
Disadvantages
Difficult to debug.
Difficult to maintain.
Difficult to write large complex programs.
Sequential order programming prevents the use of teamwork.
Repetition (Redundancy) of instructions.
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 35
Programming Paradigms – Structured
Structured
Program
Skelton
Examples:
Pascal, C
Advantages
Easier to debug.
Easier to maintain.
Made it possible to write moderately complex programs fairly easily.
Modular design concept supports the use of teamwork.
Disadvantages
Global variables and shared data areas.
Difficult to establish very large programs.
Limited capabilities to reuse code in different projects.
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 36
Programming Paradigms – Object-Oriented
Object-Orientation (OO) is one of the
computational thinking methodologies which
implies that
Any system is composed of objects (certainly a
system is also an object).
e.g., Computer System, Educational System, Political System,
Economic System, Law System, etc.
The evolution and development of a system is caused
by the interactions among the objects inside or
outside the system.
Object 1
Object 4 Object 2
Object 3
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 37
Introduction to DSA – Homework
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 38
Introduction to DSA – Homework
Flowchart Representation Assignments:
1. Draw a flowchart to represent the algorithms shown in List
HW1.1 and List HW1.2.
C:\>DSA.exe
DSA Programming
with C#!
C:\>_
SUMMARY – Q & A
MOHY Mindworks Data Structures and Algorithms with C#, Copyright © 2017-2018 Ahmed Mohyeldin 44