[go: up one dir, main page]

0% found this document useful (0 votes)
2 views185 pages

Dsa Lab Manual

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 185

Lab Manual Data Structures and Algorithms SZABIST

Data Structures and Algorithms

Laboratory
Experiments Manual
CSCL-2102

Semester 3rd
Fall-2022

Student Name: ______________________________________________

Roll Number: _______________________________________________

Lab Instructor: Syed Muhammad Hassan

Department of Computing Sciences


Shaheed Zulfiqar Ali Bhutto Institute Of Science And Technology, Karachi,Pakistan
Tel:(021)111-922-478, Fax: (021)35830446, Email: info@szabist.edu.pk
I

Preface
This laboratory manual is composed of three parts. Part one provides the general information
about use in programming and gives specific information about the equipment and lab safety.
It also provides the brief information about the IDE environment like INTELLIJ. Part two
includes the laboratory experiments, problem exercises to be performed .Part three contains the
student result that is in accordance to the Lab performance, Technical knowledge, viva voce,
Assignments, Quiz, Project, its report, term and final Exams.

Department of Computing Sciences


Shaheed Zulfiqar Ali Bhutto Institute Of Science And Technology, Karachi,Pakistan
Tel:(021)111-922-478, Fax: (021)35830446, Email: info@szabist.edu.pk
II

Introduction
The purpose of this course is to provide the students with solid foundations in the basic concepts
of programming: data structures and algorithms. The main objective of the course is to teach
the students how to select and design and implement data structures and algorithms that are
appropriate for problems that they might encounter. This course is also about showing the
correctness of algorithms and studying their computational complexities. This lab course is
designed is designed to implement of core concepts of data structures and algorithms.

Department of Computing Sciences


Shaheed Zulfiqar Ali Bhutto Institute Of Science And Technology, Karachi,Pakistan
Tel:(021)111-922-478, Fax: (021)35830446, Email: info@szabist.edu.pk
III

LAB OBJECTIVES
Upon successful completion of this Lab course, the student should be able to:

➢ Implement various data Structures and their algorithms and apply them in implementing
simple applications..

➢ Analyze simple algorithms and determine their complexities.

➢ Analyze simple algorithms and determine their complexities

➢ Implement hash tables, including collision avoidance and resolution

➢ The ability to utilize logic, mathematics, and physical sciences to model and solve

Computer Science problems

➢ The ability to think critically, perform scientific analysis and develop solutions for
typical Computer Science problems.

➢ Reinforce theory and techniques taught in the class through experiments and projects

in the laboratory.

Department of Computing Sciences


Shaheed Zulfiqar Ali Bhutto Institute Of Science And Technology, Karachi,Pakistan
Tel:(021)111-922-478, Fax: (021)35830446, Email: info@szabist.edu.pk
IV

LIST OF EXPERIMENTS
S# Date Experiments Page
Introduction to Java Programming Environment, Time Complexity & 1
1
Space Complexity.
Introduction to Array, Types of Arrays, Static and Dynamic Array 8
2 Implementation and Exercises.

Introduction to Linked List, Singly Linked List Implementation and 21


3
Exercises.
Types of Linked List i.e Circular Linked List Implementation and 40
4 Exercises.

Types of Linked List i.e Doubly Linked List Implementation and 46


5 Exercises.

Introduction to Stack, Stack Implementation and Exercises Including 54


6 PUSH, POP & PEEK Functions.

Introduction to Queue, Linear Queue Implementation and Exercises 68


7 Including ENQUEUE, DEQUEUE.
Types Of Queues including Circular Queue & Priority Queue 81
8 Implementation and Exercises.
Searching Algorithms including Linear Search, Binary Search, 91
9 Implementations in Iterative & Recursive Approach.
Searching Algorithms including Ternary Search, Jump Search, 102
10 Implementations.

