Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
657 views

Data Structure and Algorithm (Module1)

This document provides an overview of a learning module on data structures and algorithms. It begins with objectives of understanding data structures, their characteristics, the need for them, and basics of algorithms. It then introduces data structures as a way to organize data for effective operations. Examples are given of using data structures to store and retrieve player records from a file. The key aspects of interfaces, implementations, time complexity and space complexity of data structures are defined. Common problems that data structures help with are searching large datasets efficiently and handling multiple requests. The document concludes with examples of problems that can be solved using data structures and algorithms.

Uploaded by

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

Data Structure and Algorithm (Module1)

This document provides an overview of a learning module on data structures and algorithms. It begins with objectives of understanding data structures, their characteristics, the need for them, and basics of algorithms. It then introduces data structures as a way to organize data for effective operations. Examples are given of using data structures to store and retrieve player records from a file. The key aspects of interfaces, implementations, time complexity and space complexity of data structures are defined. Common problems that data structures help with are searching large datasets efficiently and handling multiple requests. The document concludes with examples of problems that can be solved using data structures and algorithms.

Uploaded by

Karl Ditan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Aemilianum College Inc.

COLLEGE OF ENGINEERING, COMPUTER STUDIES AND TECHNOLOGY (CECT)


and
COLLEGE OF EDUCATION, BUSINESS AND LIBERAL ARTS (CEBLA)
Rizal St., Piot, Sorsogon City
www.aemilianumcollege@gmail.com
http://lms.aemilianum.edu.ph/login/index.php
Contact Nos. 056 211-6012

INSPIRED BY
FAITH,
MOVED BY
SCIENCE

Vision
Inspired by three decades of academic
milestone, the Aemilianum College Inc., as one
of the leading catholic institutions envisions
herself building a better community of faithful, LEARNING MODULE
resilient, skilled professionals and globally
competent individuals, transcending the MODULE 1-2
challenges of modernization.

Mission
The institution guided by the charism of St.
Jerome Emiliani dedicates herself to form
competent and compassionate professionals
Overview
through the enrichment of academic and
religious instructions advancement of skills and
extension of relevant services to the church and
the community.
Core Values
Work, Devotion and Charity

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 1 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
LEARNING MODULE IN DATA STRUCTURES AND ALGORITHMS

I. OBJECTIVES

• Understand the importance of learning Data Structures


• Define the Characteristics of Data Structure
• Understand the need for data structure
• Understand the Basics of Algorithm
• Understand what is Flowcharts and Psuedoscode

II. INTRODUCTION

Data Structure is a way of collecting and organizing data in such a way that we
can perform operations on these data in an effective way. Data Structures is about
rendering data elements in terms of some relationship, for better organization and
storage. For example, we have some data which has, player's name "Virat"
and age 26. Here "Virat" is of String data type and 26 is of integer data type.
We can organize this data as a record like Player record, which will have both
player's name and age in it. Now we can collect and store player's records in a file or
database as a data structure. For example: "Dhoni" 30, "Gambhir" 31, "Sehwag" 33
If you are aware of Object-Oriented programming concepts, then a class also
does the same thing, it collects different type of data under one single entity. The
only difference being, data structures provides for techniques to access and
manipulate data efficiently.
In simple language, Data Structures are structures programmed to store ordered
data, so that various operations can be performed on it easily. It represents the
knowledge of data to be organized in memory. It should be designed and
implemented in such a way that it reduces the complexity and increases the
efficiency.
Java programmers use data structures to store and organize data, and we use
algorithms to manipulate the data in those structures. The more you understand
about data structures and algorithms, and how they work together, the more
efficient your Java programs will be.

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 2 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
III. LESSON

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. This tutorial will give you a great understanding on Data Structures
needed to understand the complexity of enterprise level applications and need of
algorithms, and data structures.

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 (10 6) items
every time slowing down the search. As data grows, search will become slower.
• 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.
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.

Applications of Data Structure and Algorithms

The following computer problems can be solved using Data Structures −

• Fibonacci number series


• Knapsack problem
• Tower of Hanoi
• All pair shortest path by Floyd-Warshall
• Shortest path by Dijkstra

Data Structure is a systematic way to organize data in order to use it efficiently. Following
terms are the foundation terms of a data structure.
• Interface − Each data structure has an interface. Interface represents the set of
operations that a data structure supports. An interface only provides the list of
supported operations, type of parameters they can accept and return type of these
operations.
Aemilianum College Inc. Instructor: Neil F. Fortuno
Bachelor of
Data Structures
Science in Overview 3 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
• Implementation − Implementation provides the internal representation of a data
structure. Implementation also provides the definition of the algorithms used in the
operations of the data structure.

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.

Need for Data Structure

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(10 6) items every
time slowing down the search. As data grows, search will become slower.
• 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.
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.

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 mƒ(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).

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 4 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
Basic Terminology

• Data − Data are values or set of values.


• Data Item − Data item refers to single unit of values.
• Group Items − Data items that are divided into sub items are called as Group Items.
• Elementary Items − Data items that cannot be divided are called as Elementary
Items.
• Attribute and Entity − An entity is that which contains certain attributes or
properties, which may be assigned values.
• Entity Set − Entities of similar attributes form an entity set.
• Field − Field is a single elementary unit of information representing an attribute of
an entity.
• Record − Record is a collection of field values of a given entity.
• File − File is a collection of records of the entities in a given entity set.

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.

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 5 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
• 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.

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.
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
In design and analysis of algorithms, usually the second method is used to describe
an algorithm. It makes it easy for the analyst to analyze the algorithm ignoring all
unwanted definitions. He can observe what operations are being used and how the
process is flowing.

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 6 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
Writing step numbers, is optional.
We design an algorithm to get a solution of a given problem. A problem can be solved
in more than one way.

