0% found this document useful (0 votes)
28 views

Lecture 2 Data Structures Introduction

This document discusses programming, algorithms, and data structures. It defines programming as the process of problem solving by designing algorithms represented as step-by-step instructions. An algorithm is a problem solving process that arrives at a solution in a finite amount of time. The document also introduces data structures as organized ways to store and access data efficiently and examines complexity measures like time and space complexity for algorithms.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Lecture 2 Data Structures Introduction

This document discusses programming, algorithms, and data structures. It defines programming as the process of problem solving by designing algorithms represented as step-by-step instructions. An algorithm is a problem solving process that arrives at a solution in a finite amount of time. The document also introduces data structures as organized ways to store and access data efficiently and examines complexity measures like time and space complexity for algorithms.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Data Structures And

Algorithms
Lecture 2
Programming is problem solving
• Programming is a process of problem solving
• Problem solving Techniques
Analyze the problem
Outline the problem requirements
Specify what the solution should do
Design steps, called an algorithm to solve the problem
Verify that your solution solves the problem or not

Algorithm – a step by step problem solving process in which a solution is


arrived in a finite amount of time.
Computer Programming
Program = Algorithm + Data Structures

Computer programming is the process of creating instructions for a


computer to follow. These instructions, called code, are written in a
programming language, which is a set of rules that the computer
understands.

Set of instructions that tell the computer what to do and how to do.
Introduction to Problem solving
Programming is a problem-solving activity
When you write a program you are actually writing instructions for the
computer to solve something for you.

Problem solving is the process of transforming the description of a


problem into a solution by using the knowledge of that domain and by
using appropriate tools and techniques.
Case Study: Cup
cakes
•Problem: you are
required to calculate
the amount to be
paid by a customer
buying cupcakes
Software Development Method
We solve problem using software development method which is as
follows:

1. Specify the problem requirements


2. Analyze the problem
3. Design the algorithm to solve the problem
4. Implement the algorithm
5. Test and verify
6. Documentation
Requirement Specification
Specifying the problem requirements require you to clearly state the
problem and to gain the understanding of what to be solved and what
would be the solution.

When specifying requirements, we ask ourselves the following


questions.
• What the problem is
• What the solution should provide
• What is needed to solve it
• If there are constraints and special conditions
Case Study: Cup Cake
Input
Quantity of the cup cake purchased (integer)
Price per cupcake (float)
Output
Total amount to be paid by the customer (float)
Constraint/Condition
Quantity must be more than zero
Price must be more than zero
We assume that the price of cup cake is equal
Formula/Equation
Amount to pay = quantity of cupcake * price of cupcake
Data Structure is a systematic way to organize data in order to use it efficiently.
Following terms are the foundation terms of a data structure.
• Interface − Each data structure has an interface. Interface represents the set of
operations that a data structure supports. An interface only provides the list of
supported operations, type of parameters they can accept and return type of these
operations.
• Implementation − Implementation provides the internal representation of a data
structure. Implementation also provides the definition of the algorithms used in
the operations of the data structure.
Characteristics of a Data Structure
• Correctness − Data structure implementation should implement its interface
correctly.
• Time Complexity − Running time or the execution time of operations of data
structure must be as small as possible.
• Space Complexity − Memory usage of a data structure operation should be as
little as possible.
Execution Time Cases
• There are three cases which are usually used to compare various data structure's execution time in
a relative manner.
• Worst Case − This is the scenario where a particular data structure operation takes maximum time
it can take. If an operation's worst case time is ƒ(n) then this operation will not take more than ƒ(n)
time where ƒ(n) represents function of n.
• Average Case − This is the scenario depicting the average execution time of an operation of a data
structure. If an operation takes ƒ(n) time in execution, then m operations will take ƒ(n) time.
• Best Case − This is the scenario depicting the least possible execution time of an operation of a
data structure. If an operation takes ƒ(n) time in execution, then the actual operation may take time
as the random number which would be maximum as ƒ(n).
Algorithm Complexity
• Suppose X is an algorithm and n is the size of input data, the time and space used by the algorithm
X are the two main factors, which decide the efficiency of X.
• Time Factor − Time is measured by counting the number of key operations such as comparisons
in the sorting algorithm.
• Space Factor − Space is measured by counting the maximum memory space required by the
algorithm.
Algorithm Analysis
Efficiency of an algorithm can be analyzed at two different stages, before implementation and after
implementation. They are the following −
• A Priori Analysis − This is a theoretical analysis of an algorithm. Efficiency of an algorithm is
measured by assuming that all other factors, for example, processor speed, are constant and have
no effect on the implementation.
• A Posterior Analysis − This is an empirical analysis of an algorithm. The selected algorithm is
implemented using programming language. This is then executed on target computer machine. In
this analysis, actual statistics like running time and space required, are collected.
Designing of algorithm
Designing an algorithm is the process of creating a well-defined set of
instructions to solve a specific problem or perform a task.

• Understand the problem


• Plan and pseudocode
• Choose data structure
• Develop Algorithm
• Test and Debug
• Optimize the algorithm
Pseudocode
Pseudocode is a high-level description of an algorithm that uses a mixture
of natural language and code-like elements. It's not tied to any specific
programming language and is used to outline the logic of an algorithm in
a clear and understandable way. Pseudocode often includes elements such
as:
1.Variables: Names and types of variables used in the algorithm.
2.Control Structures: Like loops (for, while) and conditional statements
(if-else).
3.Operations: Mathematical or logical operations.
4.Comments: Explanatory notes to describe the steps and clarify the
code's intent.
Pseudocode for cup cake case study
BEGIN
pricePerCupcake = 2.50
totalCost = 0.0
DISPLAY "Welcome to the Cupcake Shop!"
INPUT "How many cupcakes would you like to buy? " INTO
numberOfCupcakes
totalCost = numberOfCupcakes * pricePerCupcake
DISPLAY "You are buying", numberOfCupcakes, "cupcakes."
DISPLAY "Total cost: $", totalCost
DISPLAY "Thank you for your purchase! Have a great day."
END
Flowchart
•Flowcharts are widely used in
process modeling, system
design, and algorithm planning
because they provide a clear
visual representation of how
steps are connected in a process
or algorithm. They are especially
useful for conveying complex
procedures in a simple and
intuitive manner.

You might also like