0 Up votes0 Down votes

1 views33 pagesdata structure

Jan 31, 2019

© © All Rights Reserved

- Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
- Hidden Figures Young Readers' Edition
- The Law of Explosive Growth: Lesson 20 from The 21 Irrefutable Laws of Leadership
- The Art of Thinking Clearly
- The E-Myth Revisited: Why Most Small Businesses Don't Work and
- The Wright Brothers
- The Other Einstein: A Novel
- State of Fear
- State of Fear
- The Power of Discipline: 7 Ways it Can Change Your Life
- The Kiss Quotient: A Novel
- The 10X Rule: The Only Difference Between Success and Failure
- Being Wrong: Adventures in the Margin of Error
- Algorithms to Live By: The Computer Science of Human Decisions

You are on page 1of 33

Data Structures

Kashif Javed

kashifjaved.uet.edu.pk

Department of Electrical Engineering

UET Lahore

Course Overview

A fundamental computer science course

Prerequisite for “design and analysis of

Algorithms” taught in 6th term

A challenging course

Intensive programming

Intensive (mathematical and logic) thinking

Copyright © Kashif Javed Introduction 1-3

Prerequisites

Computer Fundamentals

• Functions, Pointers, Arrays , Structures, Recursion

User-level knowledge of Operating Systems

• Windows

• Linux

First some course terminology

in order to facilitate access and modifications

so it is important to know the strengths and limitations

of several of them

First some course terminology

procedure that takes some values, as input and

produces some value, or set of values, as output

requires in the memory determine its efficiency

be used wisely

Course Objectives

This course will help the students

collections of data to be processed by a program

focus is on main-memory data structures

algorithms

(ADTs)

Course Outline

Introduction (1)

Algorithms and Analysis (2)

Lists, Stacks, Queues (3)

Trees (4)

Hashing (5)

Priority Queues (6)

Sorting (7)

EE 232 Data Structures

Session-11 , Spring-13

Chapter 1

Introduction

Chapter 1: Introduction

Our goals: we shall

goals of this course recursion

and briefly review

programming concepts

mathematical

background

Chapter 1: roadmap

1.1 What’s the book about?

1.2 Mathematics review

1.3 A Brief Introduction to Recursion

What's the book about?

Selection Problem

Given a list of N numbers, determine the kth largest,

where k N

Algorithm 1

• Read N numbers into an array

• Sort the array in decreasing order by some

simple algorithm

• Return the element in position k

What's the book about?...

Algorithm 2

• Read the first k elements into an array and sort

them in decreasing order

• Each remaining element is read one by one

• If smaller than the kth element, then it is ignored

• Otherwise, it is placed in its correct spot in the

array, bumping one element out of the array

as the answer

What's the book about?...

Considering large input values such as N = 1million

and k = 500,000 , both the algorithms do not

terminate in a reasonable amount of time ->

impractical

A better algorithm can solve this in a second!

1) Writing a working program is not good enough!

2) When a program is to be run on a large data set,

then the running time becomes an issue

What's the book about?...

We will learn

large inputs

How to compare the running times of two

programs without actually coding them

a program

Chapter 1: roadmap

1.1 What’s the book about?

1.2 Mathematics review

1.3 A Brief Introduction to Recursion

Mathematics review

To describe portions of an algorithm and to

analyse the performance characteristics of an

algorithm

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

Mathematics review…

Properties of logarithms

logC B

logAB = ; A,B,C > 0 , A 1

logC A

log(A/B) = log(A) - log(B)

log(AB) = B log(A)

log(X) < X for all X > 0

log(1)=0, log(2)=1, log(1,024)=10,

log(1,048,576)=20

Mathematics review…

Geometric Series

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

Mathematics review…

Modular Arithmetic

The number-theoretical concept of congruence

is

• A B (mod N)

• A is congruent to B modulo N , if N divides

(A-B)

either A or B are divided by N

• e.g. 81 61 1 (mod 10)

Similarly,

• A+C B+C (mod N) and AD BD (mod N)

Copyright © Kashif Javed Introduction 1-21

Mathematics review…

Proving the statements in data structure analysis

Proof By Induction

Given a theorem

Show the theorem is true for some small value(s)

Assume the theorem is true for all cases up to

some limit k

Using this assumption, prove that the theorem

holds for the next value (k+1)

Copyright © Kashif Javed Introduction 1-22

Mathematics review…

Proof By Induction – example

Fibonacci Series

F0 = 1, F1 = 1, Fi = Fi-1 + Fi-2 , for i > 1

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

Fk+1 = Fk + Fk-1

