You are on page 1of 18

UNIVERSITY INSTITUTE OF ENGINEERING

Department of Computer Science & Engineering


(BE-CSE/IT-6th Sem)

Subject Name: ADVANCED PROGRAMMING LAB – 2

Subject Code: 21CSP-351

Submitted to: Submitted by:

Er. Shariq (E14803) Name: Lokesh Raj

UID: 21BCS8668

Section: 21BCS_CC_625

Group: A
INDEX

Name: Lokesh Raj UID: 21BCS8668

Ex. Name of Experiments Date Conduct Viva Worksheet Total Remarks Signature
No (MM: 12) (MM: 10) (Record) (MM: 30) (with date)
(MM: 8)

1. Arrays, Stacks, Queues


linked list

2. String Matching

3. Heap model

4. Hashing

5. Trees

6. Graph

7. Divide and conquer

8. Greedy

9. Backtracking

10. Dynamic Programming


UNIVERSITY INSTITUTE OF ENGINEERING
Department of Computer Science & Engineering

Subject Name: CLOUD COMPUTING AND DISTRIBUTED SYSTEMS


LAB
Subject Code: 21CSP378

Submitted to: Submitted by:

Er Piyush Name: Lokesh Raj

UID: 21BCS8668

Section: CC-625

Group: A
INDEX

Ex. List of Experiments Conduct Viva Record Total Remarks/Signature


No (MM: 12) (MM: 10) (MM: 8) (MM: 30)
Install VirtualBox or
1.1 VMware Workstation on a
Windows 7 or 8 operating
system and set up various
flavors of Linux or Windows
as virtual machines.
To install a C compiler
1.2 within the virtual machine
established using VirtualBox
and run basic programs.
Installation of Cloud Sim
1.3
tool and IDE.

Use of GAE launcher to


1.4 launch the web applications.

Simulate a cloud scenario


2.1 using Matlab and run a
scheduling algorithm.
To find a procedure to
2.2 transfer the files from one
virtual machine to another
virtual machine.
Discover a method for
2.3 initiating a virtual machine
using the TryStack (Online
OpenStack Demo Version).
Install Hadoop single node
3.1 cluster and run simple
applications like word count.
Case Studies on Cloud based
3.2 machine-learning solutions
in healthcare.
Lab based Mini Project
3.3
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment - 1.1
Student Name: Lokesh Raj UID: 21BCS8668
Branch: Computer Science Engineering Section/Group: CC-625-A
Semester: 6th Date of Performance: Jan 15, 2024
Subject Name: Cloud Computing & Distributed Systems Lab
Subject Code: 21CSP-378

1. Aim: Install VirtualBox or VMware Workstation on a Windows 7 or 8


operating system and set up various flavors of Linux or Windows as a virtual
machine.

2. Objective: To install VirtualBox and set up various flavors of Linux or


Windows as a virtual machine.

3. Algo. /Approach and output:


I. Download the virtual box.exe and click the exe file and select next button.
DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


II. Click on next button till the following page appears and click on install
button.

III. Click on finish button.

Steps to import iso file of windows:


DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


1. Download and install media creation tool.

2. Choose ISO media file to use.

3. Download Windows ISO media file in PC.


DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

4. Open Virtual Box and Click on New Button.

5. Give a name to the Virtual Machine and Select the downloaded Windows
ISO file.
DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


6. Now, click on next and change the password of the Virtual Machine and then
click on Next button.

7. Allocate base memory and processors to the Virtual Machine and click on
the Next Button.
DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


8. By following the above steps the set up of Virtual Machine has been
successfully completed.

IV. Learning Outcomes:


a. Learnt about installation of Virtual Box.
b. Learnt about uses of and functionality of VirtualBox.
c. Learnt about setting up of OS in Virtual Box.
V. Analysis:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 1.1
Student Name: Lokesh Raj UID: 21BCS8668
Branch: BE-CSE Section/Group: 625/A
Semester: 6th Date of Performance: 16-01-24
Subject Name: Advance Programming II Subject Code: 21CSP-351

1. Aim: To implement the concept of Arrays, Queues and Stack and Linked List.

2. Objective:
Problem: 3Sum
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]]
such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.

3. Algorithm:-

1. Sort the input array in non-decreasing order.


2. Initialize an empty set (resultSet) to store unique triplets.
3. Iterate through the array using a loop with index i from 0 to n-2, where n is the
size of the array.
• Initialize two pointers, j (i + 1) and k (n - 1).

