Top Banner
Data Structure Using C
25

Data Structure Using C - Glocal University

Dec 18, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data Structure Using C - Glocal University

Data Structure Using C

Page 2: Data Structure Using C - Glocal University

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.

Page 3: Data Structure Using C - Glocal University

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.

Page 4: Data Structure Using C - Glocal University

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)

Page 5: Data Structure Using C - Glocal University

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

Page 6: Data Structure Using C - Glocal University

Top-down Design

Page 7: Data Structure Using C - Glocal University

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.

Page 8: Data Structure Using C - Glocal University

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.

Page 9: Data Structure Using C - Glocal University

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

Page 10: Data Structure Using C - Glocal University

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.

Page 11: Data Structure Using C - Glocal University

Module Chart Format

Page 12: Data Structure Using C - Glocal University

Outline Design Example

Page 13: Data Structure Using C - Glocal University

Pseudocode Design Example

Page 14: Data Structure Using C - Glocal University

Top-down Design Example

Page 15: Data Structure Using C - Glocal University

Top-down Design Example

Page 16: Data Structure Using C - Glocal University

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

house.

Page 17: Data Structure Using C - Glocal University

The Top Level Draw the outline of the house

Draw the chimney

Draw the door

Draw the windowsMain

DrawChimney

DrawDoor

DrawWindows

DrawOutline

Page 18: Data Structure Using C - Glocal University

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.

Page 19: Data Structure Using C - Glocal University

Bottom-up Design

Page 20: Data Structure Using C - Glocal University

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.

Page 21: Data Structure Using C - Glocal University

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.

Page 22: Data Structure Using C - Glocal University

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

Page 23: Data Structure Using C - Glocal University

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

Page 24: Data Structure Using C - Glocal University

The Evolution

Page 25: Data Structure Using C - Glocal University

The principal paradigms Imperative Programming (C)

Object-Oriented Programming (C++, Java)

Logic/Declarative Programming (Prolog)

Functional Programming (Lisp)