0% found this document useful (0 votes)
20 views47 pages

CE101 Lecture 1 Fall 2023 2024

Uploaded by

Noha Elzahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views47 pages

CE101 Lecture 1 Fall 2023 2024

Uploaded by

Noha Elzahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

CE 101

Structured Programming
and Data Structures.
Lecture 1
Prepared By:
Dr. Amr AbdelFatah
Thanks
"Self-discipline is the ability to make yourself do what you should
do when you should do it, whether you feel like it or not."
-Elbert Hubbard.
"We must all suffer from one of two pains: the pain of discipline or the
pain of regret. The difference is discipline weighs ounces while regret
weighs tons."
-Jim Rohn.
Golden Circle model: Simon Sinek’s theory
Our Protocol and Values
• Mutual Respect.
• Quality not Quantity.
• Ask (Why ? What ? How? ).
• Self-study and Mutual Learning.
• Sustainability (Paperless workflow)
• Open source (assignments word format or code ).
• We do not learn only for the exam.
Course Description
“Internal representation of data. An in-depth study of
recursion. Abstract data structures via pointers. Stacks,
queues, lists, trees, and graphs with applications.”
Course Hours
• 4 credit hours
• 4 hours per week for the lecture (2 Lectures per week)
• 1 hour for the tutorial (1 tutorial every two weeks)
• 1 hour for the Lab (1 lab every two weeks)
Week Lecture Topic
1 Introduction
2 Structured Programming Revision
3 Sort algorithms
4 Search Algorithms
5 The First Mid-Term Exam
6 Linked Lists (part 1)
7 Linked Lists (part 2)
8 Stacks (part 1)
9 Stacks (part 2)
10 The Second Mid-Term Exam
11 Queues
12 Trees
13 Graphs
14 Review and Discussion
1-4

Grading Scheme
• Assignments (Lectures + Tutorials + labs): 10 grades
• Solve case studies
• Research
• Micro-projects
• Lectures Oral Assessment: 5 grades
• Interaction
• Behavior and attitude
• Lab Exam: 5 grades
• The first Mid term exam 8 grades
• The second Mid term exam 12 grades
• The final exam 60 grades
1-5

Course Material and Lecturer contact


• Course Material → Course Team
• Lecturer Contact → [email protected]
1-6

How to score A in this course?


• Please do all practical and assignments.
• Study regularly.
• In case of problems, please ask questions.
• Accumulating problems will make things worse as the semester
goes by.

If the only objective to Score A so there is a problem !!


Textbook
C++ Programming :
Program Design Including Data
Structures
D. S. Malik
8th Ed 2018

1
Fall 2014
1
Structured Programming
and
Data Structures.
Structured Programming
and
Data Structures.
Structured programming
It is a technique for
organizing and coding programs based on an
Algorithm
that
reduces complexity,
improves clarity,
and
facilitates debugging and modifying.
From a Problem to Algorithm
• Problem:
• Description of Input-Output relationship
• Algorithm:
• A sequence of computational step that transform the input into the output.
• Data Structure:
• An organized method of storing and retrieving data.
• Our task:
• Given a problem, design a correct and good algorithm that solves it.