Sorting Algorithms including Insertion Sort, Selection Sort & Bubble 114
11 Sort Implementations in Iterative & Recursive Approach.

Sorting Algorithms including Merge Sort & Quick Sort 128


12 Implementations.
Binary Search Tree Introduction and Implementation with Exercises 145
13 of Various Functions and Traversal Algorithms.
AVL Tree Introduction and Implementation with Exercises of 166
14 Various Functions and Rotations.

Department of Computing Sciences


Shaheed Zulfiqar Ali Bhutto Institute Of Science And Technology, Karachi,Pakistan
Tel:(021)111-922-478, Fax: (021)35830446, Email: info@szabist.edu.pk
V

SUBJECT: CSCL-2102 Lab: Data Structures and Algorithms

Marks Evaluation Sheet


Sr.
Date Date Examiner
No.
Topics Marks/Grade Performed Checked Initial’s

1 Introduction

2 ARRAYS

3 SINGLY LINKED LIST

4 CIRCULAR LINKED LIST

DOUBLY LINKED LIST


5

6 STACK

7 LINEAR QUEUE

8 CIRCULAR & PRIORITY QUEUE

9 LINEAR & BINARY SEARCH

10 TERNARY & JUMP SEARCH

INSERTION, SELECTION &


11
BUBBLE SORT ALGORITHMS
MERGE & QUICK SORT
12
ALGORITHMS

13 BINARY SEARCH TREE

14 AVL TREE

Remarks

Finalized Marks Examiner Initial’s

Department of Computing Sciences


Shaheed Zulfiqar Ali Bhutto Institute Of Science And Technology, Karachi,Pakistan
Tel:(021)111-922-478, Fax: (021)35830446, Email: info@szabist.edu.pk
VI

Guidelines to Students

➢ Students must thoroughly read the assigned work. It will be assumed that they have
studied the assigned work and have understood the majority of the material and
technical terms before the start of the experiments.
➢ All the original data have to be recorded in a Report sheet during the laboratory
sessions. Data recording on rough sheets of papers are not allowed. In order to check
for the originality of the data, ball pen or inerasable pen should be used. If correction
has to be made, just cross it out. They must hand over the Report sheet to the
demonstrator for their signature after data count.
➢ For safety reasons, students are requested not to leave their equipment unattended
during the laboratory session. In the case of special circumstances, please seek the
support of the class teachers/demonstrators.
➢ All practical contribute to the final results of the sessional course. Thus any absent
laboratory session automatically means lost marks for the final grade. Under special
circumstances (supported by documentary proof), e.g. illness and other reasonable
causes a laboratory session may be re-scheduled upon approval of the head of the
department.
➢ During the class, students will be continuously assessed by performance test on each
and every experiment.
➢ To ensure your fellow students can proceed with their experiments in a degree of
comfort and without undue noise and other disturbances, keep the noise level down and
stay in your own laboratory bench area. Mobile phones should be switched off during
the experiments.
➢ Equipment in the laboratory for the use of student community. Students need to
maintain a proper decorum in the electronics and computer laboratories. Student must
use the equipment with care. In case of any damage, students should be pay for it.

➢ Students are required to carry their report sheet, observation books or laboratory
exercise manuals with complete exercises while entering the laboratory.

➢ Buns the CD with all Simulink home activity files and attach at the end of this manual.

➢ Laboratory records needs to be submitted on or before date of submission.

Department of Computing Sciences


Shaheed Zulfiqar Ali Bhutto Institute Of Science And Technology, Karachi,Pakistan
Tel:(021)111-922-478, Fax: (021)35830446, Email: info@szabist.edu.pk
Experiment # 1 Introduction
Data Structure
In computer science, a data structure is a data organization, management, and storage format that enables
efficient access and modification. More precisely, a data structure is a collection of data values, the
relationships among them, and the functions or operations that can be applied to the data.

Algorithm

In mathematics and computer science, an algorithm is a finite sequence of well-defined, computer-


