0% found this document useful (0 votes)
4 views2 pages

Lab 1 - DSA

The document is a lab manual introducing data structures and algorithms, focusing on finding the largest number in a linear array. It discusses the importance of data structures in efficiently managing data, addressing common problems like data search and processor speed. Additionally, it outlines characteristics of data structures, how to write algorithms, and provides an example algorithm for finding the largest element in an array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Lab 1 - DSA

The document is a lab manual introducing data structures and algorithms, focusing on finding the largest number in a linear array. It discusses the importance of data structures in efficiently managing data, addressing common problems like data search and processor speed. Additionally, it outlines characteristics of data structures, how to write algorithms, and provides an example algorithm for finding the largest element in an array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DATA STRUCTURE & ALGORITHM LAB MANUAL

Lab 01
INTRODUCTION TO DATA STRUCTURES
AND SHOW THE LARGEST NUMBER IN LINEAR ARRAY

Lab Objective:
Introduction to Data Structures and Algorithms.
Find the largest number in linear array of the user given numbers.

Lab Description:
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.
 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


 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 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.

DEPARTMENT OF COMPUTER SYSTEM ENGINEERING Page | 1


DAWOOD UNIVERSITY OF ENGINEERING AND TECHNOLOGY
DATA STRUCTURE & ALGORITHM LAB MANUAL

 Space Complexity: Memory usage of a data structure operation should be as little as possible

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
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

Algorithm: (Largest Element in an Array)


This algorithm finds the largest element NUM in nonempty array DATA and its position POS. K is the total
number of elements in the array DATA.
Step 1. Set NUM = DATA [1], POS = 1,
Set I=1. ( I is the counter )
Step 2. Set I = I+ 1 [Increment Counter]
Step 3. If I > K, then
Write: POS, NUM and exit.
Step 4. If NUM < DATA [ I ], then [ Compare]
Set POS = I and NUM = DATA [ I ]
Step 5. Goto Step 2 [ Repeat Loop]

Lab Task:
1. Make a program in C++ that finds the largest number of the user given array by using the above
algorithm.
2. Make the above algorithm with Do-While loop.

DEPARTMENT OF COMPUTER SYSTEM ENGINEERING Page | 2


DAWOOD UNIVERSITY OF ENGINEERING AND TECHNOLOGY

You might also like