CSC2102 Data Structures and Algorithm Program BSSE-3 Sec. A Week 1
CSC2102 Data Structures and Algorithm Program BSSE-3 Sec. A Week 1
Week 1
Introduction Needs & Advantages Data Types Operations Algrothithms
Outline
1 Introduction
3 Data Types
4 Operations
5 Algrothithms
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 2 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Introduction
• Data Structure can be defined as the group of data elements which provides an
efficient way of storing and organizing data in the computer so that it can be used
efficiently.
• Some examples of Data Structures are arrays, Linked List, Stack, Queue, etc.
• Data Structures are the main part of many computer science algorithms as they
enable the programmers to handle the data in an efficient way.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 3 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Introduction - Contd
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 4 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Basic Terminology
Data
• Data can be defined as an elementary value or the collection of values, for example,
student’s name and its id are the data about the student.
Group Item
• Data items which have subordinate data items are called Group item, for example,
name of a student can have first name and the last name.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 5 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Record
• Record can be defined as the collection of various data items, for example, if we talk
about the student entity, then its name, address, course and marks can be grouped
together to form the record for the student.
File
• A File is a collection of various records of one type of entity, for example, if there are
60 employees in the class, then there will be 20 records in the related file where each
record contains the data about each employee.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 6 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Field
• Field is a single elementary unit of information representing the attribute of an entity.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 7 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 8 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 9 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Efficiency
• Efficiency of a program depends upon the choice of data structures. For example:
suppose, we have some data and we need to perform the search for a perticular
record. In that case, if we organize our data in an array, we will have to search
sequentially element by element. hence, using array may not be very efficient here.
There are better data structures which can make the search process efficient like
ordered array, binary search tree or hash tables.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 10 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Reusability
• Data structures are reusable, i.e. once we have implemented a particular data
structure, we can use it at any other place. Implementation of data structures can be
compiled into libraries which can be used by different clients. tables.
Abstraction
• Data structure is specified by the ADT which provides a level of abstraction. The
client program uses the data structure through interface only, without getting into
the implementation details.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 11 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Data types
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 12 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Those data types for which a language has built-in support are known as Built-in
Data types. For example, most of the languages provide the following built-in
data types.
Example
• Integers
• Boolean (true, false)
• Floating (Decimal numbers)
• Character and Strings.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 13 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Example
• List
• Array
• Stack
• Queue
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 14 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
1) Traversing:
Every data structure contains the set of data elements. Traversing the data structure
means visiting each element of the data structure in order to perform some specific
operation like searching or sorting
Example
If we need to calculate the average of the marks obtained by a student in 6 different
subject, we need to traverse the complete array of marks and calculate the total sum,
then we will devide that sum by the number of subjects i.e. 6, in order to find the average
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 15 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
2) Insertion:
Insertion can be defined as the process of adding the elements to the data structure at
any location.
Example
If the size of data structure is n then we can only insert n-1 data elements into it.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 16 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
3) Deletion:
The process of removing an element from the data structure is called Deletion. We can delete an
element from the data structure at any random location.
Example
If we try to delete an element from an empty data structure then underflow occurs.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 17 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
4) Searching:
The process of finding the location of an element within the data structure is called
Searching. There are two algorithms to perform searching, Linear Search and Binary
Search. We will discuss each one of them later in this tutorial.
5) Sorting:
The process of arranging the data structure in a specific order is known as Sorting. There
are many algorithms that can be used to perform sorting, for example, insertion sort,
selection sort, bubble sort, etc.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 18 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
6) Merging:
When two lists List A and List B of size M and N respectively, of similar type of elements,
clubbed or joined to produce the third list, List C of size (M+N), then this process is
called merging
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 19 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Algorithm
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 20 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 21 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 22 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Algorithm Characteristics
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 23 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Example
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 24 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Example
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 25 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Task
Problem:
Design an algorithm to add two numbers and display the result.
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 26 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 27 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Characteristics of an Algorithm
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 28 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Resources
From the Referred Book
Book
Seymour Lipschutz, Data Structures, Revised Edition, Schaum’s outline series,
Publisher McGraw Hill Education Private Limited, 2014
ISBN: 1259029964, 9781259029967
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 29 / 30
Introduction Needs & Advantages Data Types Operations Algrothithms
Dr. Mahmoud Aljawarneh (CS Department) Course: CSC2102 Data Structures and Algorithm Week 1 30 / 30