implementable instructions, typically to solve a class of problems or to perform a computation.
Algorithms are always unambiguous and are used as specifications for performing calculations, data
processing, automated reasoning, and other tasks.

Big O notation

We use Big O notation to describe the performance of an Algorithm.

O(1) Constant time

1|Page
O(n)

2|Page
3|Page
O(n2)

Graph Difference

4|Page
O(n3)

5|Page
Lab Tasks:
1) Identify Runtime Complexity by making different kinds of
functions in JAVA .
2) Identify Space Complexity by making different kinds of functions
in JAVA .
3) Analyze difference between Runtime Complexity and Space
Complexity.

6|Page
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5


3 On Time Submission 5
4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

7|Page
Experiment # 02

OBJECTIVE:
Introduction to Array, Types of Arrays, Static and Dynamic Array Implementation and
Exercises.

8|Page
9|Page
10 | P a g e
11 | P a g e
12 | P a g e
13 | P a g e
Exercise 1 • 1- Extend the Array class and add a new method to return the largest number. What is the
runtime complexity of this method?

• 2- Extend the Array class and add a method to return the common items in this array and another array.

14 | P a g e
• 3- Extend the Array class and add a method to return the product of Array.

• 4 - Extend the Array class and add a method to return the average of Array.

15 | P a g e
• 5 - Extend the Array class and add a method to return the reverse of Array.

• 6 - Extend the Array class and add a method to return the distinct numbers of Array.

16 | P a g e
• 7 - Extend the Array class and add a method to Replace any number from Array.

• 8 - Extend the Array class and add a method to return Even Numbers from Array.

17 | P a g e
• 9 - Extend the Array class and add a method to return ODD Numbers from Array.

• 10 - Extend the Array class and add a method to return Prime Numbers from Array.

18 | P a g e
Lab Tasks:

1) Create a Program in JAVA for implementation of Dynamic Array.


2) Create method for INSERT operation of ARRAY.
3) Create method for REMOVE operation of ARRAY.
4) Create method for SEARCH operation of ARRAY.
5) Create method for finding MAX number in ARRAY.
6) Create method for finding MIN number in ARRAY.
7) Create method for finding Common number of items from two
ARRAYS.
8) Create method for finding Product of numbers in ARRAY.
9) Create method for finding AVERAGE of numbers in ARRAY.
10) Create method for returning REVERSE of ARRAY.
11) Create method for finding Distinct numbers in ARRAY.
12) Create method for REPLACE number in ARRAY.
13) Create method for finding EVEN numbers in ARRAY.
14) Create method for finding ODD numbers in ARRAY.
15) Create method for finding PRIME numbers in ARRAY.

19 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5


3 On Time Submission 5
4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

20 | P a g e
Experiment # 03 Introduction to Linked List, Singly
Linked List Implementation and Exercises.

Linked List

In computer science, a linked list is a linear collection of data elements whose order is not given by their
physical placement in memory. Instead, each element points to the next. It is a data structure consisting of
a collection of nodes which together represent a sequence. In its most basic form, each node contains:
data, and a reference (in other words, a link) to the next node in the sequence. This structure allows for
efficient insertion or removal of elements from any position in the sequence during iteration. More
complex variants add additional links, allowing more efficient insertion or removal of nodes at arbitrary
positions. A drawback of linked lists is that access time is linear. Faster access, is not feasible. Arrays
have better access time when compared to linked lists.

Array Drawbacks Over Linked List

Resizing array is possible by making new array and copying data from existing array which can be
resource intensive depending on the size of array.

Inserting Data at any index in between can be difficult due to iterating over each element in array and
making room for the data by shifting existing elements in higher index within an array.

