/
INTRODUCTION DATA STRUCTURES AND ALGORITHMS INTRODUCTION DATA STRUCTURES AND ALGORITHMS

INTRODUCTION DATA STRUCTURES AND ALGORITHMS - PowerPoint Presentation

garboardcola
garboardcola . @garboardcola
Follow
348 views
Uploaded On 2020-10-01

INTRODUCTION DATA STRUCTURES AND ALGORITHMS - PPT Presentation

wwwasyranicom data Please forget that you get lowhigh marks for C Programming class 1 2 3 Set up in your mind right now this subject is the most interesting Things you must have Visual C 2010 Edition ID: 812994

structures data int algorithm data structures algorithm int thissum comparable search amp maxsum adt structure big array loop type

Share:

Link:

Embed:

Download Presentation from below link

Download The PPT/PDF document "INTRODUCTION DATA STRUCTURES AND ALGORIT..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

INTRODUCTIONDATA STRUCTURES AND ALGORITHMS

www.asyrani.com

/data

Slide2

Please forget that you get low/highmarks for C Programming class1

2

3

Set up in your mind right now, this subject is the most interesting!!!

Things you must have:

Visual C++ 2010 Edition

Internet Access!!! (Most important one)

Slide3

Programming is not hard as you think!!!

Slide4

Don’t remember the theory but remember how it works

Slide5

Phone number0137771180asyrani@utem.edu.my

Slide6

Things you need to doFirst go to www.asyrani.com/teaching

Slide7

Laman Struktur DataLink http://asyrani.com/data

Slide8

OverVIEWFIRST GLANCE

Slide9

Over the view …OverviewHow to create Windows 8 anyone?

Slide10

I know!!!!!!We need manpower!!!=

Computer engineers

“I will make sure that the software can

be integrated with the specific hardware”

Programmers

“I’m the one that do the programming

stuff”Designers“I design the interface and give the Windows 8 nice looks”

Slide11

Data Structures & AlgorithmsIt is part of Application Development Phase in Software Engineering

Slide12

Data Structures & AlgorithmsWhy it is important?

Slide13

Why it is so importantComputer UtilizationConsumers: control washing machine, oven, cars.Engineers & scientist: design, model, simulate.

Commerce: financial transaction, communications.

Modern Computers

Store, analyze, search, transfer and update huge collections of complex data.

Slide14

Why it is so important (2)Increase efficiency of the simulation

Organize

and access

data quickly

and smoothly

Slide15

WHY WE NEED TO STUDY ‘EM?GOOD QUESTION

Slide16

WHY I NEED TO STUDY THIS?BECAUSE ONE OF YOUR SUBJECTAND YOU ARE BORN TO BE LEARNED THIS SUBJECT!!!

Slide17

WHY I NEED TO STUDY THIS?WITHOUT Data Structures and AlgorithmsWITH Data Structures and Algorithms

Slide18

OR TO PUT IT INTO WORDSWITHOUT Data Structures and AlgorithmsWITH Data Structures and Algorithms

Slow

Too much codes

Messy code

No one can understand your code

Not efficient although it can be running correctlyEat up your computer memory too much

FastSimple and short codesClean codeMost will understand your codeEfficient and can be running smoothly Memory efficientEliminate unnecessary loops and operations.

Slide19

DATA STRUCTURES AND ALGORITHM DEFINITIONNow for serious learning avtivity

Slide20

Programming is easy as eating a pancakeDo you know how to eat?

Don’t cha??

Slide21

DIFFERENCES BETWEEN C++ AND C

Slide22

Slide23

Slide24

DEFINITION : ALGORITHMSWHO IS HERE KNOW HOW TO COOK A NASI GORENG??

TEST

NOT READY

READY

Slide25

SO WHAT IS ALGORITHM IN WORDS?STEPS OF SOLVING PROBLEMS IN SPESIFIC TIME FRAMEALSO KNOWN AS “FINITE STEP BY STEP PROBLEM SOLVING TECHNIQUE”

Slide26

