Data Structure and Algorithms

Slides:



Advertisements
Similar presentations
Chapter 1: INTRODUCTION TO DATA STRUCTURE
Advertisements

Data Structures.
Lecture - 1 on Data Structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Data Type and Data Structure Data type Set of possible values for variables.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Data Structures Lecture-1:Introduction
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
Computer Science Department Data Structures and Algorithms Lecture 1.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
Data Structure Introduction.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Topic 2 Collections. 2-2 Objectives Define the concepts and terminology related to collections Discuss the abstract design of collections.
REEM ALMOTIRI Information Technology Department Majmaah University.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Data Structure and Algorithms
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
CPS120: Introduction to Computer Science Sorting.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Mohammed I DAABO COURSE CODE: CSC 355 COURSE TITLE: Data Structures.
Advanced Data Structures Lecture 1
Introduction toData structures and Algorithms
Introduction to Data Structures
Queues.
Data Structure By Amee Trivedi.
12 Collections Software Solutions Lewis & Loftus java 5TH EDITION
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Chapter 12 – Data Structures
Course Developer/Writer: A. J. Ikuomola
CHP - 9 File Structures.
Top 50 Data Structures Interview Questions
Data Structures & File Processing
Data Structure Interview Question and Answers
Hashing, Hash Function, Collision & Deletion
© The McGraw-Hill Companies, All Rights Reserved APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
Data Structure and Algorithms
Chapter 15 Lists Objectives
Lecture – 2 on Data structures
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Data Structures Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective.
Stacks and Queues.
Data Structures Interview / VIVA Questions and Answers
Review Graph Directed Graph Undirected Graph Sub-Graph
Program based on pointers in C.
Introduction to Data Structure
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
structures and their relationships." - Linus Torvalds
Disk Storage, Basic File Structures, and Hashing
Graphs Chapter 11 Objectives Upon completion you will be able to:
Ch. 8 Priority Queues And Heaps
Introduction to Data Structures
Week # 1: Overview & Review
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Introduction to Data Structures
Introduction to Data Structure
Data Structures & Algorithms
Important Problem Types and Fundamental Data Structures
structures and their relationships." - Linus Torvalds
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
Data Structures and Algorithms Lecture-1: Introduction
Presentation transcript:

Data Structure and Algorithms Topic 1 Introduction and Overview

Basic Terminology; Elementary Data Organization Data – values/set of values. Data item – single unit of values. Group items – divided into subitems. Elementary items – not divided. E.g., employee name may be divided into three subitems – first name, middle initial and last name – social security number – single item.

Basic Terminology; Elementary Data Organization Entity – something that has attributes/properties which may be assigned values. Values may be numeric/nonnumeric. Entities with similar attributes (e.g., all employees in organization) form entity set. Attributes: Name Age Sex Social Security Number Values: Rumaisya, Saifi 34 F 134-24-5533

Basic Terminology; Elementary Data Organization Each attribute of entity set has range of values – set of all possible values that could be assigned to the particular attribute. Term “information” sometimes used for data with given attributes, or, in other words, meaningful or processed data.

Basic Terminology; Elementary Data Organization Field – single elementary unit of information representing entity attribute. Record – collection of field values of an entity. File – collection of entities records in an entity set.

Basic Terminology; Elementary Data Organization Each record in file may contain many field items, but the value in a certain field may uniquely determine the record in the file. Such a field K is called a primary key, and values k1, k2, … in such a field are called keys or key values.

Basic Terminology; Elementary Data Organization Example: Automobile dealership inventory file, each record contains: Serial Number, Type, Year, Price, Accessories Primary key? Since each automobile has unique serial number

Basic Terminology; Elementary Data Organization Example: Organization membership file, each record contains: Name, Address, Telephone Number, Dues Owed Group items – Name, Address Primary key – Name Address and Telephone Number may not serve as primary key

Basic Terminology; Elementary Data Organization Records may also be classified according to length. File can have: Fixed-length records – all records contain same data items with same amount of space Variable-length records – different lengths of records. E.g., student records since different students take different number of courses. Usually have minimum and maximum length.

Data Structures Data structure – logical or mathematical model of a particular organization of data. Choice of data model depends on: Richness in structure to mirror actual relationships of data in real world Simplicity, one can effectively process data when necessary

Classification of Data Structures

Arrays Linear (or dimensional) array List of finite number n of similar data elements referenced by a set of n consecutive numbers, usually 1, 2, 3, …, n. Array name A, elements of A denoted by subscript a1, a2, a3, …, an A(1), A(2), A(3), …, A(N) A[1], A[2], A[3], …, A[N]

Arrays Number K in A[K] is called subscript A[K] is called subscripted variable Linear arrays are called one-dimensional arrays because each element in array is referenced by one subscript.

Arrays List weekly sales can be stored in two-dimensional array, first subscript denotes store and second subscript the department. SALES is the name given to the array

Linked List Brokerage firm

Linked List Integer used as a pointer requires less space than a name

Linked List Suppose the firm wants the list of customers for a given salesperson Using Fig. 1.5, the firm would have to search through the entire customer file

Linked List Disadvantage: each salesperson have many pointers and the set of pointers change as customers are added and deleted.

Linked List

Trees Rooted tree graph/tree – data contain hierarchical relationship between elements

Trees Example Record Structure: Employee personnel record contain data items: Social Security Number, Name, Address, Age, Salary, Dependents Group item Subitem Name Last, First, MI (middle initial) Address Street, Area Area City, State, ZIP code number

Trees Example Algebraic Expression: (2x + y)(a – 7b)3 Exponentiation – vertical arrow (↑) Multiplication – asterisk (*)

Trees Exponentiation take place after subtraction, multiplication at top of tree executed last.

