Lecture#2
Lecture#2
PROGRAMMING
FUNDAMENTALS
Activity Time
8-ball problem.
Problem Statement
You are given 8 identical looking balls. One of
them is heavier than the rest of the 7 (all the
others weigh exactly the same). You are
provided with a simple mechanical balance, and
you are restricted to only 2 uses of it.
13-ball problem.
ALGORITHM
• A sequence of instruction or steps to perform a certain task.
• An algorithm is a sequence of unambiguous instructions/operations
for solving a problem, i.e., for obtaining a required output for any
legitimate input in a finite amount of time.
ALGORITHM
Correct vs. Incorrect Algorithms
• We say that an algorithm is correct when:
✓ It finds a solution in a finite number of steps.
✓ It translates every input instance into the
correct output.
• Definition: algorithm
Dictionary definition:
• Computer Algorithm:
• Take 2 pieces of paper and write on one piece "A" and on the other
piece "B":
Human
Algorithm Instruction
Language Computer’s
Pictorial
Language
Representation
Flowchart Program
Data
Constant Variable
Flowchart
A good flowchart should communicate a process clearly and effectively. When
starting out, it's a good idea to focus on a few steps.
Most flowcharts should be built using only the Start/End and Action or Process
symbols and should follow a very basic set of best practices. Sticking to these
primary flowchart symbols is the best way to ensure that your diagram will be
easy to understand.
Algorithm Example 1
Pseudo Code
Input the length in feet (Lft)
Calculate the length in cm (Lcm) by multiplying LFT with 30
Print length in cm (LCM)
Algorithm Example 2