21 | P a g e
22 | P a g e
23 | P a g e
24 | P a g e
25 | P a g e
26 | P a g e
27 | P a g e
28 | P a g e
29 | P a g e
30 | P a g e
31 | P a g e
32 | P a g e
33 | P a g e
34 | P a g e
35 | P a g e
36 | P a g e
37 | P a g e
Lab Tasks:
1) Create a Program in JAVA for implementation of Singly Linked List.

2) Create a method for INSERT node at first position of Singly Linked List.

3) Create a method for Delete node from first position of Singly Linked List.

4) Create a method for Display data from Singly Linked List.

5) Create a method for INSERT node at last position of Singly Linked List.

6) Create a method for Delete node from last position of Singly Linked List.

7) Create a method for INSERT node at middle position of Singly Linked List.

8) Create a method for DELETE node from middle position of Singly Linked List.

9) Create a method to REVERSE Singly Linked List.

10) Create a method to FIND MAX number from SINGLY LINKED LIST.

11) Create a method to FIND MIN number from SINGLY LINKED LIST.

12) Create a method to SEARCH position of data in SINGLY LINKED LIST.

38 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5


3 On Time Submission 5
4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

39 | P a g e
Experiment # 04
OBJECTIVE:
Types of Linked List i.e Circular Linked List Implementation and Exercises.

Advantages of Circular Linked Lists

• Any node can be a starting point. We can traverse the whole list by starting from any point. We just need
to stop when the first visited node is visited again.

• Useful for implementation of queue. Unlike this implementation, we don’t need to maintain two pointers
for front and rear if we use circular linked list. We can maintain a pointer to the last inserted node and
front can always be obtained as next of last.

• Circular lists are useful in applications to repeatedly go around the list. For example, when multiple
applications are running on a PC, it is common for the operating system to put the running applications on
a list and then to cycle through them, giving each of them a slice of time to execute, and then making
them wait while the CPU is given to another application. It is convenient for the operating system to use a
circular list so that when it reaches the end of the list it can cycle around to the front of the list.

40 | P a g e
41 | P a g e
42 | P a g e
43 | P a g e
Lab Tasks:
1) Create a Program in JAVA for implementation of Circular Linked List.
2) Create a method for INSERT node at first position of Circular Linked List.
3) Create a method for Delete node from first position of Circular Linked List.
4) Create a method for Display data from Circular Linked List.
5) Create a method for INSERT node at last position of Circular Linked List.
6) Create a method for Delete node from last position of Circular Linked List.
7) Create a method for INSERT node at middle position of Circular Linked List.
8) Create a method for DELETE node from middle position of Circular Linked List.
9) Create a method to REVERSE Circular Linked List.
10) Create a method to FIND MAX number from Circular LINKED LIST.
11) Create a method to FIND MIN number from Circular LINKED LIST.
12) Create a method to SEARCH position of data in Circular LINKED LIST.

44 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5


3 On Time Submission 5
4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

45 | P a g e
Experiment # 05

OBJECTIVE:

Types of Linked List i.e Doubly Linked List Implementation and Exercises.

46 | P a g e
47 | P a g e
48 | P a g e
49 | P a g e
50 | P a g e
51 | P a g e
Lab Tasks:
1) Create a Program in JAVA for implementation of Doubly Linked List.
2) Create a method for INSERT node at first position of Doubly Linked List.
3) Create a method for Delete node from first position of Doubly Linked List.
4) Create a method for Display data from Doubly Linked List.
5) Create a method for INSERT node at last position of Doubly Linked List.
6) Create a method for Delete node from last position of Doubly Linked List.
7) Create a method for INSERT node at middle position of Doubly Linked List.
8) Create a method for DELETE node from middle position of Doubly Linked List.
9) Create a method to REVERSE Doubly Linked List.
10) Create a method to FIND MAX number from Doubly LINKED LIST.
11) Create a method to FIND MIN number from Doubly LINKED LIST.
12) Create a method to SEARCH position of data in Doubly LINKED LIST.

52 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5


3 On Time Submission 5
4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

