0% found this document useful (0 votes)
56 views29 pages

Fayyaz Awan: Algorithms and Data Structures

This document provides an introduction to algorithms and data structures. It discusses the need for data structures to organize data efficiently and enable more complex applications. Different types of data structures are described, including linear structures like arrays, lists, queues and stacks, as well as non-linear structures like trees and graphs. The document also outlines common data structure operations like traversing, searching, inserting and deleting. It emphasizes that the choice of data structure and algorithms can significantly impact a program's efficiency and performance.

Uploaded by

Noman Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views29 pages

Fayyaz Awan: Algorithms and Data Structures

This document provides an introduction to algorithms and data structures. It discusses the need for data structures to organize data efficiently and enable more complex applications. Different types of data structures are described, including linear structures like arrays, lists, queues and stacks, as well as non-linear structures like trees and graphs. The document also outlines common data structure operations like traversing, searching, inserting and deleting. It emphasizes that the choice of data structure and algorithms can significantly impact a program's efficiency and performance.

Uploaded by

Noman Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

CSC112

Algorithms and Data Structures

Lecture 01 By
Introduction Fayyaz Awan
Contact Information
Instructor:
Fayyaz Awan (Lecturer)
Department of Computer Sciences
Comsats Insititute of Information Technology, Wah Cantt

Office Hours:
Monday, 11:00 am 4:30 pm
Need for Data Structures
Data structures organize data more efficient programs.
More powerful computers more complex applications.
More complex applications demand more calculations.
Organizing Data
Any organization for a collection of records that can be
searched, processed in any order, or modified.
The choice of data structure and algorithm can make the
difference between a program running in a few seconds or
many days.
Efficiency
A solution is said to be efficient if it solves the problem within
its resource constraints.
Space
Time

The cost of a solution is the amount of resources that the


solution consumes.
Selecting a Data Structure
Select a data structure as follows:
1. Analyze the problem to determine the resource constraints a
solution must meet.
2. Determine the basic operations that must be supported.
Quantify the resource constraints for each operation.
3. Select the data structure that best meets these
requirements.
Some Questions to Ask
Are all data inserted into the data structure at the beginning,
or are insertions interspersed with other operations?
Can data be deleted?
Are all data processed in some well-defined order, or is
random access allowed?
Data Structure Philosophy
Each data structure has costs and benefits.
Rarely is one data structure better than another in all
situations.
A data structure requires:
space for each data item it stores,
time to perform each basic operation,
programming effort.
Algorithms
An algorithm is any well defined computational
procedure that takes some values or set of values
as input and produces some value or set of values
as output.
An algorithm is thus a sequence of computational
steps that transforms the input into output.
How do you learn algorithms to
cook?
To become good chef, you dont learn lots of
recipes by heart.
You study existing recipes.
You practice making them.
You experiment with your own variations.
Until you can invent your own recipes.
How do you learn about
algorithms?
A good computer scientist doesnt need to
memorize a big book of algorithms.
We will begin studying famous algorithms.
You can practice executing them by hand.
Once you recognize more general patterns, you
can experiment with your own variations.
At the end of the course, I expect you to invent
algorithms yourself.
Analysis of Algorithms
The theoretical study of computer-program
performance and resource usage. Whats more
important than performance?
modularity
correctness
maintainability
functionality
robustness (strengths)
user-friendliness
programmer time
simplicity
extensibility
reliability
Origin of word:
Algorithm
The word Algorithm comes from the name of the
muslim author Abu Jafar Mohammad ibn Musaal-
Khowarizmi. He was born in the eighth century at
Khwarizm (Kheva), a town south of river Oxus in
present Uzbekistan. Uzbekistan, a Muslim
country for over a thousand years, was taken
over by the Russians in 1873.

Much of al-Khwarizmis work was written in a


book titled al Kitab al-mukhatasar fi hisab al-
jabrwal-muqabalah (The Compendious Book on
Calculation by Completion and Balancing). It is
from the titles of these writings and his name
that the words algebra and algorithm are
derived. As a result of his work, al-Khwarizmi is
Algorithm: Informal
Definition

An algorithm is any well-defined


