O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Intro to Data Structure & Algorithms

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Carregando em…3
×

Confira estes a seguir

1 de 37 Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a Intro to Data Structure & Algorithms (20)

Anúncio

Mais de Akhil Kaushik (18)

Mais recentes (20)

Anúncio

Intro to Data Structure & Algorithms

  1. 1. Introduction to Data Structure & Algorithms Akhil Kaushik Asstt. Prof., CE Deptt., TIT Bhiwani
  2. 2. Good Computer Program • A computer program is a series of instructions to carry out a particular task written in a language that a computer can understand. • There are a number of features for a good program:- – Run efficiently and correctly – Have a user friendly interface – Be easy to read and understand – Be easy to debug – Be easy to modify – Be easy to maintain
  3. 3. Good Computer Program • Programs consists of two things: Algorithms and data structures. • A good program is a combination of both algorithm and a data structure. • An algorithm is a step by step recipe for solving an instance of a problem.
  4. 4. What are Data Structures? • Data structures defines a way of organizing all data items that consider not only the elements stored but also stores the relationship between the elements. • A data structure represents the logical relationship that exists between individual elements of data to carry out certain tasks.
  5. 5. What are Data Structures? • In simple language, Data Structures are structures programmed to store ordered data, so that various operations can be performed on it easily. • Ex: Store runs according to a Batsman’s name.
  6. 6. Why study Data Structures? • To identify and develop useful mathematical entities and operations and to determine what class of problem can be solved by them. • To determine representation of abstract entities and to implement the abstract operations on these representations
  7. 7. Data Type vs Data Structure • Data type: data type a set of values that variable may assume. Int, float, char, double, Boolean. • Data Structure: extension of data type i.e. the implementation of organized data and operations allowed on data type.
  8. 8. Why study Data Structures? • DS are used in almost every program or software. • DS study is mandatory to develop better algorithm. • DS allow management of large database and internet indexing services.
  9. 9. Why study Data Structures? Study of DS includes:- • Logical description of DS • Implementation of DS • Quantitative analysis of DS
  10. 10. Why study Data Structures? Applications of DS are in every are including:- • DBMS • SIMULATION • GRAPHICS • NETWORK ANALYSIS • NUMERICAL ANALYSIS • COMPILER DESIGN • OPERATING SYSTEM • ARTIFICAL INTELLIGENCE
  11. 11. Data Structure Classification Classification can be done on the basis of :- 1. According to nature of size 2. According to its occurrence 3. Primitive and non-primitive
  12. 12. Data Structure Classification
  13. 13. STATIC AND DYNAMIC 1. Static: Here we can store data up to a fixed no. only. Ex: array. 2. Dynamic: It allows programmer to change its size during program execution to add or delete data. Ex: linked list, tree, etc.
  14. 14. LINEAR AND NON-LINEAR 1. Linear: Here data is stored in consecutive memory allocation i.e. - sequentially. Ex: array, linked list, queue, etc. 2. Non-linear: Here data is in no sequential form and usually used to identify hierarchical relationship. Ex: Trees
  15. 15. PRIMITIVE AND NON-PRIMITIVE PRIMITIVE DATATYPE: These data types are used to represent single values. • Integer: This is used to represent a number without decimal point. Ex: 12, 90 • Float and Double: This is used to represent a number with decimal point. Ex: 45.1, 67.3 • Character : This is used to represent single character Ex: ‘C’, ‘a’ • String: This is used to represent group of characters. Ex: “Stephen College" NON-PRIMITIVE DATATYPES: The data types that are derived from primary data types are known as non-Primitive data types. • These data types are used to store group of values. • The non-primitive data types are – Arrays – Structure – Union – linked list – Stacks
  16. 16. Homogenous vs Hetrogenous • Homogenous: DS refer to the data structure which store same type of elements. Ex: arrays • Non-homogenous: DS refer to the data structure which store data of different type of elements. Ex: structure.
  17. 17. Operations on Data Structure 1. Traversing: Accessing each records exactly once so that certain items in the record may be processed. 2. Searching: Finding the location of a particular record with a given key value, or finding the location of all records which satisfy one or more conditions. 3. Inserting: Adding a new record to the structure. 4. Deleting: Removing the record from the structure. 5. Sorting: Managing the data or record in some logical order(Ascending or descending order). 6. Merging: Combining the record in two different sorted files into a single sorted file. 7. Create, delete, update, etc.
  18. 18. Algorithms • An algorithm is a step by step recipe for solving an instance of a problem. • An algorithm is a precise procedure for solving a problem in finite number of steps. • An algorithm states the actions to be executed and the order in which these actions are to be executed.
  19. 19. Algorithms • An algorithm possesses the following properties:- – It must be correct. – It must be composed of a finite number of steps. – There can be no ambiguity as to which step will be done next. – It must terminate. – It takes zero or more inputs – It should be efficient and flexible – It should use less memory space as much as possible – It results in one or more outputs
  20. 20. Various steps in developing Algorithms • Devising the Algorithm:- Each step of an algorithm must be precisely defined and no vague statements should be used. – Pseudo code is used to describe the algorithm, in less formal language than a Programming language
  21. 21. Various steps in developing Algorithms • Validating the Algorithm: The proof of correctness of the algorithm. – A human must be able to perform each step by giving the required input, use the algorithm and get the required output in a finite amount of time. • Expressing the algorithm: To implement the algorithm in a programming language. – The algorithm used should terminate after a finite number of steps.
  22. 22. Efficiency of an Algorithm An algorithm should meet three things:- • It should be independent of the programming language in which the idea is realized • Every programmer having enough knowledge and experience should understand it • It should be applicable to inputs of all sizes
  23. 23. Efficiency of an Algorithm • Efficiency of an algorithm denotes the rate at which an algorithm solves a problem of size ‘n’. • It is measured by the amount of resources it uses, the time and the space. • An algorithm’s complexity is measured by calculating the time taken and space required for performing the algorithm.
  24. 24. Space Complexity of an Algorithm • It is the way in which the amount of storage space required by an algorithm varies with the size of the problem to be solved. • The space occupied by the program is generally by the following:- – A fixed amount of memory for the program code. – A variable amount of memory for variable. This space increases or decreases depending upon whether the program uses iterative or recursive procedures.
  25. 25. Space Complexity of an Algorithm • Instruction Space is the space occupied by the compiled version of the program. • Data Space is the space used to hold the variables , data structures, allocated memory and other data elements. • Environment Space is the space used on the run time stack for each function call.
  26. 26. Time Complexity of an Algorithm • The way in which the number of steps required by an algo varies with the size of the problem it is solving.
  27. 27. Time Complexity of an Algorithm • It is the amount of time needed by a program to complete its task. • The time taken for an algorithm is comprised of two times:- – Compilation Time – Run Time
  28. 28. Time Complexity of an Algorithm • Compilation time is the time taken to compile an algorithm. • While compiling it checks for the syntax and semantic errors in the program and links it with the standard libraries, your program has asked to. • It comes under the domain of computer science (software dependent).
  29. 29. Time Complexity of an Algorithm • Runtime is the time to execute the compiled program. • Note that run time is calculated only for executable statements and not for declaration statements. • It comes under the domain of electronics (depends on hardware).
  30. 30. Time Complexity of an Algorithm • It can be defined for computation of function f() as a total number of statements that are executed for computing the value of f(n). • Time complexity of an algorithm is generally classified as three types:- (i) Worst case (ii) Average Case (iii) Best Case
  31. 31. Time Complexity of an Algorithm • Worst Case: It is the longest time that an algorithm will use over all instances of size ‘n’ for a given problem to produce a desired result. – Denoted by Big-Oh (O) • Average Case: It is the average time(or average space). – Denoted by theta (Θ). • Best Case: It is the shortest time (or least space). – Denoted by Omega(Ω).
  32. 32. Time Complexity of an Algorithm
  33. 33. Time Complexity of an Algorithm fact ( long n) { for (i=1; i<=n; i++) x=i*x; return x; } • Data Space: i, n and x • Environment Space: Almost nothing because the function is called only once. • The algorithm has a complexity of O(1) because it does not depend on n. • No matter how big the problem becomes, the space complexity remains the same since the same variables are used, and the function is called only once.
  34. 34. Time Complexity of an Algorithm long fact (long x) { if (x<=1) return(1); else return (x * fact(x-1)); } • Data space : x • Environment Space: fact() is called recursively , and so the amount of space this program used is based on the size of the problem.
  35. 35. Measure Algorithms’ Performance • It needs programs to create ,append, update the database, print data, permit online enquiry and so on. • A Programmer should identify all requirements to solve the problem like:- – Type of Programming language – Narration of the program describing the tasks to be performed – Frequency of Processing (hourly, daily, weekly etc) – Input and output of the program – Limitations and restrictions for the program
  36. 36. Measure Algorithms’ Performance • What metric should be used to judge algorithms? – Length of the program (lines of code) – Ease of programming (bugs, maintenance) – Memory required – Running time *Running time is the dominant standard. – Quantifiable and easy to compare – Often the critical bottleneck
  37. 37. CONTACT ME AT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 CONTACT ME AT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 Thank You !!!

×