GOOD ALGORITHMSSimple, clear, concise and readable.Solvable, terminates after a finite number of instructions.Correct, efficient and robust.

Accomplish at least one task or produce at least one output.

Slide27

DEFINITION : DATA STRUCTURES

Slide28

DATA STRUCTURESA data structure groups the data.Structure means a set of rules that hold the data together.

Slide29

ALGORITHM ANALYSIS

Slide30

Why Algorithm analysisGenerally, we use a computer because we need to process a large amount of data. When we run a program on large amounts of input, besides to make sure the program is correct, we must be certain that the program terminates within a reasonable amount of time.

Slide31

What is Algorithm Analysis?

Slide32

BIG O NOTATION

Slide33

Big Oh NotationBig Oh notation is used to capture the most dominant term in a function, and to represent the growth rate.Also called asymptotic upper bound. Ex: 100n3 + 30000n =>O(n3

)

100n

3

+ 2n

5+ 30000n =>O(n5)

Slide34

Upper and lower bounds of a function

Slide35

Functions in order of increasing growth rate

Function

Name

C

Constant

LogN

Logarithmic

Log

2

N

Log-squared

N

Linear

NlogN

NlogN

N

2

Quaratic

N

3

Cubic

2

n

Exponential

Slide36

Functions in order of increasing growth rate

Slide37

Examples of Algorithm Running TimesMin element in an array :O(n)Closest points in the plane, ie. Smallest distance pairs: n(n-1)/2 => O(n2)Colinear points in the plane, ie. 3 points on a straight line: n(n-1)(n-2)/6 => O(n3)

Slide38

The Max. Contiguous SubsequenceIn computer science, the maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers (containing at least one positive number) which has the largest sum.

For

example, for the sequence of values −2, 1, −3, 4, −1, 2, 1, −5, 4; the contiguous

subarray

with the largest sum is 4, −1, 2, 1, with sum 6.

Slide39

The Max. Contiguous SubsequenceEXAMPLE{-2, 11, -4, 13, -5, 2} =>20{1, -3, 4, -2, -1, 6} => 7

Slide40

Brute Force Algorithm O(n2)template <class Comparable>Comparable maxSubSum(const vector<Comparable> a,

int

&

seqStart

, int & seqEnd

){ int n = a.size(); Comparable maxSum = 0; for(int i = 0; i < n; i++){ // for each possible start point for(int j = i; j < n; j++){ // for each possible end point Comparable thisSum = 0; for(int k = i; k <= j; k++) thisSum += a[k];//dominant term if( thisSum > maxSum){ maxSum = thisSum; seqStart = i;

seqEnd

= j;

}

}

}

return

maxSum

;

} //A cubic maximum contiguous subsequence sum algorithm

Slide41

O(n3) Algorithm AnalysisWe do not need precise calculations for a Big-Oh estimate. In many cases, we can use the simple rule of multiplying the size of all the nested loops

Slide42

O(n2) algorithmAn improved algorithm makes use of the fact that If we have already calculated the sum for the subsequence i, …, j-1. Then we need only one more addition to get the sum for the subsequence i, …, j. However, the cubic algorithm throws away this information.

If we use this observation, we obtain an improved algorithm with the running time O(N

2

).

Slide43

O(N2) Algorithm cont.template <class Comparable>Comparable maxSubsequenceSum(const vector<Comparable>& a,

int

&

seqStart

, int &seqEnd){

int n = a.size(); Comparable maxSum = 0; for( int i = 0; i < n; i++){ Comparable thisSum = 0; for( int j = i; j < n; j++){ thisSum += a[j]; if( thisSum > maxSum){ maxSum = thisSum; seqStart = i; seqEnd = j; } }

}

return

maxSum

;

}

Slide44

O(N) Algorithmtemplate <class Comparable>Comparable maxSubsequenceSum(const vector<Comparable>& a, int

&

seqStart

,

int

&seqEnd){

int n = a.size(); Comparable thisSum = 0, maxSum = 0; int i=0; for( int j = 0; j < n; j++){ thisSum += a[j]; if( thisSum > maxSum){ maxSum = thisSum; seqStart = i; seqEnd = j; }else if( thisSum < 0) { i = j + 1; thisSum = 0; } }

return

maxSum

;

}