Stack Also called last-in first-out (LIFO) system – linear list which insertions and deletions take place only at one end, called top New dishes inserted at top of stack and deleted only from top of stack

Queue Also called first-in first out (FIFO) system – linear list which deletions take place only at one end of list, “front” of list, and insertions take place only at other end of list, “rear” Line of people waiting at bus stop

Queue First person in line – first person to board the bus Automobiles waiting to pass through an intersection – first car in line – first car through

Graph Data contain relationship between pairs of elements which is not hierarchical E.g., airline flies only between cities connected by lines

Data Structure “record” – files “node” – linked list, trees and graphs

Data Structure Operations Data structure that one chooses depends on frequency with which specific operations are performed

Data Structure Operations Four operations: Traversing: Accessing each record exactly once so that items in record may be processed (sometimes called “visiting”) Searching: Finding location of record with given key value/finding locations of all records which satisfy one/more conditions Inserting: adding new record Deleting: removing a record

Data Structure Operations Two/more operations used; e.g., delete record with given key value, mean first need to search for location of record

Data Structure Operations Two operations: Sorting: arranging records in logical order (e.g., alphabetically according to NAME key/numerical order according to NUMBER key, such as social security/account number) Merging: combining records in two different sorted files into single

Abstract Data Types A set of data values and associated operations that are specified accurately, independent of any particular implementation. Know what a specific data type can do, but how it actually does it is hidden. Consists of a set of definitions that allow us to use the functions while hiding the implementation.

Abstract Data Types List L consisting of data items – 1, 2, 3, 4, 5, 6, 7, 8, 9 as shown in (a). Can use any of four data structures to support L – a linear list, a matrix, a tree, or a graph, as given in (b), (c) and (d) respectively.

Abstract Data Types

Abstract Data Types The users should not be aware of the structure that we use, i.e., whether it is a tree, or graph or something else. As long as they are able to insert and retrieve data, it does not make a difference as to how we store the data.

Abstract Data Types A shop maintains the list of customers, sales assistants and the average transactions on a day as given in Fig 1.12. Need to write a program, which will determine the number of sales assistants required to serve customers efficiently. Need to simulate the waiting line in the shop.

Abstract Data Types This analysis will require the simulation of a queue. Need some basic queue operations such as enqueuing and dequeuing (insertion and deletion).

Abstract Data Types A data declaration packaged together with the operations that are meaningful for the data type. Encapsulate the data and the operations on the data, and then hide from the user. The user need not know the data structure to use the ADT.

Abstract Data Type Model

Abstract Data Type Model Two different parts of ADT model – functions (public and private) and data structures. Do not come within scope of application program. Data structures are available to all ADTs functions, and function may call on any other function to accomplish its task.

Abstract Data Type Model Data structures and functions are within scope of each other. Data are entered, accessed, modified and deleted through the external application programming interface. Can only access the public functions.

Abstract Data Type Model For each ADT operation, there is an algorithm that performs its specific task. The operation name and parameters (the only interface) are available to the application. Two basic structures, namely array and linked list, can be used to implement an ADT list.

Algorithms: Complexity, Time-Space Tradeoff Well-defined list of steps for solving a particular problem. One major purpose is to develop efficient algorithms for processing data. Two major measures are time and space.

Algorithms: Complexity, Time-Space Tradeoff Complexity of an algorithm is the function which gives the running time and/or space in terms of input size. Increasing the amount of space for storing data, may be able to reduce the time needed for processing the data, or vice versa.

Searching Algorithms Consider a membership file, each record contains, among other data, the name and telephone number. Given the name of a member and want to find his or her telephone number.

Linear Search Search each record of file, one at a time, until finding the given Name and the corresponding telephone number. The time required to execute the algorithm is proportional to the number of comparisons.

Linear Search The average number of comparisons for a file with n records is equal to n/2; that is, the complexity of the linear search algorithm is given by C(n) = n/2. Impossible in practice if searching through a list consisting of thousands of names, as in a telephone book.

Binary Search Compare the given Name with the name in the middle of the list; this tells which half of the list contains Name. Then compare Name with the name in the middle of the correct half to determine which quarter of the list contains Name. Continue the process until finding Name in the list.

Binary Search Complexity of the binary search algorithm is given by C(n) = log2 n Will not require more than 15 comparisons to find a given Name in a list containing 25 000 names. Binary search algorithm has some drawbacks. The list must be stored in some type of array.

Binary Search Inserting an element in an array requires elements to be moved down the list, and deleting an element from an array requires element to be moved up the list. Telephone company printing a new directory (updates) every year while keeping a separate temporary file for new telephone customers.

Binary Search A bank may want to insert a new customer in its file almost instantaneously. A linearly sorted list may not be the best data structure for a bank.

Time-Space Tradeoff Given only the social security number of the person. Do a linear search for the record, which is extremely time-consuming for a very large number of records. How can we solve such a problem? One way is to have another file which is sorted numerically according to social security number.

Time-Space Tradeoff Would double the space required for storing data. Another way, the main file sorted numerically by social security number and to have an auxiliary array with only two columns containing: Alphabetized list of the names Pointers which give the locations of the corresponding records in the main file.

Time-Space Tradeoff Since the additional space, containing only two columns, is minimal for the amount of extra information it provides.

Time-Space Tradeoff To minimize the movement of data is to have the social security number serve as the address of each record. No movement of data when records are inserted, instant access to any record. This method of storing data require one billion (109) memory locations for only hundreds or thousands of records.

Time-Space Tradeoff This tradeoff of space for time is not worth the expense. An alternative method is to define a function H from the set K of key values – social security numbers – into the set L of addresses of memory cells. Such a function H is called a hashing function.