Chapter One Introduction To Data Structures And Algorithms PDF

Summary

This document introduces fundamental concepts of data structures and algorithms. It explains how data is organized in computer memory and how algorithms define steps to solve problems. The document emphasizes the importance of abstraction in problem-solving, and the function and definition of abstract data types.

Full Transcript

Chapter One Introduction to Data Structures and Algorithms 1 Introduction A program A set of instruction which is written in to solve a problem. A solution to a problem actually consists of two things:  A way to organi...

Chapter One Introduction to Data Structures and Algorithms 1 Introduction A program A set of instruction which is written in to solve a problem. A solution to a problem actually consists of two things:  A way to organize the data  Sequence of steps to solve the problem The way data are organized in a computers memory is said to be Data Structure. The sequence of computational steps to solve a problem is said to be an Algorithm. Therefore, a program is Data structures plus Algorithm. 2 Introduction… Data structures are used to model the world or part of the world. How? 1. The value held by a data structure represents some specific characteristic of the world. 2. The characteristic being modeled restricts the possible values held by a data structure and the operations to be performed on the data structure. The first step to solve the problem is obtaining ones own abstract view, or model, of the problem. This process of modeling is called abstraction. 3 Introduction… The model defines an abstract view to the problem. The model should only focus on problem related stuff 4 Abstraction Is a process of classifying characteristics as relevant and irrelevant for the particular purpose at hand and ignoring the irrelevant ones. Example: model students of A University. Relevant: Char Name; Char ID; Char Dept; int Age, year; Non relevant float hieght, weight; 5 Abstraction… Using the model, a programmer tries to define the properties of the problem. These properties include  The data which are affected and  The operations that are involved in the problem An entity with the properties just described is called an abstract data type (ADT). 6 Abstract Data Types Consists of data to be stored and operations supported on them. Is a specification that describes a data set and the operation on that data. The ADT specifies:  What data is stored.  What operations can be done on the data. Does not specify how to store or how to implement the operation. Is independent of any programming language 7 Abstract Data Types… Example: ADT employees of an organization:  This ADT stores employees with their relevant attributes and discarding irrelevant attributes. Relevant:- Name, ID, Sex, Age, Salary, Dept, Address Non Relevant :- weight, color, height  This ADT supports hiring, firing, retiring, … operations. 8 Data Structure In Contrast a data structure is a language construct that the programmer has defined in order to implement an abstract data type. What is the purpose of data structures in programs? – Data structures are used to model a problem. Example: struct Student_Record { char name; char ID_NO; char Department; int age; }; 9 Data Structure… Attributes of each variable: – Name: Textual label. – Address: Location in memory. – Scope: Visibility in statements of a program. – Type: Set of values that can be stored + set of operations that can be performed. – Size: The amount of storage required to represent the variable. – Life time: The time interval during execution of a program while the variable exists. 10 Algorithm Is a concise specification of an operation for solving a problem. Is a well-defined computational procedure that takes some value or a set of values as input and produces some value or a set of values as output. Inputs Algorithm Outputs An algorithm is a specification of a behavioral process. It consists of a finite set of instructions that govern behavior step-by-step. Is part of what constitutes a data structure 11 Algorithm… Data structures model the static part of the world. They are unchanging while the world is changing. In order to model the dynamic part of the world we need to work with algorithms. Algorithms are the dynamic part of a program’s world model. An algorithm transforms data structures from one state to another state. 12 Algorithm… What is the purpose of algorithms in programs? – Take values as input. Example: cin>>age; – Change the values held by data structures. Example: age=age+1; – Change the organization of the data structure: Example: Sort students by name – Produce outputs: Example: Display student’s information 13 Algorithm… The quality of a data structure is related to its ability to successfully model the characteristics of the world (problem). Similarly, the quality of an algorithm is related to its ability to successfully simulate the changes in the world. However, the quality of data structure and algorithms is determined by their ability to work together well. Generally speaking, correct data structures lead to simple and efficient algorithms and correct algorithms lead to accurate and efficient data structures. 14 Properties of Algorithms 1. Finiteness: Algorithm must complete after a finite number of steps. Algorithm should have a finite number of steps. Example of Finite Steps Example of Infinite Steps int i=0; while(true) while(i>b; cin>>a; sum= a+b; a= a+b; cin>>b; cout

Use Quizgecko on...
Browser
Browser