CS-211 Data Structure & Algorithms - Lecture1
CS-211 Data Structure & Algorithms - Lecture1
1
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Introduction
• Data Structure
• A data structure is a specialized format for organizing, processing, retrieving and
storing data.
• There are several basic and advanced types of data structures, all designed to
arrange data to suit a specific purpose.
• Linked List
• Queues
• Hash Tables
• Trees
• Data structures make it easy for users to access and work with the data they need in
appropriate ways.
• Most importantly, data structures frame the organization of information so that
machines and humans can better understand it.
2
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Introduction
• Algorithms
• An algorithm is a sequence of unambiguous instructions for solving a problem, i.e.,
for obtaining a required output for any legitimate input in a finite amount of time.
3
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Introduction
• Primitive Data Types - Programming languages commonly provide data types as part
of the language itself. These data types, known as primitives.
• The simple data types consist of values that are in the most basic form and cannot be
decomposed into smaller parts. Integer and real types, for example, consist of single numeric
values.
• The complex data types, on the other hand, are constructed of multiple components
consisting of simple types or other complex types. In Python, objects, strings, lists, and
dictionaries, which can contain multiple values, are all examples of complex types.
• The primitive types provided by a language may not be sufficient for solving large
complex problems.
• Thus, most languages allow for the construction of additional data types, known as
user-defined types since they are defined by the programmer and not the language.
Some of these data types can themselves be very complex.
4
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Abstraction
• An abstraction is a mechanism for separating the properties of an
object and restricting the focus to those relevant in the current
context.
• The user of the abstraction does not have to understand all of the
details in order to utilize the object, but only those relevant to the
current task or problem.
• Procedural abstraction is the use of a function or method knowing
what it does but ignoring how it’s accomplished.
• Data abstraction is the separation of the properties of a data type (its
values and operations) from the implementation of that data type.
5
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
6
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
7
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
General Definitions
• A collection is a group of values with no implied organization or
relationship between the individual values.
• A container is any data structure or abstract data type that stores and
organizes a collection.
• A sequence is a container in which the elements are arranged in linear
order from front to back, with each element accessible by position.
• A sorted sequence is one in which the position of the elements is
based on a prescribed relationship between each element and its
successor.
8
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
10
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Implementing ADT
11
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Implementing ADT
12
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Implementing ADT
13
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Complex ADT
• Bags
• A bag is a simple container like a shopping bag that can be used to store a
collection of items.
• The bag container restricts access to the individual items by only defining
operations for adding and removing individual items, for determining if an
item is in the bag, and for traversing over the collection of items.
14
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Bags
15
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
16
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
18
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Iterators
• An iterator is an object that provides a mechanism for performing
generic traversals through a container without having to expose the
underlying implementation.
• To use Python's traversal mechanism with our own abstract data
types, we must define an iterator class, which is a class in Python
containing two special methods, __iter__ and __next__ . Iterator
classes are commonly defined in the same module as the
corresponding container class.
19
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Iterators
20
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
21
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Application:
Student File Reader
ADT
22
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
23
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
24
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
25
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
26
Dr. Sharaf Hussain