0% found this document useful (0 votes)
2 views

Data Structures and Algorithm - 0(1)

The document discusses the importance of data structures and algorithms in efficiently storing and processing data in applications, particularly as data complexity increases. It outlines characteristics of data structures and algorithms, their applications, and the properties that define a good algorithm. Additionally, it provides guidance on writing algorithms and emphasizes that a good computer program combines both effective algorithms and data structures.

Uploaded by

kayelpat2708
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Data Structures and Algorithm - 0(1)

The document discusses the importance of data structures and algorithms in efficiently storing and processing data in applications, particularly as data complexity increases. It outlines characteristics of data structures and algorithms, their applications, and the properties that define a good algorithm. Additionally, it provides guidance on writing algorithms and emphasizes that a good computer program combines both effective algorithms and data structures.

Uploaded by

kayelpat2708
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

DATA

STRUCTURES
Prof. Adrian V. Antopina, BSIM, LPT
Central Philippine University
College of Computer Studies
Copyright 2015
Data Structure

Data Structures are the


programmatic way of storing data
so that data can be used efficiently.
Almost every enterprise application
uses various types of data
structures in one or the other way.
Why to Learn Data Structure and
Algorithms?
As applications are getting complex and data rich, there are three
common problems that applications face now-a-days.

Data Search − Consider an inventory of 1 million(106) items of a


store. If the application is to search an item, it has to search an item
in 1 million(106) items every time slowing down the search. As data
grows, search will become slower.
Why to Learn Data Structure and
Algorithms?
Processor speed − Processor speed although being very high,
falls limited if the data grows to billion records.

Multiple requests − As thousands of users can search data


simultaneously on a web server, even the fast server fails while
searching the data.
Why to Learn Data Structure and
Algorithms?
 To solve the above-mentioned problems, data structures come to
rescue. Data can be organized in a data structure in such a way
that all items may not be required to be searched, and the
required data can be searched almost instantly.
Characteristics of a Data
Structure
 Correctness − Data structure implementation should implement
its interface correctly.
 Time Complexity − Running time or the execution time of
operations of data structure must be as small as possible.
 Space Complexity − Memory usage of a data structure
operation should be as little as possible.
Applications of Data Structure and
Algorithms
 From the data structure point of view, following are some
important categories of algorithms −
 Search − Algorithm to search an item in a data structure.
 Sort − Algorithm to sort items in a certain order.
 Insert − Algorithm to insert item in a data structure.
 Update − Algorithm to update an existing item in a data
structure.
 Delete − Algorithm to delete an existing item from a data
structure.
Algorithms

 An algorithm is a step by step recipe for solving an instance of a


problem.
 Every single procedure that a computer performs is an algorithm
 An algorithm is a precise procedure for solving a problem in
finite number of steps.
 An algorithm states the actions to be executed and the order in
which these actions are to be executed.
 An algorithm is a well ordered collection of clear and simple
instructions of definite and effectively computable operations
that when executed produces a result and stops executing at
some point in a finite amount of time rather than just going on
and on infinitely.
Execution Time Cases

There are three cases which are usually used to compare various data
structure's execution time in a relative manner.
 Worst Case − This is the scenario where a particular data structure
operation takes maximum time it can take. If an operation's worst
case time is ƒ(n) then this operation will not take more than ƒ(n) time
where ƒ(n) represents function of n.
 Average Case − This is the scenario depicting the average
execution time of an operation of a data structure. If an operation
takes ƒ(n) time in execution, then m operations will take ƒ(n) time.
 Best Case − This is the scenario depicting the least possible
execution time of an operation of a data structure. If an operation
takes ƒ(n) time in execution, then the actual operation may take time
as the random number which would be maximum as ƒ(n).
Data Structures - Algorithms
Basics
Algorithm is a step-by-step procedure, which defines a set of
instructions to be executed in a certain order to get the desired output.
Algorithms are generally created independent of underlying languages,
i.e. an algorithm can be implemented in more than one programming
language.
From the data structure point of view, following are some important
categories of algorithms −
 Search − Algorithm to search an item in a data structure.
 Sort − Algorithm to sort items in a certain order.
 Insert − Algorithm to insert item in a data structure.
 Update − Algorithm to update an existing item in a data structure.
 Delete − Algorithm to delete an existing item from a data structure.
Characteristics of an Algorithm

 Not all procedures can be called an algorithm. An algorithm should


have the following characteristics −
 Unambiguous − Algorithm should be clear and unambiguous. Each of
its steps (or phases), and their inputs/outputs should be clear and must
lead to only one meaning.
 Input − An algorithm should have 0 or more well-defined inputs.
 Output − An algorithm should have 1 or more well-defined outputs,
and should match the desired output.
 Finiteness − Algorithms must terminate after a finite number of steps.
 Feasibility − Should be feasible with the available resources.
 Independent − An algorithm should have step-by-step directions,
which should be independent of any programming code.
Algorithm Properties

An algorithm possesses the following properties:


– It must be correct.
– It must be composed of a series of concrete steps.
– There can be no ambiguity as to which step will be performed
next.
– It must be composed of a finite number of steps. – It must
terminate. – It takes zero or more inputs
- It should be efficient and flexible
– It should use less memory space as much as possible
– It results in one or more outputs
How to Write an Algorithm?

 How to Write an Algorithm?


 There are no well-defined standards for writing algorithms.
Rather, it is problem and resource dependent. Algorithms are
never written to support a particular programming code.
 As we know that all programming languages share basic code
constructs like loops (do, for, while), flow-control (if-else), etc.
These common constructs can be used to write an algorithm.
 We write algorithms in a step-by-step manner, but it is not always
the case. Algorithm writing is a process and is executed after the
problem domain is well-defined. That is, we should know the
problem domain, for which we are designing a solution.
Good Computer Program

 Programs consists of two things: Algorithms and data structures.


 A Good Program is a combination of both algorithm and a data
structures.
 An algorithm is a step by step recipe for solving an instance of a
problem.
 A data structure represents the logical relationship that exists
between individual elements of data to carry out certain tasks
 A data structure defines a way of organizing all data items that
consider not only the elements stored but also stores the
relationship between the elements
Good Computer Program
A computer program is a series of instructions to carry out a particular task
written in a language that a computer can understand.
The process of preparing and feeding the instructions into the computer for
execution is referred as programming.
There are a number of features for a good program
 Run efficiently and correctly
 Have a user friendly interface
 Be easy to read and understand
 Be easy to debug
 Be easy to modify
 Be easy to maintain
Example

Let's try to learn algorithm-writing by using an example.


Problem − Design an algorithm to add two numbers and display the result.

Step 1 − START
Step 2 − declare three integers a, b & c
Step 3 − define values of a & b
Step 4 − add values of a & b
Step 5 − store output of step 4 to c
Step 6 − print c
Step 7 − STOP
Algorithms tell the programmers how to code the program. Alternatively, the
algorithm can be written as −

Step 1 − START ADD


Step 2 − get values of a & b
Step 3 − c ← a + b
Step 4 − display c
Step 5 − STOP

You might also like