computational procedure that takes
some values, or set of values, as
input and produces some value, or
set of values, as output.
An algorithm is thus a sequence of
computational steps that transform
the input into output.
Algorithms,
Programming
A good understanding of algorithms is
essential for a good understanding of the
most basic element of computer science:
programming. Unlike a program, an
algorithm is a mathematical entity, which
is independent of a specific programming
language, machine, or compiler. Thus, in
some sense, algorithm design is all about
the mathematical theory behind the
design of good programs.
Why study algorithms and
performance?
Algorithms help us to understand
scalability.
Performance often draws the line
between what is feasible and what is
impossible.
Algorithmic mathematics provides a
language for talking about program
behavior.
Performance is the currency of
computing.
Why Study Algorithms?
Necessary in any computer programming problem
Improve algorithm efficiency: run faster, process more data, do
something that would otherwise be impossible
Solve problems of significantly large sizes
Compare algorithms
Algorithms as a field of study
Learn about a standard set of algorithms
New discoveries arise
Numerous application areas
Learn techniques of algorithm design and analysis
how does one coordinate the efforts of many programmers
working on a single piece of software
Applications
Multimedia
CD player, DVD, MP3, JPG, DivX
Internet
Packet routing, data retrieval (Google)
Communication
Cell-phones, e-commerce
Computers
Circuit layout, file systems
Science
Human genome (is the complete set of genetic
information for humans)
Transportation
Airline crew scheduling, UPS deliveries
Analyzing Algorithms
Predict the amount of resources required:
memory: how much space is needed?
computational time: how fast the algorithm runs?

FACT: running time grows with the size of the input


Input size (number of elements in the input)
Size of an array, polynomial degree, # of elements in a matrix,
# of bits in the binary representation of the input, vertices and
edges in a graph

Def: Running time = the number of primitive


operations (steps) executed before termination
Arithmetic operations (+, -, *), data movement, control, decision
making (if, while), comparison
Definition: Algorithm
A computer algorithm is a detailed step by step
method for solving the problem

An algorithm is a sequence of Clear-cut instructions


for solving the problem in a finite amount of time.

An algorithm is a set of well defined computational


procedure that takes some values, or set of values,
as input and produces some value or set of values as
output.

More Generally an algorithm is any well defined


computational procedure that takes collection of
elements as input and procedures collection of
elements as output.
Definition: Data Structures
A data structure is systematic way of organizing
and accessing data with a specific relationship
between the elements.

Why data structures?

Ultimate goal -- to write efficient programs. In order


to do that, one needs to organize the data in such a
way that it can be accessed and manipulated
efficiently.
Definition: Data Structures (Cont)

A data structure is a way of arranging data in a


computer's memory or other disk storage.

A data structure is a collection of data, organized so that


items can be stored and retrieved by some fixed
techniques.
Example: Suppose you are hired to create a database of
names with all company's management and employees.
Example: Data Structures
You can make a list. You can also make a tree.
Data Structures Types
There are several common data structures: arrays,
linked lists, queues, stacks, binary trees, hash
tables, etc.

These data structures can be classified as


either linear or nonlinear data structures, based on
how the data is conceptually organized or
aggregated.
Linear Vs Non-Linear Data Structures

Linear Structures Non-Linear Structures


The array, list, queue, and Trees and graphs are classical
stack belong to this category. non-linear structures.

Each of them is a collection Data entries are not arranged


that stores its entries in a in a sequence, but with
linear sequence, and in which different rules.
entries may be added or
removed at will.

They differ in the restrictions


they place on how these
entries may be added,
removed, or accessed. The
common restrictions include
FIFO and LIFO.
Algorithms and Data
Structures
Data Structure Operations
The data appearing in our data structures are processed
by means of certain operations. The following four
operations play a major role :

1. Traversing: Accessing each record exactly once so that certain


items in the record may be processed.
2. Searching: Finding the location of the record with a given key
value, or finding the locations of all records which satisfy one or
more conditions.
3. Inserting: Adding a new record to the structure.
4. Deleting : Removing a record from the structure.
Data Structure Operations (Cont)

Sometimes two or more of the operations may be


used in given situations; e.g. we may want to delete
the record with a given key, which may mean we
first need to search for the location of the record.

The following two operations , which are used in


special situations, will be considered:
1. Sorting: Arranging record in some logical order
(ascending/ descending)
2. Merging: Combining the records in two different
sorted files into a single sorted file.
For any query Feel Free to
ask

You might also like