






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is solution to assignment for Aeronautical Engineering and Computer Programming course. It was submitted to Prof. Chitraksh Gavde at Biju Patnaik University of Technology, Rourkela. It includes: Spanning, Tree, Minimum, Prim, Parent, Fringe, Insert, Bubble, Array, Loop, Input, Output
Typology: Exercises
1 / 12
This page cannot be seen from the preview
Don't miss anything!







Home Work 9
The problems in this problem set cover lectures C7, C8, C9 and C
Prim’s Algorithm
Step 1.
Step 2
Step 3
Minimum Spanning Tree
Weight of the MST = 10 + 20 + 25 + 20 + 35 = 110
Kruskals Algorithm
Initialization
1
4
5 3
6
2 10
35
50
45
30
25
55
20
20
1
4
5 3
6
2
Step 1
1
4
5 3
6
2
35
50
45
30
25
55
20
20
1
4
5 3
6
2
35
50
45
30
25
55
20
20
10
1
4
5 3
6
2 10
1
4
5 3
6
2
Step 2
1
4
5 3
6
2
35
50
45
30
25
55
20
1
4
5 3
6
2
35
50
45
30
25
55
20 10
20
1
4
5 3
6
2 10
20
1
4
5 3
6
2
Algorithm Procedure Bubble_Sort(Input_Output_Array)
for I in 1 .. My_Array_Max loop for J in I+1 .. My_Array_Max loop
if (Input_Output_Array(I) <= Input_Output_Array(J)) then Temp := Input_Output_Array(I); Input_Output_Array(I) := Input_Output_Array(J); Input_Output__Array(J) := Temp; end if; end loop; end loop;
end Bubble_Sort;
O(N(N-1)) = O(N^2 )
a. Inserting a node into an unsorted singly linked list
Inserting into an unsorted singly linked list is carried out using the add_to_front operation. Both the best and worst case execution time is O(1).
b. Inserting a node into a sorted singly linked list
In the case of a sorted linked list, the list has to be traversed to find the right position. The list traversal takes O(n) in the worst case.
Best case execution time is O(1) if the element being inserted is the smallest element in the list (list in ascending order)
Worst case execution time is O(n) if the element being inserted is the largest element in the list (list in ascending order)
a. Design an Ada95 Package to: i. Read in N integers from an input file into an array. (N is user defined <=50) ii. Sort the array in ascending order iii. Perform binary search on the array.
The package is designed as follows: Data Structures:
type my_array is array (1 .. 50) of integer;
Subprograms: -- procedure to create an array with <=50 elements -- assumes that input can be found in input_file.txt -- accepts the array -- returns array with elements read from file and the number of elements read procedure Create ( Num_Array : in out My_Array; Size : out Integer );
procedure Merge ( Input_Array : in out My_Array; Lb_1 : in Integer; Ub_1 : in Integer; Lb_2 : in Integer; Ub_2 : in Integer ); -- procedure to sort the array in ascending order -- accepts the array and the lowerbound(lb) and upperbound(ub) -- returns the sorted array procedure Merge_Sort ( Num_Array : in out My_Array; Lb : in Integer; Ub : in Integer );
--function to perform binary search on the array -- accepts the array, lb, ub and the element being searched for -- returns the index of the element if it is found -- returns -1 if the element is not found function Binary_Search ( Num_Array : My_Array; Lb : Integer; Ub : Integer; Looking_For : Integer ) return Integer;
The merge sort procedure will recursively call itself until it has only single element arrays. These are inherently sorted. It will then merge the successively larger elements until the whole sorted array is produced.
Merge
Pre-Conditions: An array of 1 or more elements, Legal values of Lower_Bound_1, Upper_Bound_1, Lower_Bound_2 and Upper_Bound_2,
Post-Condition: A merged array that is sorted
Algorithm
c. Index := Index + 1;
Binary Search
Pre-Conditions: Array to be searched Item that you are searching for
Post-condition: Index location of the item you are searching for Return –1 if the number is not found. Algorithm
iii. if ( Input_Array(Current_Index) > Number_to_Search) then Lower_Bound = Current_Index + else Upper_Bound = Current_Index – 1
b. Write a program to test your package that will
-- program to test Home_Work_9 Package -- Programmer: Jayakanth Srinivasan -- Date Last Modified: April 06,
with Ada.Text_Io; with Ada.Integer_Text_IO; with Home_Work_9; use Home_Work_9;
procedure Test_Hw_9 is