53 | P a g e
Experiment # 06
OBJECTIVE:

Introduction to Stack, Stack Implementation and Exercises Including PUSH, POP & PEEK Functions.

54 | P a g e
55 | P a g e
56 | P a g e
57 | P a g e
58 | P a g e
59 | P a g e
• 1- Create a Method to Print Max/Min value in Stack!

• 2- Create a Method to Print Product value in Stack!

• 3- Create a Method to Print Average value in Stack!

• 4- Create a Method to Replace Top value in Stack!

• 5- Create a Method to print Even/ODD in Stack!

• 6- Create a Method to Search for value position in Stack!

60 | P a g e
• Create a Function in Main Class using Stack Implementation For reversing a String.

61 | P a g e
62 | P a g e
63 | P a g e
64 | P a g e
65 | P a g e
Lab Tasks:

1) Create a program in JAVA for the implementation of STACK data structure using
Array.

2) Create a method to PUSH data into STACK.

3) Create a method to POP data from STACK.

4) Create a method to PEEK data in STACK.

5) Create a method to check if STACK is FULL.

6) Create a method to check if STACK is EMPTY.

7) Create a method to Find MAX number in STACK.

8) Create a method to Find MIN number in STACK.

9) Create a method to Find AVERAGE number in STACK.

10) Create a method to SEARCH for value position in STACK.

11) Create a method to print EVEN/ODD number in STACK.

12) Create a method to REVERSE data in STACK.

13) Create a program in JAVA for the implementation of STACK data structure
using Linked List.

66 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5

3 On Time Submission 5

4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

67 | P a g e
Experiment # 07
OBJECTIVE:
Introduction to Queue, Linear Queue Implementation and Exercises Including ENQUEUE, DEQUEUE.

68 | P a g e
69 | P a g e
70 | P a g e
71 | P a g e
72 | P a g e
73 | P a g e
74 | P a g e
75 | P a g e
76 | P a g e
77 | P a g e
78 | P a g e
Lab Tasks:

1) Create a program in JAVA for the implementation of QUEUE data structure using
Array.

2) Create a method to ENQUEUE data into QUEUE.

3) Create a method to DEQUEUE data from QUEUE.

4) Create a method to PEEK data in QUEUE.

5) Create a method to check if QUEUE is FULL.

6) Create a method to check if QUEUE is EMPTY.

7) Create a method to Find MAX number in QUEUE.

8) Create a method to Find MIN number in QUEUE.

9) Create a method to Find AVERAGE number in QUEUE.

10) Create a method to SEARCH for value position in QUEUE.

11) Create a method to print EVEN/ODD number in QUEUE.

12) Create a method to REVERSE data in QUEUE.

13) Create a program in JAVA for the implementation of QUEUE data structure
using Linked List.

79 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5

3 On Time Submission 5

4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

80 | P a g e
Experiment # 08
OBJECTIVE:
Types Of Queues including Circular Queue & Priority Queue Implementation and Exercises.

81 | P a g e
82 | P a g e
83 | P a g e
84 | P a g e
85 | P a g e
86 | P a g e
87 | P a g e
88 | P a g e
Lab Tasks:

1) Create a program in JAVA for the implementation of CIRCULAR


QUEUE data structure using Array.

2) Create a method to PUSH data into CIRCULAR QUEUE.

3) Create a method to POP data from CIRCULAR QUEUE.

4) Create a method to PEEK data in CIRCULAR QUEUE.

5) Create a method to check if CIRCULAR QUEUE is FULL.

6) Create a method to check if CIRCULAR QUEUE is EMPTY.

7) Create a method to Find MAX number in CIRCULAR QUEUE.

8) Create a method to Find MIN number in CIRCULAR QUEUE.

9) Create a method to Find AVERAGE number in CIRCULAR QUEUE.

10) Create a method to SEARCH for value position in CIRCULAR


QUEUE.

