Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Chapter 1 Introduction To Data Structure

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 26

BENAZIR BHUTTO SHAHEED

UNIVERSITY LYARI, KARACHI

Department of Computing Science &


Information Technology
DATA STRUCTURES AND ALGORITHM
Lecture 1
Objectives
• Provide understanding with data storage concepts.
• Provide the concept of analysis of algorithm.
• Introduce the concept of data structures and their
implementation.
• Provide understanding the characteristics and optimal
behaviour of various types of structures.
Course Outline
• Array
• 2D Array
• Matrices algebra
• Linear Search
• Binary search
• Bubble, insertion, selection ,quick, merge sorts
• Infix to post fix evaluation
• List, Stack ,queue
• Link list, double link list, circular link list, link list as stack and queue
• Binary and binary search trees
• Heap and heap sort
• Dijikstra algorithm
• Prim’s and Kruskul’s algorithms
• Greedy algorithm
Recommended books
• Text Book
• Data Structures And Algorithms in C++, 4/e, Adam Drozdek
• Reference books
• Data Structures And Algorithms Analysis in C++, 3/e, Mark Allen
Weiss
• Data Structures Using C++,Varsha H. Patil
• Sedgwick R Algorithms in C++ Addison Wesley Reading, Mass
1998
• Knuth D, The Art of programming Vol 1,2,3,Addison Wesley
Reading Mass
Assessment breakdown(Theory)
100 marks
• Quizzes 05%
• Three quizzes
• Assignments 05%
• Two assignment
• Presentation 10%
• Class Participation/ Attend. 05%
• Total 25%

• Mid term 25%


• Final 50%
Assessment breakdown(Lab)
50 marks
• Quizzes 05%
• Two quizzes
• Assignments 10%
• Two assignment
• Lab Performance 10%
• (Weekly lab performance + lab file + attendance + Viva)
• Project 25%
• Group of 2-3 students
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.

• Data may be organized in many different ways, the


logical or mathematical model of a particular organization
of data in memory or on disk is called Data Structure.

Algorithms are used for manipulation of data.


What is Data Structure?
• There are three basic things associated with data
structures:

• space for each data item it stores


• time to perform each basic operation
• programming effort
Data Structure Operation
The data appearing in our data structure is processed by means of certain operations. The
particular data structure that one chooses for a given situation depends largely on the
frequency with which specific operations are performed. The following four operations play
a major role:

Traversing
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 structures
Linear Data Structure Non- Linear Data
data structure is said to Structure
be linear if its elements A non-linear structure is
form a sequence, or in mainly used to represent
other words a linear list. data containing a
hierarchical relationship
between elements.
• Array
• Tree
• Stack
• Graph
• Queue
• Linked List
Characteristic of Data Structure
Data Advantages Disadvantages
Structure
Arrays Quick insertion, very fast access if Slow search, Slow deletion,
index is known Fixed size
Ordered Quicker search than unsorted array. Slow insertion and deletion,
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 if Deletion algorithm is complex.
tree remains balance
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
Data Structure and Algorithms
• Algorithm: An algorithm is a finite set of instructions that
takes some raw data as input and transforms it into
refined data.
• An algorithm is a well-defined list of steps for solving
computational problem.
• Program: Program is an implementation of an algorithm in
some programming language.
• Data Structure: Organization of data needed to solve the
problem.
Algorithmic Problem

Specification of output
Specification of input
as a function of input

• Infinite number of input instances satisfying the


specification. For eg: A sorted, non-decreasing sequence
of natural numbers of non-zero, finite length:
• 1,20,908,909,100000,1000000000.
Algorithmic Solution

Input instance,
Output related to the
adhering to the Algorithm
input as required
specification

• Algorithm describes actions on the input instance.


• Infinitely many correct algorithms for the same algorithmic
problem.
What is a Good Algorithm?
• Efficient:
• Running time
• Space used
• Efficiency as a function of input size:
• The number of bits in an input number
• Number of data elements (numbers, points)
Analysis of Algorithms
• The theoretical study of computer program
• performance and resource.
• What is more important then performance?
• Why study algorithm and performance?
Analysis of Algorithm
• Asymptotic analysis attempts to estimate the resource
consumption of an algorithm.
• It allows us to compare the relative costs of two or more
algorithms for solving the same problem
• Asymptotic Notations are languages that allow us to analyze an algorithm's
running time by identifying its behavior as the input size for the algorithm
increases. This is also known as an algorithm's growth rate. ... Asymptotic
Notation gives us the ability to answer these questions.
• In mathematical analysis, asymptotic analysis, also known as asymptotic, is
a method of describing limiting behavior.
Asymptotic Analysis

• Goal: to ignore machine dependent constants


• Like “rounding”; 1,000,001=1,000,000
• 3n2=n2

• Capturing the core: how the running time of an algorithm


increases with size of the input in the limit.
Asymptotic Notation
• The “big-Oh” O-Notation:
• Asymptotic upper bound
• f(n)=O(g(n)), if there exists constant c and n0 s.t. f(n)< c g(n) for
n>no
• f(n) and g(n) are functions over non-negative integers.
• Drop low-order terms and
• Ignore leading constants.
• Eg: 3n3+90n2-5n+6= Ѳ(n2)
• Eg: 50 n log n =Ѳ(n log n)
Asymptotic Analysis of Running Time
• Use O notation to express number of primitive operations
executed as function of input size.
• Comparing asymptotic running times
• An algorithm that runs in O(n) time is better than one that runs in
O(n2) time
• Similarly, O(log n ) I better than O(n)
• Hierarchy of functions: log n<n<n2,n3<2n
• Caution! Beware of very large constant factors. An
algorithm running in time 1,000,000 n is still O(n) but
might be less efficient than one running in time 2n2 which
is O(n2)
Example of Asymptotic Analysis
• Algorithm prefixAverages1(X):
• Input: An n-element array X of number
• Output: An n-element array A of numbers such that A[i] is
the average of elements x[0],……x[i].
for i=0 to n-1
a=0
for j=0 to I
a=a+x[j] n2
A[i]=a/(i+1) n
Return array A
Analysis: Running time is O(n2)
A Better Algorithm

• Algorithm prefixAverages2(X):
• Input: An n-element array X of number
• Output: An n-element array A of numbers such that A[i] is
the average of elements x[0],……x[i].
S=0
for i=0 to n
s=s+X[i]
A[i]=s/(i+1)
return array A
Analysis: Running time is O(n)
Asymptotic Notation(terminology)
• Special classes of algorithms:
• Logarithmic: O(log n)
• Linear: O(n)
• Quadratic: O (n2)

• Polynomial: O (nk), k> 1


• Exponential: O (an), a>1
• “Relatives” of the Big-O
• Ω (f(n)): Big Omega-asymptotic lower bound
• Ѳ (f(n)): Big Theta-asymptotic tight bound
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.

 So if your problem is taking a long time but not much


memory, a space-time tradeoff would let you use more
memory and solve the problem more quickly.

 Or, if it could be solved very quickly but requires more


memory than, you can try to spend more time solving the
problem in the limited memory.

You might also like