SAMRAT ASHOKA TECHNOLOGICAL INSTITUTE
COMPUTER SCIENCE AND INFORMATION
TECHNOLOGICAL DEPARTMENT
S.A.T.I.
PRACTICAL FILE
DATA STRUCTURE AND ALGORITHM
AI- 2031
SUBMITTED BY
SUBMITTED TO SRIJAN KUMAR
PROF. RASHI MAM MAHESHWARI
ENROLLMENT NO.
0108AI211057
INDEX
S.NO. TOPIC DATE PAGE NO. REMARK
FIND A PAIR WITH THE GIVEN 6-11-2022
1.
SUM IN AN ARRAY
2. FIND MAXIMUM PRODUCT OF
6-11-2022
TWO INTEGERS IN AN ARRAY
FIND LARGEST NUMBER
6-11-2022
3. POSSIBLE FROM SET OF GIVEN
NUMBERS
PRINT ALL POSSIBLE SOLUTIONS 6-11-2022
4.
TO N QUEENS PROBLEM
CHECK IF A NUMBER IS EVEN OR
6-11-2022
5. ODD WITHOUT USING ANY
CONDITIONAL STATEMENT
6. ALL-PAIRS SHORTEST PATHS – 6-11-2022
FLOYD WARSHALL ALGORITHM
CHECK IF A GRAPH IS STRONGLY
7. 6-11-2022
CONNECTED OR NOT
PRINT COMPLETE BINARY
8. SEARCH TREE (BST) IN 6-11-2022
INCREASING ORDER
FIND THE MINIMUM AND
6-11-2022
MAXIMUM ELEMENT IN AN
9. ARRAY USING DIVIDE AND
CONQUER
CALCULATE THE HEIGHT OF A
10. 6-11-2022
BINARY TREE.
QUESTION-1 :- Find a pair with the given sum in an array.
Answer :-
ALGORITHM:-
Step 1. Start a program.
Step 2. Create array using loop to insert n numbers.
Step 3. Take input for number user want.
Step 4. Run to loops to check if sum of pair is equal to given sum.
Step 5. If pair if found print it else continue.
Step 6. Stop
Input :-
Output:-
Question-2:- Find maximum product of two integers in an array.
Answer:-
ALGORITHM:-
Step 1. Start
Step 2. Create array of n numbers using loop
Step 3. Create a variable which keep track of max multiple of two numbers.
Step 4. Use to loops to multiple the numbers.
Step 5. If multiple number is greater than previous max multiple then change the
multiple to current multiple.
Step 6. Else continue.
Step 7. Print the multiple.
Step 8. Stop
Input:-
Output:-
Question-3 :- Find largest number possible from set of given numbers.
Answer:-
Algorithm:-
Step1. Start with the first number in the set.
Step2. Compare this number to the next number in the set.
Step3. If the first number is larger, move to the next number in the set.
Step4. If the first number is smaller, compare it to the next number in the set.
Step5. If the first number is larger, move to the next number in the set.
Step 6. If the first number is smaller, compare it to the next number in the set.
Step7. Repeat this process until you reach the end of the set.
Step8. The largest number will be the last number compared.
Input:-
Output:-
Question-4:- Print all possible solutions to N Queens problem.
Answer:-
Step 1. start a by including headers.
Step 2. Initialize variable that are needed.
Step 3. create a cheese board "n X n".
Step 4. placing queen without attacking each other.
Step 5. take input as number integer.
Step 6. stat a loop.
Step 7. print number of n.
Step 8. end the program.
Input:-
Output:-
Question-5:- Check if a number is even or odd without using any conditional statement.
Answer:-
ALGORITHM
Step 1. Start
Step 2. Create array for ‘e’ and ‘o’
Step 3. ‘e’ denotes even and ‘o’ denotes odd
Step 4. Find remainder of given number by dividing the number by 2
Step 5. Print the output b putting the remainder in array indexing method
Step 8. Stop
Input:-
Output:-
QUESTION-6:- All-pairs shortest paths – floyd warshall algorithm.
Answer:-
Algorithm:-
1. start a program by including headerds.
2. initalise variable as needed.
3. create a matrix.
4. run a for loop with variable "k"="0 to n" ?
5. another for loop i from 0 to n.
6. followed by loop J also from 0 to n.
7. compare both the statement.
8. print current matrix.
Input:-
‘
Output:-
Question-7:- Check if a graph is strongly connected or not.
Answer:-
Algorithm:-
Input:-
Output:-
Question-8:- Print complete Binary Search Tree (BST) in increasing order.
Answer:- \
Algorithm:-
Step 1.start program,
Step 2.Take input an array
Step 3.Creat binary search tree.
Step 4.Inserting data from array into the binary search.
Step 5.the traverse the tree
Step 6.We shorted the element
Step 7.Print (" Binary Search in ascending")
Step 8.End.
Input:-
Output:-
Question-9:- Find the minimum and maximum element in an array using Divide and Conquer.
Answer:-
Algorithm:-
Step 1.start program
Step 2.Consider the min and max
Step 3.Compare the statement for array containing only one or two elements
Step 4.find the middle element
Step 5.Initialize two variable min and max by - Infinity
Step 6.Print the value of both variable of min and max
Step 7.End the program
Input:-
Output:-
Question-10:- Calculate the height of a binary tree.
Answer:-
Algorithm:-
Step 1. Start a program
Step 2. By using link list concept
Step 3. Make a struct node
Step 4. Take condition if Node = Null
Step 5. Then make a new node
Step 6. Print(“Height of tree1”)
Step 7. End Program
Input:-
Output:-