11) Create a method to print EVEN/ODD number in CIRCULAR


QUEUE.

12) Create a method to REVERSE data in CIRCULAR QUEUE.


13) Create a program in JAVA for the implementation of CIRCULAR
QUEUE data structure using Linked List.
14) Create a program in JAVA for the implementation of PRIORITY
QUEUE.

89 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5

3 On Time Submission 5

4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

90 | P a g e
Experiment # 09
OBJECTIVE:
Searching Algorithms including Linear Search, Binary Search, Implementations in
Iterative & Recursive Approach.

91 | P a g e
92 | P a g e
93 | P a g e
94 | P a g e
95 | P a g e
96 | P a g e
97 | P a g e
98 | P a g e
99 | P a g e
Lab Tasks:
1)Create a function to search for Integer Data using Approach of Iterative Linear Search
Algorithm.

2)Create a function to search for Integer Data using Approach of Recursive Linear Search
Algorithm.

3)Create a function to search for Integer Data using Approach of Iterative Binary Search
Algorithm.

4)Create a function to search for Integer Data using Approach of Recursive Binary Search
Algorithm.

100 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5

3 On Time Submission 5

4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

101 | P a g e
Experiment # 10
OBJECTIVE:
Searching Algorithms including Ternary Search, Jump Search, Implementations.

102 | P a g e
103 | P a g e
104 | P a g e
105 | P a g e
106 | P a g e
107 | P a g e
108 | P a g e
109 | P a g e
110 | P a g e
111 | P a g e
Lab Tasks:

1)Create a function to search for Integer Data using Approach of Iterative Ternary
Search Algorithm.

2)Create a function to search for Integer Data using Approach of Recursive Ternary
Search Algorithm.

3)Create a function to search for Integer Data using Approach of Iterative Jump
Search Algorithm.

4)Create a function to search for Integer Data using Approach of Recursive Jump
Search Algorithm.

112 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5


3 On Time Submission 5
4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

113 | P a g e
Experiment # 11
OBJECTIVE:
Sorting Algorithms including Insertion Sort, Selection Sort & Bubble Sort Implementations in Iterative &
Recursive Approach.

114 | P a g e
115 | P a g e
116 | P a g e
117 | P a g e
118 | P a g e
119 | P a g e
120 | P a g e
121 | P a g e
122 | P a g e
123 | P a g e
124 | P a g e
Lab Tasks:

1)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Ascending) Order by using Approach of (Iterative Selection Sort Algorithm).

2)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (

Ascending ) Order by using Approach of (Recursive Selection Sort Algorithm).

3)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Descending) Order by using Approach of (Iterative Selection Sort Algorithm).

4)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in ( Descending ) Order by using Approach of (Recursive Selection Sort Algorithm).

5)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Ascending) Order by using Approach of (Iterative Insertion Sort Algorithm).

125 | P a g e
6)Create a function to sort Integer Array which should be taken as Input from user by using Scanner cla ss
object then sort in

(Ascending) Order by using Approach of (Recursive Insertion Sort Algorithm).

7)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Descending) Order by using Approach of (Iterative Insertion Sort Algorithm).

8)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in (Descending) Order by using Approach of (Recursive Insertion Sort Algorithm).

9)Create a function to sort Integer Array which should be taken as Input from user by using Scanner class
object then sort in

(Ascending) Order by using Approach of (Iterative Bubble Sort Algorithm).

10)Create a function to sort Integer Array which should be taken as Input from user by using Scanner
class object then sort in

(Ascending) Order by using Approach of (Recursive Bubble Sort Algorithm).

11)Create a function to sort Integer Array which should be taken as Input from user by using Scanner
class object then sort in (Descending) Order by using Approach of (Iterative Bubble Sort Algorithm).

12)Create a function to sort Integer Array which should be taken as Input from user by using Scanner
class object then sort in (Descending) Order by using Approach of (Recursive Bubble Sort Algorithm).