15
How do we solve problems?
• We "just do"
• Guesswork-and-luck
• Trial-and-error
• Experience (possibly someone else's)
• "Scientifically"

16
The Problem-solving Process
"Doctor, my head hurts"

Patient has elevated


Analysis pressure in anterior
Problem parietal lobe.
specification
1. Sterilize cranial saw
Design
2. Anaesthetize patient
3. Remove top of skull
Algorithm 4. Get the big spoon...
5. etc., etc.
Implementation sterilize(saw,alcohol);
raise_hammer();
Program lower hammer(fast);
start(saw);
/* etc. etc. */
Compilation
0100111010110010101010101001
0101010101001100101010101010
0101101001110101010101001001
Executable 0111010011110101010111110101
(solution) 01000110100001101...
17
Algorithm
Muhammad ibn Musa Al-Khwarizmi from Khwarazm
(now Khiva in Uzbekistan)
• Circa 780-850 C.E. (Common Era)
• a Persian mathematician, astronomer, and geographer during the
Abbasid Caliphate, a scholar in the House of Wisdom in Baghdad
• often considered one of the fathers of algebra

18
Algorithm -- Examples
• A cooking recipe
• Assembly instructions for a model
• The rules of how to play a game
• Description of a martial arts
technique
• Directions for driving from A to B
• A car repair manual
19
What is the specification of algorithm?
• We can specify an algorithm by 3 types:
1. Using Natural language
2. Pseudocode
3. Flowchart

20
Natural language
• Natural language is general way to solve any
problem
• For e.g to perform addition of two numbers we write
in natural language
Step1: read the first number (assume a)
Step2:read the second number (assume b)
Step3:add 2 numbers(a and b)and store the result in a variable c
Step4:display the result
Pseudocode
• Combination of natural language and programming language
construct
• For e.g.to perform addition of two numbers we write in
pseudo-code
//this algo perform addition of two integers
//input two integers a and b
// output of two integers
C=a+b
Write c
22
Pseudocode
• The benefit in using pseudo code lies in the strict adherence to structure in combination
with informal language.
IF [condition is true]
THEN [do statement 1]
ELSE BEGIN
[do statement 2]
[do statement 3]
END
• or
IF (the temperature is less than 20 degrees Celsius]
THEN [wear a jacket]
ELSE BEGIN
[wear a short sleeve shirt] [bring sunglasses]
END
Flow chart (Example 1)

24
Flow chart (Example 2)

25/49
The three structures
• All programming problems can be solved using three
structures:
• Statements
• Loops
• Choice
• The completeness of the three structures seems unlikely;
but, with the addition of nesting (structures within
structures), it is easily demonstrated that any programming
problem can be solved using only three structures.
Statements
• Statements provide the basic mechanism to do something.
• Possibilities include:
[count = 0]
PRINT_STRING("Select Option:")
• Anywhere a single statement can be used, a group of statements, or a
statement block, can be used.
BEGIN
[statement 1]
[statement 2]
[statement 3]
END
The Loop Structure
• Used to repeatedly perform an operation.
• Adding a series of numbers or searching a list for a
value are two examples of programming problems
that require loops.
• The term "iteration" is also used in this context.
• Although there are several possible forms of loops,
only two are necessary, WHILE/DO and REPEAT/UNTIL.
The Choice Structure
• The third basic structure is that of "choice"-the
programmer's "fork in the road”.
• The two most common arrangements are the
IF/THEN/ELSE statement and the CASE
statement.
Advantages of structured programming

• Simple to trace, thus facilitating debugging.


• Easy to read.
• Structures are easy to describe in flowcharts, syntax
diagrams and pseudo code.
Disadvantages of structured programming
• Only a few high-level languages (Pascal, C) accept the structures
directly; others require an extra stage of translation.
• Structured programs may execute slower and require more
memory than the unstructured equivalent.
• Some problems (a minority) are more difficult to solve using
only the three structures rather than a brute-force "spaghetti"
approach.
• Nested structures can be difficult to follow.
Structured Programming
and
Data Structures.
Structured Programming
and
Data Structures.
Data Structure

a particular way
of storing and organizing data
in a computer
so that
it can be used efficiently.
Data Structure
• Different kinds of data structures are suited to
different kinds of applications.
• Storing and retrieving can be carried out on data
stored in both main memory and in secondary
memory.
Data Structure
• The simplest data structure is the one-
dimensional (linear) array.
• Data items stored non-consecutively in
memory may be linked by pointers.
• Many algorithms have been developed for
storing data efficiently.
Data Structure Classification
• Primitive / Non-primitive
• Basic Data Structures available / Derived from Primitive Data
Structures
• Homogeneous / Heterogeneous
• Elements are of the same type / Different types
• Static / Dynamic
• memory is allocated at the time of compilation / run-time
• Linear / Non-linear
• Maintain a Linear relationship between element
ADT - General Concept
• Problem solving with a computer means processing
data.
• To process data, we need to define the data type and
the operation to be performed on the data
• The definition of the data type and the definition of
the operation to be applied to the data is part of the
idea behind an Abstract Data Type (ADT).
ADT Definition
In computer science, an abstract data type (ADT)
is
a mathematical model
for
a certain class of data structures
that
have similar behavior.
ADT in Simple Words
• Definition:
• Is a set of operation
• Mathematical abstraction
• No implementation detail
• Example:
• Lists, sets, graphs, stacks are examples of ADT
along with their operations
ADT - General Concept
• The user of an ADT needs only to know that a set of
operations are available for the data type, but does
not need to know how they are applied.
• Several simple ADTs, such as integer, real, character,
pointer and so on, have been implemented and are
available for use in most languages.
Primitive Data Types
• Languages like ‘C’ provides the following primitive data
types:
• boolean
• char, byte, int
• float, double
• Each primitive type has:
• A set of values
• A data representation
• A set of operations
Why ADT?
• Modularity
• divide program into small functions
• easy to debug and maintain
• easy to modify
• group work
• Reuse
• do some operations only once
• Easy to change the implementation
• transparent to the program
Implementing an ADT
• To implement an ADT, you need to choose:
• A data representation
• must be able to represent all necessary values of the ADT
• should be private
• An algorithm for each of the necessary operation:
• must be consistent with the chosen representation
• all auxiliary (helper) operations that are not in the contract should be
private
• Remember: Once other people are using it
• It’s easy to add functionality
Data Structure and Algorithms
Lists, Stacks, Queues Insert
Heaps Delete
Binary Search Trees
Find
AVL Trees
Hash Tables Merge
Graphs Shortest Paths
Disjoint Sets Union
Data Structures Algorithms
Used Everywhere!
Theory Graphics AI

Applications
Systems

Data Structures
Discussion
Thanks

You might also like