Data Structure and Algorithm (Module1)
Data Structure and Algorithm (Module1)
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
I. OBJECTIVES
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.
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.
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.
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.
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.
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).
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.
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.
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
You should strive for consistency when writing pseudocode. Being consistent will make it
much easier to translate the pseudocode into actual source code.
DO
READ ch
count = count + 1
END IF
UNTIL ch EQ '\n'
PRINT count
END
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
Activity 1.
2. ____________________ are Data items that are divided into sub items
Noted: