1 Introduction

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Data Structure and Algorithm

COC2060
- Nadeem Akhtar
Course Objective

 To introduce the concept of data structures including arrays, linked lists, stacks, queues,
binary trees, heaps, binary search trees, and graphs etc., and apply these data structures in
problem solving.
 To introduce applications of various data structures and its use in a manner that adds to the
efficiency of an algorithm in writing effective programs.
Course Outcome

 After completion of this course, you will be able to


1. Learn how the choice of data structures and algorithm design methods impact the
performance of programs.
2. Analyze the importance and use of Abstract Data Types (ADTs)
3. Design and implement elementary Data Structures such as arrays, trees, Stacks, Queues, and
Hash Tables.
4. Identify algorithms as a pseudo-code to solve some common problems.
5. Explain best, average, and worst-cases of an algorithm using Big-O notation.
Recommended Books

 Seymour Lipschutz, Data Structures, TMH


 Aaron M. Tenenbaum, Langsam, Data structures using C, Pearson, 2008
5 What is a Computer Program?

 To exactly know, what is data structure? We must know:


 What is a computer program?

processing
Input Output
Datastructures and Algorithms 10/11/2022
Data

 Data is plural of datum- a piece of information


 Data are values or a set of values
 Data item refers to single unit of values
 Data item
 Group item :
 Data item that can be subdivided into sub item.
 Ex Name : First Name, Middle initial and Last Name

 Elementary item:
 Data item that can not be sub divided into sub item

 Ex : PAN card number / Bank Pass Book Number is treated as single item
Elementary Data Organization

 Collection of data are frequently organized into a hierarchy of fields, records and files
 Entity :
 Something that has certain attributes or properties which may be assigned values
 Values may be numeric or non-numeric
 Ex: The employee of an organization
Attributes Name Age Sex Employee Code
Values John 33 M 13472
Elementary Data Organization

 Entity with similar attributes ( e.g all employees of an organization) form an entity set
 Each attribute of an entity set has a range of values [ the set of possible values that could be
assigned to the particular attribute]
 Information: Data with given attribute or processed data

 Field is a single elementary unit of information representing an attribute of an entity


 Record is the collection of field values of a given entity
 Fixed Length
 Variable Length
 File is the collection of records of the entities in a given entity set
Example
Issues in Data Structures

 Study of Data Structure includes the following three steps


 Logical or Mathematical description of the structure of data
 Implementation of the structure on a computer
 Quantitative analysis of the structure, which includes determining the amount of memory needed
to store the structure and the time required to process the structure
 Second and third step depends on whether data is stored in main memory or secondary
storage
 In this course, we are concerned only with data stored in main memory
Data Structure

 Data Structure
 The logical or mathematical model of a particular organization of data
 Choice of a model depends on two factor
 It must be rich enough in structure to mirror the actual relationships of the data in the real world
 The structure should be simple enough that one can effectively process the data when necessary
 A data structure is a way to logically organize data that specifies:
 A set of data elements i.e., a data object and
 A set of operations which may legally be applied to elements of this data object.
Operations

 Operations:
 Data appearing in DS are processed by means of certain operation
 A particular DS, one chooses for a given situation depends largely on the frequency with which specific
operations are performed
 Main operations
 Traversal
 Search
 Insertion
 Deletion
 Sort

 Issues
 Space needed
 Operations efficiency (Time required to complete operations)
Categorization
14 Pictorial Representation

array

Linked list

queue
tree stack
Datastructures and Algorithms 10/11/2022
Algorithms

 A list of well defined instructions for solving a particular problem


 High level and language independent instructions
 Each instruction must be clear
 Finite number of instructions
 There may be many algorithms for solving a problem
 Good Algorithm: Efficient Algorithm
 Time
 Space
Time-space trade-off

 Each algorithm involve a particular data structure


 Choice of data structure effect the efficiency of algorithm
 Time-space trade-off
 Increasing the amount of space may reduce time need and vice
versa
Example: Search Algorithms

 Suppose we have a file containing information about employees


 Name, Age, Sex, Telephone Number, Address
 We are given name of an employee and want to search for his/her
Telephone number
 Linear Search
 Traverse the file linearly starting from the first record
 Number of comparisons is equal to (n+1)/2
 What if file is very large
Binary Search
 Binary search can be used if names are sorted alphabetically
 General Idea of binary search
 Compare given name with the name in the middle of list
 Tells which half of the list contains given name
 Repeat this process until given name is found
 Number of comparisons is log2n
Number of comparisons in Binary Search
Number of comparisons in Binary Search

log 𝑁
𝑁
¿ ∑ (𝑖 ∗
2 ( 𝑙𝑜𝑔𝑁 − 𝑖+1 )
)/ 𝑁
𝑖=1

For array of 15 elements, Number of comparisons is


Binary Search

 Very efficient than linear search


 Drawbacks
 Sorted list
 Direct access to middle element
 insertion and deletion in sorted array is difficult
Example 1: time space trade-off
Example 1: time space trade-off
Example 1: time space trade-off
Example 2: time space trade-off
Roll No Name
55 Clark
712 Hill
3 Drew
124 White
943 Brown
345 Adams
231 Bill

 Roll No can be used as address


 No movement od data in insertion and deletion
 Instant access to any record
 Mostly empty locations- memory is allocated for non-existing records
 Efficient Method: Hashing
 A hash function H transform a key value K into address L

You might also like