0% found this document useful (0 votes)
3 views24 pages

Lec1 Introduction - 1

The document outlines a course on data structures and algorithms, emphasizing the importance of understanding and implementing efficient data structures in programming using C/C++. It covers fundamental concepts, characteristics of good software, various data structures, and their applications, as well as abstract data types and algorithms. The course aims to prepare students for programming challenges and interviews by enhancing their problem-solving skills.

Uploaded by

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

Lec1 Introduction - 1

The document outlines a course on data structures and algorithms, emphasizing the importance of understanding and implementing efficient data structures in programming using C/C++. It covers fundamental concepts, characteristics of good software, various data structures, and their applications, as well as abstract data types and algorithms. The course aims to prepare students for programming challenges and interviews by enhancing their problem-solving skills.

Uploaded by

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

Data

Structures
Muhammad Usman Joyia
Course Objective
Introduce the basic concepts of data structures /ADTs, and use them
efficiently in algorithms for solving various problems using C/C++
What should you expect in this course?
◦ Extensive programming
◦ A lot of thinking

What should you learn by the end of this course


◦ Ability to understand common programming problems and design and
implement efficient data structures to solve them

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Why should we study
this course?
Well, because it is the core computer sciences course
Any other reason to study this course?
We want to make a successful career after graduation
The most common programming interviews questions
◦ Linked lists
◦ Strings
◦ Binary Trees
◦ Arrays
◦ Queues

Source: http://maxnoy.com/interviews.html

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Introduction
Fundamentals of data structures
An overview of computer programming
Data types
Abstract data types
C/C++ Background
Review of pointers
◦ Defining pointer variables

Supplying values to pointer variables

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Fundamentals
of Data
Structures
What is a data
structure?
Data structures are used in almost every program or software system
In computer sciences, a data structure is a particular way of storing
and organizing data in a computer so that it can be used efficiently
◦ Efficient data structures  Efficient algorithms

Focus: Efficiency and performance


◦ Time and space analysis of algorithms

Performance is the measure of quality of


the work done by any machine.
efficiency is the ratio of desired output to
the required input for any machine.

Source: http://en.wikipedia.org/wiki/Data_structure
DEPARTMENT OF COMPUTER SCIENCE, FAST-NU
Performance vs
efficiency
Performance is the measure of quality of the work done by any
machine.
Efficiency is the ratio of desired output to the required input for
any machine.

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Important
characteristics of a
good software
A good design
Easy to implement
Easy to use
Easy to maintain
Reliable solution of the given problem
 So, the data structure to solve a particular problem should be
selected with the above objectives in mind

Source: http://en.wikipedia.org/wiki/Data_structure
DEPARTMENT OF COMPUTER SCIENCE, FAST-NU
Some example data
structures…

Arrays Stack Tree Linked List


Data structure = representation and operations associated
with a data type

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Example of data
structure

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Data structure
applications
Arrays
◦ Consecutive memory locations
◦ lists (one dimensional arrays)
◦ matrices (two dimensional arrays)
◦ database applications
◦ to implement other data structures, such as heaps, hash tables, queues, stacks,
strings
Stacks
◦ expression evaluation and syntax parsing

Queues
◦ scheduling
◦ transportation
◦ operations management

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Data structure
applications
Trees
◦ Efficient searching of data (binary search tree)
◦ Manipulate hierarchical data
◦ Manipulate sorted data

Linked lists
◦ Can be used to implement several other common abstract data structures,
such as
◦ Stacks
◦ Queues
◦ Symbolic expressions, etc.

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


What is an algorithm?
In mathematics and computer science, an algorithm is a step-by-step
procedure for solving a problem
◦ expressed as a finite list of well-defined instructions
◦ with a finite amount of data
◦ in a finite amount of time

Algorithms are used for


◦ calculations
◦ data processing, and
◦ solving complex problems?

In simple words:
◦ an algorithm is a step-by-step procedure for computations

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Sample problem
What are the sequence of steps to be followed to start a car

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