126 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5

3 On Time Submission 5

4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

127 | P a g e
Experiment # 12
OBJECTIVE:
Sorting Algorithms including Merge Sort & Quick Sort Implementations.

128 | P a g e
129 | P a g e
130 | P a g e
131 | P a g e
132 | P a g e
133 | P a g e
134 | P a g e
135 | P a g e
136 | P a g e
137 | P a g e
138 | P a g e
139 | P a g e
140 | P a g e
141 | P a g e
142 | P a g e
Lab Tasks:

1) Create a function for implementation of Recursive Merge Sort Algorithm for


sorting of Integer Data in Descending Order.

2) Create a function for implementation of Iterative Merge Sort Algorithm for


sorting of Integer Data in Descending Order.

3) Create a function for implementation of Iterative Quick Sort Algorithm for


sorting of Integer Data in Descending Order.

4) Create a function for implementation of Recursive Quick Sort Algorithm for


sorting of Integer Data in Descending Order.

143 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5


3 On Time Submission 5
4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

144 | P a g e
Experiment # 13
OBJECTIVE:
Binary Search Tree Introduction and Implementation with Exercises of Various
Functions and Traversal Algorithms.

BACKGROUND THEORY:

In computer science, a binary search tree (BST), also called an ordered or sorted binary tree, is a rooted
binary tree whose internal nodes each store a key greater than all the keys in the node's left subtree and less
than those in its right subtree. A binary tree is a type of data structure for storing data such as numbers in
an organized way. Binary search trees allow binary search for fast lookup, addition and removal of data
items . The order of nodes in a BST means that each comparison skips about half of the remaining tree, so
the whole lookup takes time proportional to the binary logarithm of the number of items stored in the tree.
This is much better than the linear time required to find items by key in an (unsorted) array

145 | P a g e
146 | P a g e
147 | P a g e
148 | P a g e
149 | P a g e
150 | P a g e
151 | P a g e
152 | P a g e
153 | P a g e
154 | P a g e
155 | P a g e
156 | P a g e
157 | P a g e
158 | P a g e
159 | P a g e
160 | P a g e
161 | P a g e
162 | P a g e
163 | P a g e
Lab Tasks:

1) Create a method by which we can INSERT INT value in BINARY SEARCH TREE.
2) Create methods by which we can FIND INT value in BST & Calculate Height Of BST.
3) Create methods to Traverse Tree in PRE Order Traversal, POST Order Traversal, IN Order
Traversal.
4) Create methods to return MAX & MIN value in BST.
5) Create methods to Validate BST & Find Equality of Two BSTs.

164 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5


3 On Time Submission 5
4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

165 | P a g e
Experiment # 14
OBJECTIVE:
AVL Tree Introduction and Implementation with Exercises of Various Functions and
Rotations.

166 | P a g e
167 | P a g e
168 | P a g e
169 | P a g e
170 | P a g e
171 | P a g e
172 | P a g e
173 | P a g e
174 | P a g e
175 | P a g e
Lab Tasks:

1) Create a method by which we can INSERT INT value in AVL TREE.


2) Create methods to return HEIGHT & SETHEIGHT of AVL TREE.
3) Create methods for checking Balance Factor, isLeftHeavy() & isRightHeavy() of a AVL
TREE.
4) Create a method to check Balance of AVL TREE.
5) Create methods to perform rotations by implementing rotateLeft() & rotateRight() of AVL
TREE.

176 | P a g e
Lab’s Evaluation Sheet

Students Registration No

Date Performed:
Group No:

Date of Submission

Marks /Grade
Sr. No. Categories Total Marks/Grade
Obtained

1 Student’s Behavior 2.5

2 Lab Performance 2.5


3 On Time Submission 5
4 Home Activity 10

Net Result 20

Examined By: Syed Muhammad Hassan Date

177 | P a g e

You might also like