Hence, many solution algorithms can be derived for a given problem. The next step
is to analyze those proposed solution algorithms and implement the best suitable
solution.

Algorithm Analysis

Efficiency of an algorithm can be analyzed at two different stages, before


implementation and after implementation. They are the following −
• A Priori Analysis − This is a theoretical analysis of an algorithm. Efficiency of
an algorithm is measured by assuming that all other factors, for example,
processor speed, are constant and have no effect on the implementation.
• A Posterior Analysis − This is an empirical analysis of an algorithm. The
selected algorithm is implemented using programming language. This is then
executed on target computer machine. In this analysis, actual statistics like
running time and space required, are collected.

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 7 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
Pseudocodes and Flowcharts
A flowchart is a visual representation of an algorithm's control flow. This
representation illustrates statements that need to be executed, decisions that need
to be made, logic flow (for iteration and other purposes), and terminals that indicate
start and end points.

Fig.1 Flowchart Symbols and Functions

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 8 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
Fig. 2. Example of a Flowchart

An alternative to flowcharts is pseudocode, which is a textual representation of an


algorithm that approximates the final source code. Pseudocode is useful for quickly writing
down an algorithm's representation. Because syntax is not a concern, there are no hard-
and-fast rules for writing pseudocode.

You should strive for consistency when writing pseudocode. Being consistent will make it
much easier to translate the pseudocode into actual source code.

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 9 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
DECLARE CHARACTER ch = ''

DECLARE INTEGER count = 0

DO

READ ch

IF ch GE '0' AND ch LE '9' THEN

count = count + 1

END IF

UNTIL ch EQ '\n'

PRINT count

END

Fig. 3. Sample Pseudocode

The pseudocode first presents a couple of DECLARE statements that introduce


variables ch and count, initialized to default values. It then presents a DO loop that
executes UNTIL ch contains \n (the newline character), at which point the loop ends and
a PRINT statement outputs count's value.

For each loop iteration, READ causes a character to be read from the keyboard (or perhaps
a file--in this case it doesn't matter what constitutes the underlying input source) and
assigned to ch. If this character is a digit (one of 0 through 9), count is incremented by 1.

IV. REFERENCES

https://www.infoworld.com/article/3215112/java-101-datastructures-and-
algorithms-in-java-part-1.html?page=2

https://www.tutorialspoint.com/data_structures_algorithms/algorithms_basics.
htm

https://www.owlnet.rice.edu/~ceng303/manuals/fortran/FOR3_3.html

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 10 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
V. ASSESSMENT

Activity 1.

Name: ____________________________ Date: ___________________

Course & Year: _________________________

Identification. Write the correct answers in the blank space provided.


1. _____________________are values or set of values.

2. ____________________ are Data items that are divided into sub items

3. _____________________are Data items that cannot be divided.

4. _____________________ is a collection of field values of a given entity.

5. _____________________ are Entities of similar attributes form an entity set.

6. _____________________is a collection of field values of a given entity.

7. _____________________ is a single elementary unit of information representing


an attribute of an entity.

8. ______________________ refers to single unit of values.

9. ______________________ is the running time or the execution time of operations


of data structure must be as small as possible.

10. _______________________is the memory usage of a data structure operation


should be as little as possible.

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 11 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
Activity 2.

Name: ____________________________ Date: ___________________

Course & Year: _________________________

Multiple Choice. Encircle the correct answer.

1. Algorithm to search an item in a data structure.


a. Sort
b. Searching
c. Search/
d. Sorting
2. Algorithm to insert item in a data structure.
a. Insert/
b. Input
c. Dividing
d. Adding
3. Algorithm to update an existing item in a data structure.
a. Algorithm
b. Sorting
c. Update/
d. Delete
4. Algorithm to sort items in a certain order.
a. Sort/
b. Update
c. Delete
d. Search
5. Algorithm to erase an existing item from a data structure.
a. Search
b. Erase
c. Sort
d. None of the above/

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 12 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
6. An algorithm should have 0 or more well-defined inputs.
a. Unambiguous
b. Input/
c. Delete
d. Sort
7. Algorithms must terminate after a finite number of steps.
a. Independent
b. Finiteness/
c. Feasibility
d. Output
8. An algorithm should have 1 or more well-defined outputs, and should match the
desired output.
a. Independent
b. Finiteness
c. Feasibility
d. None of the above/
9. This is a theoretical analysis of an algorithm.
a. Posterior Analysis
b. Priority Analysis
c. Priori Analysis/
d. All of the above
10. a visual representation of an algorithm's control flow
a. Pseudocodes
b. Flowchart/
c. Posterior Analysis
d. None of the above
Prepared by:
NEIL F. FORTUNO
Instructor

Noted:

JOSEFINA R. SARMIENTO, MIT LYDIA L. ANINIPOT, Ed. D.


Dean, CECT Dean, CEBLA

Aemilianum College Inc. Instructor: Neil F. Fortuno


Bachelor of
Data Structures
Science in Overview 13 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.
Aemilianum College Inc. Instructor: Neil F. Fortuno
Bachelor of
Data Structures
Science in Overview 14 of
And Second Year
Information 14
Algorithms
Technology
Course Subject Course Year Level Current Module
Page
no.

You might also like