Fk+1 < (5/3) k + (5/3) k-1

< (3/5)(5/3) k+1 + (3/5)2(5/3) k+1

< (5/3) k+1 [ 3/5 + (3/5)2]

< (5/3) k+1 [24/25]

< (5/3) k+1

Mathematics review…

Proof by Contradiction

Assume a theorem is false

known property is false

“There is an infinite number of prime numbers”

Proof:

• Assume the theorem is false and there is

some largest prime Pk

Mathematics review…

Proof by Contradiction – example…

Let P1, P2, …,Pk be all the primes in the increasing

order

Consider N = P1P2P3…Pk + 1

Since N > Pk, so N is not a prime

However, none of P1, P2, …,Pk divides N exactly,

because there will always be a remainder of 1

This is a contradiction, because every number is

either a prime or a product of primes

Hence the original assumption is false the theorem

is true

Copyright © Kashif Javed Introduction 1-26

Chapter 1: roadmap

1.1 What’s the book about?

1.2 Mathematics review

1.3 A Brief Introduction to Recursion

A brief introduction to recursion

Recursive function

a function that is defined in terms of itself

6! = 6 * 5 * 4 * 3 * 2 * 1

could be written as:

6! = 6 * 5!

follows:

n! = n * (n-1)!

A brief introduction to recursion…

integers. So we should be a bit more precise:

n! = 1 (if n is equal to 1)

n! = n * (n-1)! (if n is larger than 1)

int fac(int numb){

if(numb <=1)

Base Case

return 1;

else Recursive Call

return numb * fac(numb-1);

}

Copyright © Kashif Javed Introduction 1-29

A brief introduction to recursion…

Lets find the factorial of 3, that is, numb=3

fac(3) :

3 <= 1 ? No

fac(3) = 3 * fac(2)

fac(2) :

2 <= 1 ? No

fac(2) = 2 * fac(1)

fac(1) :

1 <= 1 ? Yes

return 1

fac(2) = 2 * 1 = 2 int fac(int numb){

return fac(2) if(numb<=1)

return 1;

fac(3) = 3 * 2 = 6 else

return fac(3) return numb * fac(numb-1);

fac(3) has the value 6 }

Copyright © Kashif Javed Introduction 1-30

A brief introduction to recursion…

While using recursion, we must be careful not to

create an infinite chain of function calls:

int fac(int numb){

return numb * fac(numb-1); Oops!

} No termination

or condition

int fac(int numb){

if (numb<=1)

return 1;

else

return numb * fac(numb+1);

} Oops!

Copyright © Kashif Javed Introduction 1-31

A brief introduction to recursion…

Define a base case

• A base case can be solved without recursion

and it terminates recursion

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

Introduction: Summary

Covered the basics You now have:

What's the book about? Overview of this course

In the mathematical

review,

Logarithms

Arithmetic series

Geometric Series

Mathematical induction

to write correct recursive

programs

- Problem-Solving StrategiesUploaded byAbu Alzam
- QuantProblemSet IIIUploaded byapi-27239845
- TheZTutorial-2Uploaded bycnshariff@gmail.com
- springer-undergraduate-texts-in-mathematics-and-technology-david-r-finston-patrick-j-morandi-auth-abstract-algebra_-structure-and-application-2014-birkhc3a4user-basel.pdfUploaded byTinku Saha
- Limits at Infinity NotesUploaded byrjpatil19
- Discrete Mathematics-Mathematical InductionUploaded bymohitsingh316
- A Novel Parallel Algorithm for Enumerating CombinationsUploaded byshabunc
- Zi NotesUploaded byHoàng Nguyễn
- rurbric weeblyUploaded byapi-314753944
- Natural Deduction Manual JAPEUploaded byOtavio Camargo
- ch04Uploaded byAbuomer Mohamed
- 3112vlsics14Uploaded bysilpasivaram
- Class6.Discrete MathsUploaded byMohammad Gulam Ahamad
- sUploaded byEpic Win
- ValUploaded byDevid Bita
- SajidUploaded byaamir ali
- Testovi deljivostiUploaded byZlz Blz
- GödelUploaded byhtroll333
- Writing a Control PaperUploaded bySohibul Hajah
- ALP ProgramsUploaded byShrihari Vaidya
- Csharp_Arrays.pptxUploaded bytorab
- 17566512Uploaded byWesley Passos
- java Unit II, III & IV.docxUploaded byvinodkhar
- Swift Standard Library ReferenceUploaded byBill Velawras
- UNIT 3-Intermediate Code GenUploaded byNick Soni
- Discrete Mathematics-Lecture 1Uploaded byManjeet Singh
- 2007s.pdfUploaded byGanesh Kumar
- adt1Uploaded byArash Singh
- Ad 081Uploaded byAvijit Guha
- Test Prep SolutionsUploaded byEleazar Jedaías Neri

