data structure using c - glocal university

25
Data Structure Using C

Upload: others

Post on 18-Dec-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Data Structure Using C

The Skill of programming Programming is a skill that must be developed.

Driving a car cannot be learned by reading a book only, you must practice.

Programming is also a skill and cannot be learned by reading a book only, YOU MUST PRACTICE.

Attend class sessions and do assignments individually.

What is a Program? An algorithm consists of a set of explicit and

unambiguous finite steps which, when carried out for a given set of initial conditions, produce the corresponding output and terminate in a finite time.

An algorithm is correct if for every input instance, it halts with the correct output.

An algorithm corresponds to a solution to a problem that is independent of any programming language.

A program may also be thought of as an algorithm expressed in a programming language.

The Problem-Solving Aspect

I. Problem Definition Phase

II. Getting started on a problem

III. The use of specific examples

IV. Similarities among problems

V. Working backwards from the solution

VI. General problem solving strategies

Divide and Conquer

Dynamic Programming (Greedy Search, Backtracking, Branch and Bound)

Top – Down Design

A solution method where the problem is broken down into smaller subproblems, which in turn are broken into smaller problems until each subproblem can be solved in a few steps. (Also called Divide and Conquer)

Top-Down Design ↔Step-wise Refinement ↔ Modular Programming

Top-down Design

Advantages of Top-Down Design Breaking the problem into parts helps us to clarify what

needs to be done.

At each step of refinement, the new parts become less complicated and, therefore, easier to figure out.

Parts of the solution may turn out to be reusable.

Breaking the problem into parts allows more than one person to work on the solution.

Structured ProgramsWe will use top-down design for all remaining

programming projects.

Programs produced using this method and using only the three kinds of control structures: sequential, selection and repetition are called structured programs.

Structured programs are easier to test, modify, and are also easier for other programmers to understand.

Structured Programming Structured programming is a programming paradigm

aimed at improving the clarity, quality, and development time of a computer program by making extensive use of the structured control flow constructs of selection (if/then/else) and repetition (while and for), block structures, and subroutines.

E.g. ALGOL, Pascal, PL/I and Ada

Design Specification There are two commonly used tools to help to document

program logic (the algorithm).

These are: Module Structure Chart (Hierarchical Tree)

Outlining (writing decomposition)

Pseudo code (mixture of English and C)

Flowcharting

Generally, flowcharts work well for small problems but Pseudocode is used for larger problems.

We will use both methods here.

Module Chart Format

Outline Design Example

Pseudocode Design Example

Top-down Design Example

Top-down Design Example

Another Example Problem: Write a program that draws this picture of a

house.

The Top Level Draw the outline of the house

Draw the chimney

Draw the door

Draw the windowsMain

DrawChimney

DrawDoor

DrawWindows

DrawOutline

Bottom-up Design

In a bottom-up approach the individual base elements of the system are first specified in great detail.

These elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is formed.

Bottom-up Design

Major steps in the Program development Cycle

Analyze: Define the problem

Design: Plan the solution to the problem

Develop the Interfaces to the program

Code: Translate to programming language

Debug and Test Make sure program is error free

Documentation: Organize all the required materials

to describe the program.

Programming Languages We cannot program a computer using Natural

languages such as Chinese or English – too ambiguous.

Programming languages are very structured to eliminate ambiguity.

A Computer Programming Language provides an unambiguous and precise way of specifying a set of instructions to a computer.

Machine Languages, Assembly Languages, and High-level LanguagesThree types of programming languages

1. Machine languages Strings of numbers giving machine specific instructions

Example:1100110011001100

0101010101010101

2. Assembly languages English-like abbreviations representing elementary computer

operations (translated via assemblers)

Example:LOAD BASEPAY

ADD OVERPAY

STORE GROSSPAY

Machine Languages, Assembly Languages, and High-level LanguagesThree types of programming languages (continued)

3. High-level languages

Codes similar to everyday English

Use mathematical notations (translated via compilers)

Example:

grossPay = basePay + overTimePay

The Evolution

The principal paradigms Imperative Programming (C)

Object-Oriented Programming (C++, Java)

Logic/Declarative Programming (Prolog)

Functional Programming (Lisp)