The algorithm to start
the car
◦ Insert the key
◦ Make sure car is in neutral gear
◦ Press the gas pedal/ (Accelerator)
◦ Turn the key to the start position
◦ If the engine starts in 6 seconds 
◦ Release the key to the ignition position
◦ Else if the engine does not start in 6 seconds 
◦ Release the key and gas pedal
◦ Wait for 10 seconds , and repeat the steps 3 – 6, but no more than 5 times
◦ If the car does not start
◦ Call the workshop

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Data types
primitive data types in c/c++
Some primitive data
types…
Name Description Size Range
char Character or small 1 byte signed: -128 to 127
integer unsigned: 0 to 255
Int Integer 4 bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
iong int (long) Long integer 4 bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool Boolean value. It can 1 byte true or false
take one of two values:
true or false
float Floating point number 4 bytes +/- 3.4e +/- 38 (~7 digits)

double Double precision 8 bytes +/- 1.7e +/- 308 (~15 digits)
floating point number

long double Long double precision 8 bytes +/- 1.7e +/- 308 (~15 digits)
floating point number

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Arrays
Used to store a collection of elements (variables)
type array-name[size];
Meaning:
This declares a variable called <array-name> which contains <size>
elements of type <type>
The elements of an array can be accessed as: array-name[0],…
array-name[size-1]
Example:
int a[100]; //a is a list of 100 integers, a[0], a[1], …a[99]
double b[50];
char c[10];

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Abstract data types
Abstraction – Omitting or hiding low-level details with a simpler,
higher-level idea. For example, the user only has to understand the
preconditions and postconditions of the program, not the full internal
behavior of the it.
Abstract data types is a powerful idea that enables to separate how we
use a data structure in a program from the particular form of the data
structure itself.

Reading: https://web.mit.edu/6.031/www/sp17/classes/12-abstract-data-types/

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Abstract data type
In computer science, an abstract data type (ADT) is a mathematical
model for data types, where a data type is defined by its behavior
(semantics) from the point of view of a user of the data, specifically in
terms of possible values, possible operations on data of this type, and
the behavior of these operations
ADT users are NOT concerned with how the task is done but rather
what it can do.
An abstract data type is a data declaration packaged together with the
operations that are meaningful for the data type.

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Abstract data types:
Example
Example: abstract stack (functional)
A complete functional-style definition of a stack ADT could use the
three operations:
◦ push: takes current stack state and an arbitrary value, insert it into the stack
and returns updated state;
◦ top: takes a current state, returns a value;
◦ pop: takes current state, delete a value from top, returns updated state;

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Abstract data types:
Excercise
Consider an abstract data type Bool. The type has the following
operations:
true : Bool
false : Bool
and(Bool, Bool) : Bool
Or(Bool × Bool) : Bool
Not(Bool) : Bool
… where the first two operations construct the two values of the type,
and the last three operations have the usual meanings of logical and,
logical or, and logical not on those values.

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Answer the following…
Which of the following are possible ways that Bool might be
implemented, and still be able to satisfy the specs of the operations?
Choose all that apply.
◦ As a single bit, where 1 means true and 0 means false.
◦ As an int value where 5 means true and 8 means false.
◦ As a reference to a String object where "false" means true and "true" means
false.
◦ As a long value where all possible values mean true.
◦ As an int value > 1 where prime numbers mean true and composite numbers
mean false.

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU


Explanation
All are correct.
Bool can be implemented by any kind of data structure, as long as it
distinguishes the two values true and false along with the operations
specified on the values.
That’s the essence of what makes an abstract data type. The operations
themselves (and their specs) completely define the data type,
abstracting away from the details of data structure, memory storage, or
implementation. It’s a Bool data type because it provides these
operations, not because of how it’s actually stored inside the machine

DEPARTMENT OF COMPUTER SCIENCE, FAST-NU

You might also like