1 / 33

Algorithm and Data Structure EKT 334 Lec . 1 Mohamed Elshaikh

Algorithm and Data Structure EKT 334 Lec . 1 Mohamed Elshaikh. Instruction…. 4 units course Lectures 60% Lab 20% Tutorials 20% Evaluation Course work 30% Assignments, and quizzes Tests 70% Test 1&2 20% Final exam 50%. Instructions…. What EKT334 to: (Course outcomes)

dorcas
Download Presentation

Algorithm and Data Structure EKT 334 Lec . 1 Mohamed Elshaikh

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithm and Data StructureEKT 334Lec. 1Mohamed Elshaikh

  2. Instruction… • 4 units course • Lectures 60% • Lab 20% • Tutorials 20% • Evaluation • Course work 30% • Assignments, and quizzes • Tests 70% • Test 1&2 20% • Final exam 50%

  3. Instructions… • What EKT334 to: (Course outcomes) • Ability to design algorithm for problem solving • Ability to write C code in data structures and analyze the efficiency of their implementations • Ability to implement and evaluate the sorting and searching techniques • Ability to implement and evaluate Tree and Graph

  4. What EKT334 about…. • Contents : • Algorithms • Arrays and pointers • Structure and union • Linear data structure • Sorting techniques • Searching techniques • Trees • Graphs

  5. Instructions: • What would be in the labs: • Arrays and pointers • Structure, union, and stack • Queue, and linked lists • Sorting • Searching • Tree • Graph

  6. Instructions… • How to study: • Lecture notes • Lab modules • Handouts, and extra materials • And of course a text book: • Data structures and algorithms, concepts, techniques, and applications’ by G. A. V. Paihttp://www.mhhe.com/pai/dsa. • Please do early reading, and solve all assignments, tutorials, and quizzs

  7. Instructions… • How to catch up with me: • Ph: 0175171894 • Email: elshaikh@unimap.edu.my • Office: KKF8A (bp5)

  8. Q and A

  9. Week 1: outlines… • Introduction • Algorithms : Definition, structure and • properties • Development of an algorithm • Data structures and algorithms • Data structures : Abstract Data Type

  10. Introduction • Computer science and other discipline • Most technologies engaged to computer science • Solving problems • Analyzing problems • Storing and retrieving data • Computerization • Automation • Others..

  11. Omnipresence of computers Computer Industry Transportation Space Technology Weather Science

  12. Discipline of Computer science from the view point of problem solving • Computer discipline • Machines • What are the appropriate machine • Language • How to chose the proper language • Language limitations and the solution requirements • Foundation • Problem definition • Solution modeling • Technology • Web base solution • Mobile application • Machine coding • High or low end peripheral device

  13. Discipline of Computer science from the view point of problem solving Technologies Foundations Machines Languages

  14. Algorithms • Definition An algorithm may be defined as a finite sequence of instructions each of which has a clear meaning and can be performed with a finite amount of effort in a finite length of time • The first algorithm was designed by (Abu Jafar Mohammed Ibn Musa Al Khwarizmi, Al Khwarizmi) • The solution to any computing problem involves executing series of actions in a specific order • Algorithms are represented in: • Pseudo code : artificial and informal language that helps programmers develop algorithms • Flow charts

  15. Al Khwarizmi’s Example • Example • To find the addition of two numbers, calls for summing up the digits occurring at specific positions and previous carry digit, representatively moving from the least significant digit to the most significant digits have been exhausted. • 9 8 7+ • 6 7 • (carry 1) 3 • 9 8 7+ • 6 7 • (carry 1) 6 3 • 9 8 7+ • 6 7 • 1 0 6 3

  16. Structure of algorithm • An algorithm has the following structure: • input step • assignment step • decision step • repetitive step • output step • Example consider the demonstration of Al Khwarizmi’s algorithm for the addition of two numbers, what are: Input , assignment, decision, repetitive, and output steps?

  17. Properties of algorithm • An algorithm is endowed with the following properties: • Finiteness • Algorithm must terminates after a finite number of steps • Definiteness • Precisely defined or unambiguously specified • Generality • Solving all problems of a particular class • Effectiveness • Not too complex to warrant another algorithm • Input-Output

  18. Development of an algorithm • The steps involved in the development of an algorithm are as follows: (i) problem statement (ii) model formulation (iii) algorithm design (iv) algorithm correctness (v) implementation (vi) algorithm analysis (vii) program testing (viii) documentation

  19. Data Structures And Algorithms • design of an efficient algorithm for the solution of the problem calls for the inclusion of appropriate data structures • The proper structure of data contributes to the efficiency of the solution • Consider the problem of searching for a telephone number in the telephone directory • It is easy since the numbers are sorted in an alphabetical oreder • What if, the phone number are sorted according to the phone numbers • Or, according to the subscription of the telephone • The subject of data structures is intrinsically connected with the design and implementation of efficient algorithms. Data structures deals with the study of methods, techniques and tools to organize or structure data.

  20. Data Structures - Definition • A data type refers to the type of values that variables in a programming language hold. Thus the data types of integer, real, character, Boolean which are inherently provided in programming languages are referred to as primitive data types. • A list of elements is called as a data object. For example, we could have a list of integers or list of alphabetical strings as data objects. • The data objects which comprise the data structure, and their fundamental operations are known as Abstract Data Type (ADT). • In other words, an ADT is defined as a set of data objects D defined over a domain L and supporting a list of operations O.

  21. ADT – an illustration • Data objects: • Set of all positive integers D • Operations: • Addition of positive integers INT1 and INT2 into RESULT • ADD ( INT1, INT2, RESULT) • Subtraction of positive integers INT1 and INT2 into RESULT • SUBTRACT ( INT1, INT2, RESULT) • Check if a number INT1 is a positive integer • CHECK_POSITIVE( INT1) (Boolean function)

  22. Efficiency of algorithms • The performance of algorithms can be measured on the scales of time and space • The time complexity of an algorithm or a program is a function of the running time of the algorithm or program • The space complexity of an algorithm or a program is a function of the space needed by the algorithm or program to run to completion • The empirical orposterioritesting approach calls for implementing the complete algorithms and executing them on a computer for various instances of the problem • The theoretical or aprioriapproach calls for mathematically determining the resources such as time and space needed by the algorithm, as a function of a parameter related to the instances of the problem considered.

  23. Apriori Analysis • Apriori estimation is interested in the following for the computation of efficiency: (i) the number of times the statement is executed in the program, known as the frequency count of the statement, and (ii) the time taken for a single execution of the statement Program segment A … x = x + 2; …

  24. Program segment B … for k = 1 to n do x = x + 2; end … Program segment C … for j = 1 to n do for k = 1 to n do x = x + 2; end end …

  25. Asymptotic Notations

  26. Time Complexity Of An Algorithm Using O Notation • Algorithms reporting O(1) time complexity indicate constant running time • The time complexities of O(n), O(n2) and O(n3) are called linear, quadratic and cubic time complexities respectively. O(logn) time complexity is referred to as logarithmic • In general, time complexities of the type O(nk) are called polynomial time complexities. • Time complexities such as O(2n), O(3n), in general O(kn) are called as exponential time complexities. • Some of the commonly occurring time complexities in their ascending orders of magnitude are listed below: O(1)≤ O(log n) ≤ O(n) ≤ O(n.log n) ≤ O(n2) ≤ O(n3) ≤ O(2n)

  27. Polynomial Vs Exponential Algorithms 1 : n2 2: 2n 3: n.log2n 4: log2n Growth rate of some computing time functions

  28. Comparison of polynomial and exponential algorithms

  29. Average, Best And Worst Case Complexities • That input instance (or instances) for which the algorithm takes the maximum possible time is called the worst case and the time complexity in such a case is referred to as worst case time complexity • That input instance for which the algorithm takes the minimum possible time is called the best case and the time complexity in such a case is referred to as best case time complexity. • All other input instances which are neither of the two are categorized as average cases and the time complexity of the algorithm in such cases is referred to as average case complexity.

  30. Let T(n) be the running time of the recursive function FACTORIAL(n). The running times of lines 1 and 2 is O(1). The running time for line 3 is given by O(1) + T(n-1). Here T(n-1) is the time complexity of the call to the recursive function FACTORIAL(n-1). Thus for some constants c, d, T(n) = c + T(n-1), if n > 1 = d, if n ≤ 1 The recursive terms in the recurrence relation are replaced so as to move the relation closer to the base criterion viz., T(n) = 1, n≤ 1. The approximation of the closed form solution obtained viz., T(n) = (n-1)c +d yields O(n).

  31. The Tower of Hanoi puzzle Peg S Peg I Peg D Tower of Hanoi puzzle ( initial configuration)

  32. function TRANSFER(N, S, I, D) /* N disks are to be transferred from peg S to peg D with peg I as the intermediate peg*/ ifN is 0 thenexit(); else { TRANSFER(N-1, S, D, I); /* transfer N-1 disks from peg S to peg I with peg D as the intermediate peg*/ Transfer disk from S to D; /* move the disk which is the last and the largest disk, from peg S to peg D*/ TRANSFER(N-1, I, S, D); /* transfer N-1 disks from peg I to peg D with peg S as the intermediate peg*/ } end TRANSFER.

  33. The recurrence relation is given by, T(N) = 0, if N =0 = 2. T(N-1) + 1, if N > 0 Solution of the recurrence relation for the Tower of Hanoi puzzle,

More Related