- EE-452 Power System Analysis Mannual 2013Uploaded byamarahhtahir786
- Domains of LearningUploaded byJunaid Alvi
- Sir Kashif Chapter 1Uploaded byJunaid Alvi
- Sir Kashif Chapter 7Uploaded byJunaid Alvi
- Earth Ground Resistance TestUploaded bykbgreat14471
- Lecture 11Uploaded byJunaid Alvi
- 12Uploaded byJunaid Alvi
- 2014_04_msw_a4_format.docUploaded bysunnyday32
- c Reaction Rates and Equilibrium Lect 2Uploaded byJunaid Alvi
- 480-al-ramadhan.pdfUploaded byJunaid Alvi
- Circuit AnalysisUploaded byJunaid Alvi
- Python FundamentalsUploaded bysanal_kumar_11
- Sir Kashif Chapter 2Uploaded byJunaid Alvi
- PolymerProperties From CESUploaded byJunaid Alvi
- PE4710 vs PE100Uploaded byphatmat
- Zhang 2015Uploaded byJunaid Alvi
- Chen 2016Uploaded byJunaid Alvi
- JIC07_A36Uploaded byJunaid Alvi
- HEC Recognized Engineering JournalsUploaded byJunaid Alvi
- 3Uploaded byJunaid Alvi
- Upsdown SurgingUploaded byJunaid Alvi
- 104612_Pulse Amplitude Modulation (Synchronisation,Intersymbol Interference,Eye Diagrams)Uploaded byBibi Mohanan
- FEAUploaded byJitender Singh Rawat
- v1109r2 Transformer Winding Hot SpotTemperature Determination (2)Uploaded byJunaid Alvi
- case5Uploaded byMahmoud Qotb
- LineToGroundVoltageMonitoring_08262005Uploaded byJunaid Alvi
- APE-LEC-7Uploaded byJunaid Alvi
- APE-LEC-8Uploaded byJunaid Alvi

- Rehabilitating_Water_and_Wastewater_Treatment_Plants.pdfUploaded byArchana Acchu
- Gestra Sandwich Check Valve RK76Uploaded bynrd9771
- 49858535 STAAD Technical Reference 2005Uploaded byJay Patel
- JOBO_CPP-3_Manual_GB_V1.1_26.03.13Uploaded byMarian Tudor
- RV Rental Connection is Changing the RV Rental MarketplaceUploaded byPR.com
- tgav kcrUploaded byapi-278632018
- Fast Dormancy and Enhanced Cell FACH V1 - OLNUploaded byMatthew Barnett
- how to throw a fiesta day 4Uploaded byapi-245081461
- Married Life-Clarinet, Violin, Cello, And PianoUploaded byOziel Jacobo
- Executive Security Handbook PDF for FreeUploaded byJennifer
- MFL-Sensor.pdfUploaded byShanmuga Navaneethan
- ATUploaded byGeorge Laffor
- Generator Room Ventilation 1Uploaded byPradeep Sukumaran
- China's Disruptors (Ed Tse) 10-18-2016Uploaded byvivek singh
- Project Guide M43C Propulsion_08.2012Uploaded byTime To Use Brain
- Research Paradigms.pptUploaded byRahmat Sayyid Zharfan
- sixth grade website evaluation unitUploaded byapi-199155734
- connection methodsUploaded byapi-349722336
- Unified Patents Inc. v. Uniloc USA, Inc., IPR2017-00184, Paper 1 (Nov. 10, 2016)Uploaded byShawn Ambwani
- 2_ Market Opportunities on Circular Economy_FinalUploaded byAna Reyna
- Stefan Joseph Hlouschko- The Effects of Porous Media on Explosion Development in Partially Filled EnclosuresUploaded byGhoree23456
- RTGEGSUploaded bySunitha Josephine
- 59 Python Glossary of Terms You Must Know - DataFlairUploaded byAyushGour
- A10-PPT-20 Dic.pptxUploaded byJaime Morales
- ECG & AMT-IIUploaded byRobby Sharma
- Hics 207-Hospital Incident Managment Team Himt ChartUploaded byslusaf
- bai 3-C1Uploaded byviettiennguyen
- 2011-08-11 minutesUploaded byRyuki
- SpecificationUploaded byMessala Yovera
- mql5Uploaded byromantiko123

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.