Lec1-Introduction To Data Structure and Algorithms
Lec1-Introduction To Data Structure and Algorithms
Tazeen Muzammil
• Teacher’s Name: Tazeen Muzammil
•
• Course Code: CSC-260
Quizzes 10
Mid–Term Examination 20
Final Examination 50
Labs 10
Project 10
Total 100
Goals of this Course
• The objective of this course is to
introduce the analysis and designing of
data structures using various standard
algorithms.
• Cover well-known data structures such
as dynamic arrays, linked lists, stacks,
queues, trees and graphs.
• Implement data structures in C++
Data Representation
• A computer is a machine that
manipulates data.
• The prime aim of data structure
includes to study how data is
organized in a computer, how it is
manipulated, how it is retrieved, and
how it can be utilized, resulting in
more efficient programs.
What is Data Structure?
• In computer science, a data structure is a
particular way of storing and organizing data in
a computer so that it can be used efficiently.
Transversing
Accessing each record exactly once so that certain items in the record may be
processed.(This accessing or processing is sometimes called 'visiting" the records.)
Searching
Finding the location of the record with a given key value, or finding the locations of
all records, which satisfy one or more conditions.
Inserting
Adding new records to the structure.
Deleting
Removing a record from the structure.
Types of Data Structure
Arrays Quick insertion, very fast access if Slow search, Slow deletion,
index is known Fixed size
Ordered Quicker search than unsorted Slow insertion and deletion,
Array array. Fixed size
Stack Provides last-in first-out access Slow access to other items
Queue Provides first-in first-out access Slow access to other items
Linked List Quick insertion and quick deletion Slow search
Binary Trees Quick search, insertion and Deletion algorithm is
deletion if tree remains balance complex.
Hash Table Very fast access if key known, Fast Slow deletion, access slow if
insertion. key not known, inefficient
memory usage
Heap Fast insertion ,deletion. Access to Slow access to other items
largest item
Graph Models real world situation Some algorithms are slow
and access.
What is an Algorithm?
• An algorithm is a finite set of
instructions that takes some raw
data as input and transforms it into
refined data.
Space Complexity
• Amount of Computer memory
required during the program
execution, as a function of input size.
Asymptotic Notation
• Helps to compare algorithms.
• Suppose we are considering two algorithms, A and
B, for solving a given problem. Furthermore, let us
say that we have done a careful analysis of the
running times of each of the algorithms and
determined them to be Ta(n) and Tb(n),
respectively, where n is a measure of the problem
size. Then it should be a fairly simple matter to
compare the two functions and to determine which
algorithm is the best!
Types of Analysis
• Types of Analysis
– Worst case running time
– Average case running time
– Best case running time
Worst case Running Time
• The behavior of the algorithm with respect to
the worst possible case of the input instance.
• The worst-case running time of an algorithm is
an upper bound on the running time for any
input. Knowing it gives us a guarantee that the
item does not occur in data.
• There is no need to make an educated guess
about the running time.
Average case Running Time
• The expected behavior when the input is randomly
drawn from a given distribution.
• The average-case running time of an algorithm is an
estimate of the running time for an "average" input.
• Computation of average-case running time entails
"knowing all possible input sequences, the
probability distribution of occurrence of these
sequences, and the running times for the individual
sequences”.
• Often it is assumed that all inputs of a given size are
equally likely.
Best case Running time
• The behavior of the algorithm when
input is in already in order.
• For example in sorting, if elements are
already sorted for a specific algorithm.
• The best case running time rarely
occurs in practice comparatively with
the first and second case.
Time-Space Tradeoff
• In computer science, a space-time or time-memory
tradeoff is a way of solving a problem or calculation in
less time by using more storage space (or memory), or by
solving a problem in very little space by spending a long
time.