data structure - lecture 1 introduction]
DESCRIPTION
Computer Science CourseTRANSCRIPT
![Page 1: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/1.jpg)
Instructor : Kiran Ijaz Lecture : 01Date : 5th August, 2008
![Page 2: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/2.jpg)
Session Outline and Learning OutcomesThe learning outcomes of the session
are to:Understand the contents and requirements
of the courseUnderstand the fundamental concepts
behind computer programsDefine Data Structures and their purpose
along with their associated operationsUnderstand and practically apply the
Performance Measures of Algorithms through Time Complexity Analysis
![Page 3: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/3.jpg)
Life Lines for Course Execution Instructor: Kiran Ijaz
Office: N -111B email: [email protected]
Online course content & coordination: Course Folder:
\margala\DS_C&D_Fall08 Group Home Page:
Will be announced in next calss Course Yahoo Group Email:
Will be announced in next calssTeaching Assistant: Tayyab Bin Tariq & Ehtasham-ul-HaqOffice Hours:
Monday : 12:00 to 2:30 Wednesday: 1:00 to 2:00 Friday: 10:30 to 12.30
![Page 4: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/4.jpg)
Course ContentsIntroductionAlgorithm Complexity AnalysisSimple Data Types and Abstract Data TypesArrays and ListsElementary Data StructuresStack and QueuesRecursion and Time Complexity of Recursive
AlgorithmsTrees and GraphsSet structureSearching techniquesHashingSorting techniques
![Page 5: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/5.jpg)
Textbooks and Supplementary Reading ListIntroduction to Algorithms by Thomas
H. Cormen et alData Structures and Algorithms by A. V.
Aho, J. E. Hopcroft, J. D. UllmanData Structures using C and C++ 2nd
Edition by Yedidyah Langsam, Moshen J. Augenstein and Aaron M. Tenenbaum
Theory and problem of Data structures By Seymour Lipschutz
![Page 6: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/6.jpg)
AssessmentAssignments 10%Quizzes (Not Announced) 10%Project 15%Mids 25% (12.5+12.5)Final 40%
No retake of quizzes, mids or finalNo extension in deadline of assignments and projectSubmission guidelines must be followedSubmit compressed files (Winzip Only) Name your submission folder in the format
RollNo_Name_Assessment# e.g. 302_kiran_Assessment#3
![Page 7: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/7.jpg)
Labs and Tutorials3 Credit Course with no regular labTutorials can be arranged if needed
Attendance is Compulsory
Make Groups of 3s for Lab and Class assignments
![Page 8: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/8.jpg)
Importance of FeedbackRegular Feedback and Constant Interaction is
ExpectedShow full involvement and Participation in
the CourseHave Trust and Faith!
![Page 9: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/9.jpg)
Introduction
![Page 10: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/10.jpg)
Computer Program
What is a Computer Program?
Input(DS)
Process(Algorithm)
Output(DS)
Data Structures+Algorithms=Programs
ProblemSolution
![Page 11: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/11.jpg)
Data structures let the input and output be represented in a way that can be handled efficiently and effectively.
Array
Linked List
TreeQueue
Stack
![Page 12: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/12.jpg)
Data Structures: Formal DefinitionData may be organized in different ways
Data structure is the logical or mathematical model of a particular organization of data
Must be rich enough to mirror the actual relationships of the data in the real world
Simple
![Page 13: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/13.jpg)
The Need for Data StructuresGoal: to organize data
Criteria: to facilitate efficient storage of dataretrieval of data manipulation of data
Design Issue: select and design appropriate data types.
(This is the real essence of OOP.)
![Page 14: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/14.jpg)
Data Structure OperationsTraversing
Accessing each record exactly once so that certain items in the record may be processed
Searching Finding the location of the record with the given key value
or finding the location of all records which satisfy one or more conditions
Insertion Adding a new record to the structure
Deletion Removing a record from the structure
Sorting Arrange the records in a logical order
Merging Combining records from two or more files or data
structures into one
![Page 15: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/15.jpg)
Program Efficiency & Complexity Analysis of Algorithms
![Page 16: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/16.jpg)
Steps Involved In Writing A Computer ProgramProblem formulation & specification
Design of solution
Implementation
Testing
Documentation
Evaluation of the solution
![Page 17: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/17.jpg)
Problem Formulation & SpecificationHalf the battle is knowing what
problem to solveMost problems have no simple precise
specification.Some problems are impossible to
formulate.Identify the problem parametersExpressing the problem by a formal
model.Looking for a solution for the modelIn the absence of a solution, discover
about the model
![Page 18: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/18.jpg)
What is an Algorithm?An algorithm is a definite procedure for
solving a problem in finite number of steps
Algorithm is a well defined computational procedure that takes some value(s) as input, and produces some value(s) as output
Algorithm is finite number of computational statements that transform input into the output
Algorithm Definition : A finite set of statements that guarantees an optimal solution in finite interval of time
![Page 19: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/19.jpg)
What is an Algorithm? Finite sequence of instructions
An input should not take the program in an infinite loop
Each instruction having a clear meaning Very subjective. What is clear to me, may not be clear to you.
Each instruction requiring finite amount of effortVery subjective. Finite on a super computer or a P4?
Each instruction requiring finite time to completeVery subjective. 1 min, 1 hr, 1 year or a lifetime?
![Page 20: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/20.jpg)
Favorite AlgorithmsTakes less memory (Space Efficient)Smaller execution timeSmaller programming timeTime complexity (most important)
![Page 21: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/21.jpg)
Efficient AlgorithmsConsumes lesser amount of resources while
solving a problem of size nMemoryTime
So do we just measure the processor time?
![Page 22: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/22.jpg)
Measuring EfficiencyThe efficiency of an algorithm is a
measure of the amount of resources consumed in solving a problem of size n.
The resource we are most interested in is time We can use the same techniques to analyze the
consumption of other resources, such as memory space.
It would seem that the most obvious way to measure the efficiency of an algorithm is to run it and measure how much processor time is needed
Is it correct??
![Page 23: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/23.jpg)
Real Time Execution Vs. Algorithm ComplexitySame algorithms running on different
processors, don’t take the same time, why?Processor speedProcessor typeProgramming languageQuality of compilerSize and nature of inputOperating system
![Page 24: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/24.jpg)
Running Time of an AlgorithmFactors affecting running time:
Nature of inputNumber of inputNumber of steps/primitive operations
Running time is measured in terms of number of steps/primitive operations.
Generally time grows with size of input, so running time of an algorithm is usually measured as function of input size.
Independent from machine, OSWould not vary from processor to
processor as algorithm steps would remain the same
![Page 25: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/25.jpg)
Analyzing an AlgorithmFinding running time of an
AlgorithmRunning time is measured by number of
steps/primitive operations performedSteps means elementary operation like
,+, *,<, =, A[i] etc We will measure number of steps taken in
term of size of input
![Page 26: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/26.jpg)
Analysis of AlgorithmsAssume input size to be N/nPrimitive steps: +,-,*,/,= etc.What about loops and control structures?
![Page 27: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/27.jpg)
Simple Example (1)// Input: int A[N], array of N integers// Output: Sum of all numbers in array A
int Sum(int A[], int N) { int s=0; for (int i=0; i< N; i++) s = s + A[i]; return s;}
How should we analyse this?
![Page 28: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/28.jpg)
Simple Example (2)// Input: int A[N], array of N integers// Output: Sum of all numbers in array A
int Sum(int A[], int N){ int s=0;
for (int i=0; i< N; i++)
s = s + A[i];
return s;}
1
2 3 4
5 6 7
8
1,2,8: Once3,4,5,6,7: Once per each iteration of for loop, N iterationTotal: 5N + 3The complexity function of the algorithm is : f(N) = 5N +3
![Page 29: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/29.jpg)
Simple Example (3) Growth of 5n+3
Estimated running time for different values of N:
N = 10 => 53 stepsN = 100 => 503 stepsN = 1,000 => 5003 stepsN = 1,000,000 => 5,000,003 steps
As N grows, the number of steps grow in linear proportion to N for this function “Sum”
![Page 30: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/30.jpg)
What Dominates in Previous Example?What about the +3 and 5 in 5N+3?
As N gets large, the +3 becomes insignificant5 is inaccurate, as different operations require
varying amounts of time and also does not have any significant importance
What is fundamental is that the time is linear in N.Asymptotic Complexity: As N gets large, concentrate on the highest order term:
Drop lower order terms such as +3 Drop the constant coefficient of the highest
order term i.e. 5
![Page 31: Data Structure - Lecture 1 Introduction]](https://reader034.vdocuments.mx/reader034/viewer/2022050705/546b5b1faf795962298b4b7a/html5/thumbnails/31.jpg)
Asymptotic ComplexityThe 5N+3 time bound is said to "grow
asymptotically" like N This gives us an approximation of the
complexity of the algorithm Ignores lots of (machine dependent) details,
concentrate on the bigger picture