• While j is less than k:

• Calculate the sum, sum = nums[i] + nums[j] + nums[k].

• If sum is zero, add the triplet {nums[i], nums[j], nums[k]} to


resultSet.
• If sum is greater than zero, decrement k.

• If sum is less than zero, increment j.

4. Convert resultSet to a vector and return it as the final result.

5. Source Code:
class Solu7on {
public:
// Shubham Gaurav 21BCS11419
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
vector<vector<int>> threeSum(vector<int>& nums) {
set<vector<int>> st;
sort(nums.begin(), nums.end());
vector<vector<int>> ans;
int n = nums.size();

for (int i = 0; i < n - 2; i++) {


int j = i + 1;
int k = n - 1;

while (j < k) {
int a = nums[i];
int b = nums[j];
int c = nums[k];

if ((a + b + c) == 0) {
st.insert({a, b, c});
j++;
k--;
} else if ((a + b + c) > 0) {
k--;
} else {
j++;
}
}
}

for (auto it : st) {


ans.push_back(it);
}

return ans;
}
};

6. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Learning Outcomes:
1. Learnt about different data structures and manipulation on them, including
arrays, queues, stacks, and linked lists.
2. Proficiently implemented algorithms for optimized data storage and retrieval
using arrays.
3. Learnt about different time complexities associated with different approach to
solve a problem.
Experiment-1.2
Student Name: Lokesh Raj UID: 21BCS8668
Branch: BE-CSE Section/Group:622-'A'
Semester: 6th Date of Performance:23Jan
Subject Name: Advanced Programming lab-2 Subject Code:21CSP-351

Aim:
• Rotate String
• Repeated string match
• Find Index of First Occurences

Objective:
• Given two strings s and goal, return true if and only if s can become goal after some number of
shifts on s. A shift on s consists of moving the leftmost character of s to the rightmost position.
• Given two strings a and b, return the minimum number of times you should repeat string a so
that string b is a substring of it. If it is impossible for b to be a substring of a after repeating it,
return -1.
• Given two strings needle and haystack, return the index of the first occurrence of needle in
haystack, or -1 if needle is not part of haystack.

Algorithm:

Repeated String algorithm :


1. Create a temporary string s and set it equal to a.
2. Initialize a counter count to 1.
3. Calculate the maximum number of repetitions needed (n = length of b / length of a).
4. Loop i from 0 to n (inclusive):
a. If s contains b as a substring, return count.
b. Concatenate a to s.
c. Increment count.
5. If the loop completes without finding a match, return -1.
Rotate String :
1. Check if the lengths of the two input strings s and goal are not equal. If they are not equal,
return false since rotating strings of different lengths cannot produce the same string.
2. Concatenate the string s with itself, effectively creating a new string that contains all possible
rotations of the original string.
3. Check if the goal string is a substring of the concatenated string s.
4. If the goal string is found in the concatenated string, return true; otherwise, return false.

Find Index of first occurrences:

1. Initialize variables n to the length of needle, h to the length of haystack, i, and c to 0.


2. Loop from i = 0 to (h - n + 1):
a. If substring of haystack starting at index i with length n is equal to needle:
i. Set c to 1.
ii. Break the loop.
3. If c is 1, return the value of i; otherwise, return -1.

Code(A):

public:
bool rotateString(string s, string goal) {
if(s.length()!=goal.length()) return false;
s=s+s;

cout<<" " <<" 21BCS7439 ";

if(s.find(goal)<s.length())
return true;
return false;
}
};
Output(A):

Code(B):
class Solution {
public:
int repeatedStringMatch(string a, string b) {
string s=a;
int count=1;
int n=b.length()/a.length();

cout<<" UDAY PRATAP SINGH "<<" 21BCS7439 ";

for(int i=0;i<n+1;i++){
if(s.find(b)!=-1) return count;
s+=a;
count++;
}
return -1;
}
};
Output(B):

Code(C):
class Solution {
public:
int strStr(string haystack, string needle) {
int n = needle.length(),h = haystack.length(),i,c=0;
for(i=0;i<(h-n+1);i++){

cout<<" UDAY PRATAP SINGH "<<" 21BCS7439 ";

if(needle == haystack.substr(i,n)){
c=1;
break;
}
}
if(c==1) return i;
return -1;
}
};
Output(C):

Time complexity : A) O(N)


B) O(N)
C) O(N)
Space complexity : A) O(1)
B) O(1)
C) O(1)

You might also like