Download presentation

Presentation is loading. Please wait.

Published byEliezer Wooton Modified over 2 years ago

1
Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Email : eaymanelshenawy@yahoo.comeaymanelshenawy@yaho Lectures on Data Structure

2
Students using this book should have knowledge of either an object-oriented or procedural programming language. Knowledge of basic features, including primitive data types. Operators. control structures. functions (methods). input and output is assumed. Pre-requisites

3
Lecture 1 Algorithms and Data Structures

4
Algorithms and Data Structure a data structure is a systematic way of organizing and accessing data. design of "good" data structures and algorithms. Algorithm is a step-by -step procedure for performing some task in a finite amount of time. We must analyze data structures and algorithms in order to classify them as “good”.

5
Algorithmic Performance There are two aspects of algorithmic performance : Time Instructions take time. How fast does the algorithm perform? What affects its runtime? Space Data structures take space What kind of data structures can be used? How does choice of data structure affect the runtime? We will focus on time: – How to estimate the time required for an algorithm – How to reduce the time required 5

6
Relative costs of algorithms and DS Performing Analysis of the algorithm when the input sets are very large (asymptotic analysis). 1, 10, 100, 1000, 1 million of items. If an algorithm take 5 secs to perform 1000 items, what time it will be talk if the number of items are 1,000,000? 5 secs or 5 years. You must know before your customer knows.

7
Rate of Growth how an algorithm’s complexity changes as the input size grows? Big-O notation uses a capital O (“order”) and a formula that expresses the complexity of the algorithm. The formula may have a variable, n, which represents the size of the input.

8
Common order functions Constant O(1) whose complexity is constant regardless of how large the input size is. The 1 does not mean that there is only one operation or that the operation takes a small amount of time. It might take 1 microsecond or it might take 1 hour. The point is that the size of the input does not influence the time the operation takes.

9
Common order functions Linear O(n) whose complexity grows linearly with the size of the input. If an input size of 1 takes 5 ms, an input with one thousand items will take 5 sec. Ex. a looping mechanism that accesses each member.

10
Common order functions Logarithmic O(log n) whose complexity is logarithmic to its size. Many Divide and Conquer algorithms. The binary search tree Contains method implements an O(log n) algorithm.

11
Algorithms and Data Structure Common order functions Linearithmic O(n log n) A linearithmic algorithm, or log linear, is an algorithm that has a complexity of O(n log n). Some divide and conquer algorithms fall into this bucket. merge sort and quick sort.

12
Algorithms and Data Structure Common order functions Quadratic O(n 2 ) Whose complexity is quadratic to its size Do not scale well as the input size grows. Ex. an array with 1000 integers 1,000,000 operations to complete. An input with 1,000,000 items would take one trillion (1,000,000,000,000) operations. If each operation takes 1 ms to complete, an O(n 2 ), an input of 1,000,000 items will take nearly 32 years to complete. Making that algorithm 100 times faster would still take 84 days. ( Bubble sort is an example)

13
Common order functions Quadratic O(n 2 ) ( Bubble sort is an example) – Nested Loops

14
What we are measuring The amount of time the operation takes to complete (operational complexity, Time). The amount of resources (memory) an algorithm uses (resource complexity, Space). An algorithm that runs ten times faster but uses ten times as much memory might be perfectly acceptable in a server environment with vast amounts of available memory, but may not be appropriate in an embedded environment where available memory is severely limited.

15
Common operations Comparison operations (greater than, less than, equal to). Assignments and data swapping. Memory allocations. Searching Comparison (Read only operation) no assignment is done. Sorting comparison, assignments, allocations. What we are measuring

16
Algorithms and Data Structure Comparing Growth Rates

17
Tools of measuring Experimental Studies Executing it on various test inputs and recording the actual time spent in each execution. System.currentTimeMillis() Perform several experiments on many different test inputs of various sizes. Plotting the performance of each run, input size, n, versus the running time, t. Statistical analysis that seeks to fit the best function of the input size to the experimental data.

18
Tools of measuring Experimental Studies

19
Tools of measuring Experimental Studies Limitations Experiments can be done only on a limited set of test inputs; Difficult to comparing two algorithms on tow different environments. We have to fully implement and execute an algorithm in order to study its running time experimentally.

20
Tools of measuring develop a general way of analyzing the running times of algorithms. Takes into account all possible inputs Evaluate the relative efficiency of any two algorithms on different environments. Can be performed by studying a high-level description of the algorithm without actually implementing it or running experiments on it.

21
Counting Primitive operations Primitive operation is a low-level instruction with constant time. Counting the primitive can be used as measure for algorithm performance.

22
Counting Primitive operations we can perform an analysis directly on the high- level pseudo-code instead. We define a set of primitive operations such as the following: Assigning a value to a variable. Calling a method. Performing an arithmetic operation (for example, adding two numbers) Comparing two numbers Indexing into an array Following an object reference Returning from a method.

23
Pseudo code

Similar presentations

OK

Chapter 10 Algorithm Analysis. Introduction Generalizing Running Time Doing a Timing Analysis Big-Oh Notation Analyzing Some Simple Programs.

Chapter 10 Algorithm Analysis. Introduction Generalizing Running Time Doing a Timing Analysis Big-Oh Notation Analyzing Some Simple Programs.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on aquatic animals Free ppt on planets in the solar system Ppt on scout and guide Ppt on project management training Ppt on blood stain pattern analysis terminology Can keynote read ppt on iphone Ppt on how open source softwares are better than branded softwares Ppt on exploring fibonacci numbers Ppt on body mass index Ppt on kinetic theory of matter/gas laws