Professional Documents
Culture Documents
QUESTION 1.
The next greater element of some element x in an array is the first greater
element that is to the right of x in the same array.
You are given two distinct 0-indexed integer arrays nums1 and nums2,
where nums1 is a subset of nums2.
For each 0 <= i < nums1.length, find the index j such that nums1[i] ==
nums2[j] and determine the next greater element of nums2[j] in nums2. If
there is no next greater element, then the answer for this query is -1.
Return an array ans of length nums1.length such that ans[i] is the next
greater element as described above.
Ans: To find the next greater element for each element in nums1 from
nums2, you can follow this algorithm:
1. Initialize an empty stack and an empty dictionary to store the next
greater elements.
2. Iterate through nums2 from right to left:
3. Pop elements from the stack that are less than the current element and
store their next greater element as the current element.
4. Push the current element into the stack.
5. After iterating through nums2, elements left in the stack have no
greater element to their right, so mark them as -1.
6. Create a dictionary mapping elements to their next greater elements.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
7. Iterate through nums1 and retrieve the next greater element from the
dictionary.
Code:
import java.util.HashMap; import java.util.Stack; public class
NextGreaterElement {
public static int[] nextGreaterElement(int[] nums1, int[] nums2) {
Stack<Integer> stack = new Stack<>();
HashMap<Integer, Integer> nextGreater = new
HashMap<>(); for (int num : nums2) { while (!
stack.isEmpty() && stack.peek() <= num) { stack.pop();
} nextGreater.put(num, stack.isEmpty() ? -1 : stack.peek());
stack.push(num);
} int[] result = new int[nums1.length]; for (int i = 0; i < nums1.length; i++)
{ result[i] = nextGreater.get(nums1[i]);
} return
result;
} public static void main(String[] args) { int[] nums1 = {4, 1,
2}; int[] nums2 = {1, 3, 4, 2}; int[] result =
nextGreaterElement(nums1, nums2);
for (int i : result) {
System.out.print(i + " ");
}
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
}
public static void main(String[] args)
{ System.out.println("Addition:");
System.out.println("int: " + add(5, 3));
System.out.println("double: " + add(5.5, 3.3));
System.out.println("\nSubtraction:");
System.out.println("int: " + subtract(5, 3));
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Intermediate Problems
Q1. Simulate a cloud scenario using cloudsim and run a scheduling
algorithm, which is not present in cloudsim.
Ans. To simulate a cloud scenario using CloudSim and run a scheduling
algorithm that is not present in CloudSim, you can follow these steps:
1. Set up the CloudSim environment: First, you need to set up the
CloudSim environment by initializing the CloudSim library, creating
datacenters, and creating a broker.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
2. Create virtual machines (VMs): Next, create the VMs with the
required configurations, such as the number of cores, RAM, and
storage.
3. Create cloudlets: Cloudlets represent the tasks that need to be
executed on the VMs. Create cloudlets with the required
configurations, such as the number of PEs, length, and file size.
4. Implement the scheduling algorithm: Implement the scheduling
algorithm that you want to run on the cloudlets. This algorithm
should take the cloudlets and VMs as input and assign the cloudlets
to the VMs based on the scheduling policy.
5. Submit the cloudlets to the broker: Submit the cloudlets to the broker
for execution on the VMs.
6. Run the simulation: Run the simulation and monitor the performance
metrics, such as the makespan, resource utilization, and throughput.
2.Create cloudlets:
List<Cloudlet> cloudletList = new
ArrayList<>(); // Create cloudlets for (int i = 0; i
< 10; i++) { cloudletList.add(createCloudlet(i,
1000, 1, 1));
}
// Submit cloudlets to the broker
broker0.submitCloudletList(cloudletList); 3. Implement the scheduling
algorithm: public class CustomScheduler extends DatacenterBroker {
@Override public void processCloudletSubmit(CloudletList
cloudletList) { super.processCloudletSubmit(cloudletList); //
Implement the custom scheduling algorithm here
// ...
}
}
4. Submit the cloudlets to the broker:
CustomScheduler scheduler = new CustomScheduler();
scheduler.submitCloudletList(cloudletList);
5. Run the simulation:
CloudSim.startSimulation();
CloudSim.stopSimulation();
Q2. Consider two cloud service systems: Google File System and
Amazon S3. Explain how they achieve their design goals to secure data
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Data backups: Regular data backups ensure that data can be recovered
in case of a system failure.
6. Failover mechanisms: Failover mechanisms ensure that a system
continues to operate even if one of the components fails.
7. Load balancing: Load balancing ensures that a system is not
overloaded, which can lead to system failures.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
To secure the application cloud (SaaS), the infrastructure cloud (IaaS), and
the platform cloud (PaaS), hardware mechanisms such as secure enclaves
and software schemes such as encryption and access control can be used.
Secure enclaves provide a secure area in memory for sensitive data and
code, while encryption ensures that data is protected during transmission and
storage. Access control enables the management of user access to resources,
ensuring that only authorized users can access sensitive data and resources.
However, there are specific requirements and difficulties associated with
these mechanisms and schemes. For example, secure enclaves require
specialized hardware and software, while encryption and access control
require careful key management and configuration. Additionally, there may
be limitations, such as performance overhead and compatibility issues.
Q5. Move file from Host system to Virtual Machine.
Ans. To move a file from the host system to a virtual machine, there are
several methods you can use, depending on the virtualization software
you are using.
For Hyper-V, you can use Enhanced Session Mode, shared folders, or
PowerShell to transfer files from the host to the guest. Enhanced Session
Mode allows you to access the resources on the local host from the virtual
machine, including files and folders. Shared folders allow you to create a
folder on the local host and then map it on the virtual machine to transfer
files from the local host to the virtual machine. PowerShell can help you
transfer files via command, but you need to enable Guest Services on the
VM first.
For VirtualBox, you can use shared folders, ISO files, or USB sticks to
transfer files between the host and the guest. Shared folders allow you to
create a folder on the host machine and then map it on the virtual machine to
transfer files. ISO files can be created from a folder and then mounted to the
VM as a virtual CD/DVD drive. USB sticks can be mounted to the VM as a
physical device to transfer files.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
For VMware, you can use the drag-and-drop feature, the copy and paste
feature, shared folders, or mapped drives to transfer files and text
between the host system and virtual machines and between virtual
machines.
Q6. Build a modular program-using MAKE.
Ans: Building a modular program using make involves creating a Makefile
that specifies the rules for compiling and linking different modules of the
program. Each module should have its own source files and header files, and
the Makefile should specify dependencies between modules. By using
make, you can automate the build process and ensure that only modified
modules are recompiled when necessary.
Here's an example of how to build a modular program using make:
Let's assume we have a simple C program consisting of three modules:
main.c, module1.c, and module2.c, each with their corresponding
header files module1.h and module2.h.
1. Create the source files:
cssCopy code main.c module1.c module2.c
module1.h module2.h
2. Create a Makefile: makeCopy code
# Compiler and flags CC = gcc CFLAGS = -Wall -Wextra -g # Executable
name EXEC = program # Source files and object files SRCS = main.c
module1.c module2.c OBJS = $(SRCS:.c=.o) # Targets all: $(EXEC)
$(EXEC): $(OBJS) $(CC) $(CFLAGS) -o $@ $^ %.o: %.c $(CC)
$(CFLAGS) -c -o $@ $< clean: rm -f $(EXEC) $(OBJS)
3. Explanation of the Makefile:
• CC: Compiler command.
• CFLAGS: Compiler flags for debugging (-Wall, -Wextra, -g).
• EXEC: Name of the executable.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Templates and Images: Create templates and images for virtual machine
provisioning, allowing users to quickly deploy pre-configured VM
instances.
5. Users and Groups: Define user accounts and assign roles and permissions
to control access to cloud resources and operations.
6. Monitoring and Logging: Implement monitoring and logging mechanisms
to track resource usage, performance metrics, and operational activities
within the private cloud environment.
Deployment Process:
1. Installation: Install and configure OpenNebula on a dedicated server or
virtual machine according to the installation guide provided by OpenNebula.
2. Configuration: Configure host nodes, storage, networking, and other
infrastructure components using the OpenNebula management interface or
command-line tools.
3. Integration: Integrate OpenNebula with existing infrastructure components
such as hypervisors, storage systems, and networking devices for seamless
operation.
4. User Management: Set up user accounts, groups, and access controls to
manage user access and permissions within the private cloud environment.
5. Resource Allocation: Allocate computing resources, storage capacity, and
network bandwidth based on workload requirements and organizational
policies.
6. Testing and Validation: Conduct testing and validation to ensure the proper
functioning of the private cloud infrastructure, including provisioning,
migration, and management of virtual machines.
7. Documentation and Training: Document the deployment process,
configuration settings, and operational procedures to facilitate ongoing
management and maintenance. Provide training to system administrators
and users on how to utilize the private cloud platform effectively.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Benefits of OpenNebula:
• Flexibility: OpenNebula supports multiple hypervisors, storage
backends, and networking technologies, allowing organizations to tailor
the private cloud environment to their specific requirements.
• Scalability: The modular architecture of OpenNebula enables horizontal
scaling of infrastructure components to accommodate growing workloads
and user demands.
• Cost-effectiveness: By leveraging existing hardware resources and
opensource software, OpenNebula offers a cost-effective solution for
building and managing private clouds compared to proprietary cloud
platforms.
• Control and Security: With full control over infrastructure resources
and data, organizations can implement robust security measures and
compliance policies to protect sensitive information and ensure
regulatory compliance within the private cloud environment.