0% found this document useful (0 votes)
40 views19 pages

Data Structures and Algorithms: Aamir Zia

This lecture introduces the course on data structures and algorithms. It covers the course outline, contents, and good programming practices. The course will cover fundamental data structures like arrays, stacks, queues, lists, trees, graphs, and searching/sorting algorithms. It emphasizes selecting the appropriate data structure based on the problem requirements and operations needed. Abstract data types are introduced as a way to define the essential characteristics of a data structure separately from its implementation.

Uploaded by

M Naveed Shakir
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)
40 views19 pages

Data Structures and Algorithms: Aamir Zia

This lecture introduces the course on data structures and algorithms. It covers the course outline, contents, and good programming practices. The course will cover fundamental data structures like arrays, stacks, queues, lists, trees, graphs, and searching/sorting algorithms. It emphasizes selecting the appropriate data structure based on the problem requirements and operations needed. Abstract data types are introduced as a way to define the essential characteristics of a data structure separately from its implementation.

Uploaded by

M Naveed Shakir
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/ 19

Lecture 1

Data Structures and Algorithms


Aamir Zia
Introduction
• Course outline
• Rules and regulations
• Course contents
• Good Programming Practices
• Data Types and Data Structures
• ADT
Course Description
• Title: Data Structures and Algorithms
• Code: CMP-210
• Credit Hours: 04
• Prerequisite: OOP
• Follow Up: Design and Analysis of Algorithms
Contents
• Introduction to Algorithms
• Arrays
• Stacks
• Recursion
• Queues
• Lists and its variations
• Trees
• Hashing
• Searching and sorting Techniques
• Graphs
Good Programming Practices
• Programs and subprograms should be well structured.
 Use a modular approach for a complex problem.
 Use the basic control structures when developing each code
segment.
 Sequence, selection, repetition
 Use local variables within subprograms.
 Use parameters to pass information to and from subprograms.
 Avoid global Variables.
• All source code should be documented.
 Each program should include opening documentation.
  Each subprogram should be documented in a manner similar to
programs.
  Comments should be used to explain key code segments and / or
segments whose purpose or design is not obvious.
  Use meaningful identifiers.
Good Programming Practices
• Source code should be aesthetic; it should be formatted in a
style that enhances its readability.
 Put each statement of the program on a separate line.
 Use uppercase and lowercase letters in a way that contributes to
program readability.
 Put each {and} on separate lines.
 Align each {and corresponding}.
 When a statement is continued from one line to another, indent the
continued line(s).
 Align the identifiers in each constant and variable declaration,
placing each on a separate line.
 Insert blank lines between declarations and statements and between
blocks of statements to make clear the structure of the program.
Data Types
In computer programming, a data type is a classification identifying
one of various types of data, such as floating-point,..
• Simple (basic)
– (char, int, float, double), in c++,
– (char, int, float, Double, Boolean, short, long, short in, string)
• Modifiers
– signed, unsigned
• Qualifiers
– static, const, volatile, void
• Structured (derived)
– Arrays, structures, unions, classes
• Advanced (composite)
– List, queues, stacks, trees, graphs
Data Structures and algorithms
• Algorithms
– Outline, the essence of a computational procedure, step by step
instruction
• Program
– An implementation of an algorithm in some computer programming
languages
• Data Structures
Data may be organized in many
– Goal: organize data
different ways. the logical and
– Criteria: facilitate efficient mathematical model of a
• storage of data particular organization of data
• retrieval of data is called Data structure
• manipulation of data
• Process:
– select and design appropriate data types
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.
Examples
Searching an online phone directory: Linear search?
OK for small organizations
too slow for large ones
 Amount of data is an important factor.

Compiler lookup of an identifier's type, etc. in a symbol table:


Linear search? No, too slow
Binary search? No, too much work to keep sorted
 Number of accesses & speed required is an important factor.
Use hash tables

Text processing: Store in an array / vector?


OK for text analysis — word counts, average word length, etc.
Not for word-processing — Too inefficient if many insertions & deletions
   Static vs. dynamic nature of the data is an important factor
Abstract Data Type (ADT)
• Abstraction
– Separating data from implementation
– Generalization
– a concept or idea not associated with any specific instance
• ADT(Abstract Data Type)
– A collection of related data items together with basic
operations between them and operations to be performed on
them
– A data type is a collection of values and set of operation on
those values
• values and operation that are implemented using a hardware or
software data structure
abstract data type (ADT)

a collection of
related data items together with
an assoicated set of operations

e.g. whole numbers (integers) and arithmetic operators for


addition, subtraction, multiplication and division.

Why "abstract?"
Data, operations, and relations are studied
independent of implementation.

What not how is the focus.


implementation of an ADT

consists of
storage structures (aka data structures) to store the data items
and
algorithms for the basic operations and relations.

The storage structures/data structures used in implementation are


provided in a language (primitive or built-in)
or built from the language constructs (user-defined).

In either case, successful software design uses data abstraction:


Separating the definition of a data type from its implementation.
Goals of this Course
1. Reinforce the concept that costs and benefits
exist for every data structure.

2. Learn the commonly used data structures.


– These form a programmer's basic data structure
“toolkit”.

3. Understand how to measure the cost of a data


structure or program.
– These techniques also allow you to judge the merits
of new data structures that you or others might
invent.
Linear Data Structure
• Data Structures are said to be linear where data
elements are arranged sequentially or linearly.
• Each and every elements are attached to its previous and
next adjacent. Single level is involved.
• All the elements are traversed in a single run.
• Easy to implement because computer memory is
arranged in a linear way.
• Applications are mostly used in applications software
development.
• Examples include Array, Stack, Queue, Linked List.

18
Non-Linear Data Structure
• Data Structures are said to be non-linear where data
elements are not arranged sequentially or linearly, rather
these are arranged in hierarchical manner.
• There is a multiple level involved in data elements.
• All the elements cannot be traversed in a single run only.
• These are not easy to implement in comparison to non-
linear data structure.
• Applications are mostly used in the area of AI and Image
Processing.
• Examples include Graphs and Trees.

19

You might also like