Data Structures
Kashif Javed
kashifjaved.uet.edu.pk
Department of Electrical Engineering
UET Lahore
A challenging course
Intensive programming
Intensive (mathematical and logic) thinking
Chapter 1
Introduction
Algorithm 1
• Read N numbers into an array
• Sort the array in decreasing order by some
simple algorithm
• Return the element in position k
Exponents Logarithms
XA•XB = X A+B All logarithms are to the
XA XB = X A-B base 2, unless otherwise
specified
(XA) B = X A•B
Definition:
XA + XA = 2•XA X2•A
XA = B if and only if
2N + 2N = 2•2N = 2N+1
logX B = A
logC B
logAB = ; A,B,C > 0 , A 1
logC A
2i = 2N+1 - 1
i=0..N
AN+1 - 1
Ai =
i=0..N A -1
1
If 0 < A < 1, Ai
i=0..N
A-1
1
If N , Ai =
i=0..N
A-1
Copyright © Kashif Javed Introduction 1-19
Mathematics review…
Arithmetic Series
N(N+1)
i =
2
i=1..N
Proof By Induction
Given a theorem
Show that
Fi < (5/3) i , for i 1
Inductive Hypothesis:
Fi < (5/3) i , for i = 1, 2, ..., k
Copyright © Kashif Javed Introduction 1-23
Mathematics review…
Proof By Induction – example…
Now prove that Fk+1 < (5/3)k+1
Recursive function
a function that is defined in terms of itself
Making progress
• For cases that are to be solved recursively, the
recursive call must always be to a case that
makes progress toward the base case
In the mathematical
review,
Logarithms
Arithmetic series
Geometric Series
Mathematical induction