Slide45

Sequential SearchA sequential search steps through the data sequentially until an match is found.A sequential search is useful when the array is not sorted.A sequential search is linear O(n) (i.e. proportional to the size of input)Unsuccessful search --- n timesSuccessful search (worst) --- n times

Successful search (average) --- n/2 times

Slide46

Binary SearchIf the array has been sorted, we can use binary search, which is performed from the middle of the array rather than the end.We keep track of low_end and high_end, which delimit the portion of the array in which an item, if present, must reside.If low_end is larger than high_end, we know the item is not present.

Slide47

6.8 Limitations of Big-Oh AnalysisBig-Oh is an estimate tool for algorithm analysis. It ignores the costs of memory access, data movements, memory allocation, etc. => hard to have a precise analysis.Ex: 2nlogn vs. 1000n. Which is faster? => it depends on n

Slide48

EASY WAY TO CALCULATE BIG O

Slide49

LET’S RIDEHere we iterate 'n' times. Since nothing else is going on inside the loop (other then constant time printing), this algorithm is said to be O(n).

Slide50

LET’S RIDEEach loop is 'n'. Since the inner loop is nested, it is n*n, thus it is O(n^2). Hardly efficient. We can make it a bit better by doing the following:

Slide51

LET’S RIDEOuter loop is still 'n'. The inner loop now executes 'i' times, the end being (n-1). We now have (n(n-1)). This is still in the bound of O(n^2), but only in the worst case.

Slide52

