0% found this document useful (0 votes)
27 views29 pages

Data Structures and Algorithms Chapter 1

This document provides an introduction to data structures and algorithms through a chapter overview of a textbook. It discusses: 1) The objectives of understanding abstraction, problem solving processes, and implementing abstract data types through Python programming. 2) Computer science as the study of problems, algorithms as step-by-step solutions, and the role of abstraction in managing complexity. 3) Python as an easy-to-learn object-oriented language with built-in data types and control structures that allows reviewing algorithms through interactive sessions.

Uploaded by

maya khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
27 views29 pages

Data Structures and Algorithms Chapter 1

This document provides an introduction to data structures and algorithms through a chapter overview of a textbook. It discusses: 1) The objectives of understanding abstraction, problem solving processes, and implementing abstract data types through Python programming. 2) Computer science as the study of problems, algorithms as step-by-step solutions, and the role of abstraction in managing complexity. 3) Python as an easy-to-learn object-oriented language with built-in data types and control structures that allows reviewing algorithms through interactive sessions.

Uploaded by

maya khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 29

Data Structures and Algorithms

Chapter 1 Slides Set 1

Mutee U Rahman, PhD


Introduction

Book:
Problem Solving with Algorithms and Data
Structures By Brad Miller, David Ranum
Chapter 1: Introduction

Objectives
• To review the ideas of computer science,
programming, and problem-solving.
• To understand abstraction and the role it plays
in the problem-solving process.
• To understand and implement the notion of an
abstract data type.
• To review the Python programming language.
Introduction
• Problems
• Problem Solutions
• Algorithms
• Programs

The science of computing is concerned with using


computers to solve problems.
What is Computer Science?
• Computer science is the study of problems, problem-
solving, and the solutions that come out of the problem-
solving process.
• Given a problem, a computer scientist’s goal is to develop
an algorithm, a step-by-step list of instructions for solving
any instance of the problem that might arise.
• Computer science can be thought of as the study of
algorithms.
• However, we must be careful to include the fact that some
problems may not have a solution
• We say that a problem is computable if an algorithm exists
for solving it.
What is Computer Science?
• An alternative definition for computer science,
then, is to say that computer science is the
study of problems that are and that are not
computable, the study of the existence and the
nonexistence of algorithms
• You will note that the word “computer” did not
come up at all.
• Solutions are considered independent from the
machine.
What is Computer Science?
• Computer science, as it pertains to the problem-
solving process itself, is also the study of
abstraction.
• Abstraction allows us to view the problem and
solution in such a way as to separate the so-
called logical and physical perspectives
• Interface abstraction
• Procedural abstraction
What Is Programming?
• Programming is the process of taking an
algorithm and encoding it into a notation, a
programming language, so that it can be
executed by a computer
• Computer science is not the study of
programming.
• Programming, however, is an important part of
what a computer scientist does
• All data items in the computer are represented as
strings of binary digits.
• In order to give these strings meaning, we need to
have data types.
• Data types provide an interpretation for this binary
data so that we can think about the data in terms
that make sense with respect to the problem
being solved.
• These low-level, built-in data types (sometimes
called the primitive data types) provide the
building blocks for algorithm development.
• The difficulty that often arises for us is the fact
that problems and their solutions are very
complex.
• These simple, language-provided constructs
and data types, although certainly sufficient to
represent complex solutions, are typically at a
disadvantage as we work through the problem-
solving process.
• We need ways to control this complexity using
abstractions
Why Study Data Structures and
Abstract Data Types?
• To manage the complexity of problems and the
problem-solving process, computer scientists
use abstractions to allow them to focus on the
“big picture” without getting lost in the details.
• Process abstraction and data abstraction
• Abstract Data Types (ADTs)
Why Study Algorithms?
• Algorithms are solutions
• One problem may have many solutions
• How to compare the solutions?
• How to find the best solution?

we learn analysis techniques that allow us to compare and contrast


solutions based solely on their own characteristics, not the characteristics
of the program or computer used to implement them
Complexity and Decidability

Problems

Decidable Undecidable

Tractable Intractable
Python Introduction
• Python is a modern, easy-to-learn, object-
oriented programming language.
• It has a powerful set of built-in data types and
easy-to-use control constructs.
• Since Python is an interpreted language, it is
most easily reviewed by simply looking at and
describing interactive sessions.
Every piece of data is object
• In python everything is an object
• What is an object:
• It has data (state) and methods (the interface)
• A class defines how an instance of a object
behaves
• Actual data items are called objects
• “an object is a instance of a class”
Built in Atomic types
• Two numeric types:
• int ( holds whole numbers, no limits)
• float (holds floating point numbers – 64 bit )
• Standard operators + - * /
Note that / on two integers will result in float
(2.7 python does integer divide)
• % does modulus as in C++ and java
• // will always do integer divide in python 3+
• ** does power (exponentiation) i.e. 2**8
The None type
• A variable may be assigned the special value
None to indicate it does not have a value
• None evaluates to False
Lets look at examples
•+-
• / in 3.4 create float result
• // does integer divide
• % does modulus
• ** does power
• and or True False not
boolean type and compare ops
• Boolean type has values True and False
• You can use the operators not and or
False or True
Not (False and True)
• You can use all the comparison ops
> >= < <= == and != as in C++ and java
• but you can't use && or || or ! for boolean
operators
Assignment Op
• = is the assignment operator
• a variable is created when its name is used the
first time on the left of a = operator
• the variable will point to the data that is the result
of the expression on the right side.
• It is the data (object) that has the value and type,
not the variable
• Example:
amount = 45.55 # amount variable is created,
and it refers to a float object with value 45.55
assignment with existing
variable
• When a variable already exists, and you assign
a new value to it, then the variable will now
point to the new value.
x = 199 x is created and it is assigned to point to int
object with data 00

x = "abc" x is assigned to point to new object type str


with value of "abc", it no longer points to old 199
Each assignment creates
a new memory location
for new object
after 1
theSum = 1 type int

theSum
Each assignment creates
a new memory location
for new object
after 1
theSum = 1 type int

theSum
then after 2
theSum = 2 type int

theSum
Each assignment creates
a new memory location
for new object
after 1
theSum = 1 type int

theSum
then after 2
theSum = 2 type int

theSum
then after "abc"
theSum = "abc" type str

theSum
Precedence table from lowest to highest priority
Operator Description
lambda Lambda expression
if – else Conditional expression
or Boolean OR
and Boolean AND
not x Boolean NOT
in, not in, is, is not, Comparisons, including
<, <=, >, >=, !=, == membership tests and identity tests
| Bitwise OR
^ Bitwise XOR
& Bitwise AND
<<, >> Shifts
+, - Addition and subtraction
*, /, //, % Multiplication, division, remainder
+x, -x, ~x Positive, negative, bitwise NOT
** Exponentiation
x[index], x[index:index], Subscription, slicing,
x(arguments...), x.attribute call, attribute reference

(expressions...), [expressions...], Binding or tuple display, list display,


{key:value...}, {expressions...} dictionary display, set display
Class in Python
Operator Overloading
• It makes it possible for the programmer to interact with
objects in a very natural way.
• Operator overloading is already implemented for a variety of
the built-in classes or types in various programming
languages including python
• Many languages support Operator Overloading
• Support here means that you can overload operators for
your own data types / classes
• Python programmers often call these operators Magic Methods
because a method automatically gets called when an operator is
used in an expression
Python Magic Methods
Operator Overloading

You might also like