You are on page 1of 12

SVKM’s NMIMS

Mukesh Patel School of Technology Management & Engineering Shirpur Campus


Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

Experiment # 1
Date of Performance:-12-12-2023 Date of Submission:- 12-12-2023
Class:- MBA TECH CE DIV-B
Student SAP Id:- 70472200296
Student Roll No:- N274
Student Name:- Jenish Mehta
TITLE: Implement the basic programs of array in C or C++.

AIM: To understand the programming concept using array.


1. Write a program in C to store elements in an array and print it.
Test Data :
Input 10 elements in the array :
element - 0 : 1
element - 1 : 1
element - 2 : 2
.......
Expected Output :
Elements in array are: 1 1 2 3 4 5 6 7 8 9
2. Write a program in C to read n number of values in an array and display it in reverse
order.
Test Data :
Input the number of elements to store in the array :3
Input 3 number of elements in the array :
element - 0 : 2
element - 1 : 5
element - 2 : 7
Expected Output :
The values store into the array are :
257
The values store into the array in reverse are :
752
3. Write a program in C to find the sum of all elements of the array.
Test Data :
Input the number of elements to be stored in the array :3
Input 3 elements in the array :
element - 0 : 2
element - 1 : 5
element - 2 : 8
Expected Output :
Sum of all elements stored in the array is : 15
4. Write a program in C to copy the elements of one array into another array.
Test Data :

1
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

Input the number of elements to be stored in the array :3


Input 3 elements in the array :
element - 0 : 15
element - 1 : 10
element - 2 : 12
Expected Output :
The elements stored in the first array are :
15 10 12
The elements copied into the second array are :
15 10 12
5. Program to find the average of n (n < 10) numbers using arrays
6. Task 1: Illustrate the operation of INSERTION-SORT on the array A = [32, 45, 29, 66,
41, 58, your roll no]
Task2: Implementation of Insertion Sort
Task 3: Comment on the performance of Insertion Sort, after filling up the following
table

Array Data No. of No. of Swaps


Size(n) Comparisons
4
8
16

Task 4: Find out number of times each step will be executed if array is almost sorted.
Demonstrate with an example.

INSTRUCTIONS FOR STUDENTS:


1. Implement Program in C Programming Language.
2. Copy and Paste Code as per instructions.
3. Write Conclusion.
4. Answer all the Questions.

SOURCE CODE:

INPUT AND OUTPUT:

1.

2
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

OUTPUT:

2.

3
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

OUTPUT:

3.

4
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

OUTPUT:

4.

5
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

OUTPUT:

5.

6
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

OUTPUT:

6.

7
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

TASK 1: Original Array: [32, 45, 29, 66, 41, 58, 274]

1. Iteration 1:
Sorted Array: [32, 45, 29, 66, 41, 58, 274]
Key: 45 (the second element)
Comparison: 32 < 45 (true), no swap

2. Iteration 2:
Sorted Array: [32, 45, 29, 66, 41, 58, 274]
Key: 29 (the third element)
Comparison: 45 > 29 (false), swap 45 and 29
Updated Array: [32, 29, 45, 66, 41, 58, 274]

3. Iteration 3:
Sorted Array: [32, 29, 45, 66, 41, 58, 274]
Key: 66 (the fourth element)
Comparison: 45 < 66 (true), no swap

4. Iteration 4:
Sorted Array: [32, 29, 45, 66, 41, 58, 274]
Key: 41 (the fifth element)
Comparison: 66 > 41 (false), swap 66 and 41
Updated Array: [32, 29, 45, 41, 66, 58, 274]

5. Iteration 5:
Sorted Array: [32, 29, 45, 41, 66, 58, 274]
Key: 58 (the sixth element)
Comparison: 66 > 58 (false), swap 66 and 58
Updated Array: [32, 29, 45, 41, 58, 66, 274]

6. Iteration 6:
Sorted Array: [32, 29, 45, 41, 58, 66, 274]
Key: 274 (the seventh element)
Comparison: 66 < 274 (true), no swap

Final Sorted Array: [32, 29, 45, 41, 58, 66, 274]

TASK 2:

8
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

OUTPUT:

TASK 3:

9
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

Output:

Array Size(n) No. of Comparisons No. of Swaps

10
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

4 3 0
8 7 0
16 15 0

QUESTIONS:

Q-1 What is Algorithm?


An algorithm is a step-by-step set of instructions or rules designed to perform a specific task or
solve a particular problem.

Q-2 What is the difference between algorithm and program?

Algorithm:
- An algorithm is a step-by-step set of well-defined instructions or rules
designed to perform a specific task or solve a particular problem.
- Algorithms are abstract and independent of any specific programming language
or implementation.
- Algorithms provide a high-level description of a solution to a problem,
focusing on the logic and steps involved.

Program:
- A program is a set of instructions written in a specific programming language
that can be executed by a computer to perform a particular task.
- Programs are concrete and language-specific implementations of algorithms.
- Programs take the abstract idea of an algorithm and provide the detailed,
executable instructions necessary for a computer to carry out a task.

Q-3 What is the difference between priori and posterior analysis of algorithm?

1. A Priori Analysis of Algorithm:


 A priori analysis involves predicting the performance of an algorithm
before it is actually implemented or executed. It is based on theoretical
analysis and mathematical reasoning.
 This type of analysis relies on assumptions about the input data, the
machine model, and the algorithm itself. It aims to estimate the
algorithm's efficiency without the need for actual implementation or
experimentation.

11
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Instructor Manual Lab Manual Academic Year- 2023-24
Year:- II Subject:- Design & Analysis of algorithms Semester:- IV

 A priori analysis provides insights into the algorithm's efficiency in an


abstract sense. However, it may not always reflect the real-world
performance accurately, as it makes assumptions that might not hold in
practical scenarios.
2. A Posteriori Analysis of Algorithm:
 A posteriori analysis involves evaluating the performance of an algorithm
after it has been implemented and executed on a specific computer
system with actual input data.
 This type of analysis is empirical and involves measuring the algorithm's
actual behaviour in practice. It considers factors such as the specific
programming language, compiler, hardware, and input characteristics.
 A posteriori analysis provides a more realistic assessment of an algorithm's
efficiency under specific conditions. It takes into account the actual
runtime performance and resource usage. However, it requires
implementation and execution, which may be resource-intensive

12

You might also like