LET’S RIDEAt first you might say that the upper bound is O(2n); however, we drop constants so it becomes O(n). Mathematically, they are the same since (either way) it will require 'n' elements iterated (even though we'd iterate 2n times).

Slide53

LET’S RIDEYou wouldn't do this exact example in implementation, but doing something similar certainly is in the realm of possibilities. In this case we add each loop's Big O, in this case n+n^2. O(n^2+n) is not an acceptable answer since we must drop the lowest term. The upper bound is O(n^2). Why? Because it has the largest growth rate (upper bound or limit for the Calculus inclined).

Slide54

LET’S RIDEOuter loop is 'n', inner loop is 2, this we have 2n, dropped constant gives up O(n).

Slide55

LET’S RIDEThere are n iterations, however, instead of simply incrementing, 'i' is increased by 2*itself each run. Thus the loop is log(n).

Slide56

LET’S RIDEThis example is n*log(n). (Remember that nested loops multiply their Big O's.)

Slide57

CONCLUSION OF BIG OIn short Big O is simply a way to measure the efficiency of an algorithm. The goal is constant or linear time, thus the various data structures and their implementations. Keep in mind that a "faster" structure or algorithm is not necessary better. For example, see the classic hash table versus binary tree debate. While not 100% factual, it often said that a a hash-table is O(1) and is therefore better then a tree.

REFERENCE:

http

://www.dreamincode.net/forums/topic/125427-determining-big-o-notation/

Slide58

Types of data structuresWhat we will learn???

Slide59

Linear Data Structures

Because we arrange it linearly

Slide60

Non-Linear Data Structures

The data is not necessarily need to arrange in order

Slide61

Operation of Data Structures

Slide62

Characteristic of Data StructuresDATA STRUCTURE

ADVANTAGES

DISADVANTAGES

Array

Quick inserts

Fast access if index known

Slow searchSlow deletesFixed sizeOrdered ArrayFaster search than unsorted arraySlow insertsSlow deletesFixed sizeStackLast-in, first-out accessSlow access to other itemsQueueFirst-in, first-out accessSlow access to other items

Linked-list

Quick inserts

Quick deletes

Slow search

Binary Tree

Quick search

Quick inserts

Quick deletes

(If the tree remains balanced)

Deletion algorithm is complex

Slide63

Characteristic of Data Structures

DATA STRUCTURE

ADVANTAGES

DISADVANTAGES

2-3-4 Tree

Quick search

Quick insertsQuick deletes(Tree always remains balanced)(Similar trees good for disk storage)Complex to implementHash TableVery fast access if key is knownQuick insertsSlow deletesAccess slow if key is not knownInefficient memory usageHeapQuick insertsQuick deletesAccess to largest itemSlow access to other items

Graph

Best models real-world situations

Some algorithms are slow and very complex

Slide64

DATA TYPEMove into the next one

Slide65

DATA TYPEThe basic stuff. What do you need to have before cooking nasi goreng?Nasi putihPerencah

Adabi

Ikan

bilis

But how much?Nasi

putih around 600 gramPerencah Adabi around 30.5 gram30 – 40 ikan bilis

Slide66

DATA TYPEThe basic stuff. What do you need to have before cooking nasi goreng?Nasi putih

Perencah

Adabi

Ikan

bilisBut how much?

Nasi putih around 600 gramPerencah Adabi around 30.5 gram30 – 40 ikan bilisThis is what we’ve called Data Type Data type of a variable is the set of values that the variable may assume.Basic Data Types in C++ :int , char , double, String, Boolean, etc.

Slide67

Abstract data type (adt)Now let us look deeper

Slide68

Before we proceedI know you guys want to know whether you guys need to memorize all this stuff or notTo be honest. I’ve never memorize all things that I do not use. Even terms etcBut because YOU ARE STUDENT, you guys still need to memorize some facts because you have quizzes, test(s) and final exam to consider.

Slide69

ADT

Slide70

ADT(2)

Slide71

Example

Slide72

ADT and Data Structures?A Data Structure is an implementation of an ADT. That is it is a translation of ADT into statements of a programming language. It consists of:The declarations that define a variable to be of that ADT type.

The operations defined on the ADT(using procedures of the programming language).

An ADT implementation chooses a data structure to represent the ADT

Each data structure is built up from the basic data types of the underlying programming language using the available data structuring facilities , such as arrays, pointers , files , sets, etc.

Slide73

Example:A ” Queue ”

is an abstract data type which can be defined as a sequence of elements with operations such as

Enqueue(x,q)

,

Dequeue(q)

.

This can be implemented using data structures such as:ArraySingly linked listDoubly linked listCircular array

Slide74

Key words:Data Structures & Algorithms – Definition A

data structure

is an arrangement of data in a computer's memory or even disk storage. An example of several common data structures are arrays, linked lists, queues, stacks, binary trees, and hash tables.

Algorithms

, on the other hand, are used to manipulate the data contained in these data structures as in searching and sorting. Many algorithms apply directly to a specific data structures. When working with certain data structures you need to know how to insert new data, search for a specified item, and deleting a specific item.

Slide75

Key words:Data types

When we consider a primitive type we are actually referring to two things:

a data item

with certain characteristics and the

permissible operations on that data

The data type's permissible operations are an inseparable part of its identity; understanding the type means understanding what operations can be performed on it

Example:An int in Java or C++, for example, can contain any whole-number value from -2,147,483,648 to +2,147,483,647. It can also be used with the operators +, -, *, and /

Slide76

Key words:Abstract Data Type (ADT)

Is a class considered

without regard to its implementation

.

It can be thought of as a "

description

" of the data in the class and a list of operations that can be carried out on that data and instructions on how to use these operations. An end user (or class user), you should be told what methods to call, how to call them, and the results that should be expected, but not HOW they work. Consider for example the stack class. The end user knows that push() and pop() exist and how they work. The user doesn't

and

shouldn't

have to

know how

push() and pop()

work

, or whether data is stored in an array, a linked list, or some other data structure like a tree.

Slide77

Next Class:Chapter 2 (part 1) Introduction to C++Programming fundamentals

Slide78

NoteAlways browse to www.asyrani.com

/data

Wait for further updated information in my website

You are encouraged to collaborate in study groups.

But you cannot directly copy or slightly change

other students

solutions or code