0% found this document useful (0 votes)
4 views

hpc_1-3

The document provides an overview of Google Colab, highlighting its features, advantages, and disadvantages, as well as practical exercises involving Linux commands and the implementation of the Quick Sort algorithm using Python. Google Colab is a hosted Jupyter Notebook service that offers free access to computing resources, making it suitable for machine learning and data science. Additionally, it discusses the Divide and Conquer strategy, emphasizing its efficiency and application in sorting algorithms.

Uploaded by

kandrakarthik15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

hpc_1-3

The document provides an overview of Google Colab, highlighting its features, advantages, and disadvantages, as well as practical exercises involving Linux commands and the implementation of the Quick Sort algorithm using Python. Google Colab is a hosted Jupyter Notebook service that offers free access to computing resources, making it suitable for machine learning and data science. Additionally, it discusses the Divide and Conquer strategy, emphasizing its efficiency and application in sorting algorithms.

Uploaded by

kandrakarthik15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

FACULTY OF ENGINEERING AND TECHNOLOGY


HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

PRACTICAL NO-01

AIM- Study the facilities provided by Google Colab.

INTRODUCTION-
What is Google Colab?
Colab is a hosted Jupyter Notebook service that requires no setup to use and provides free
access to computing resources, including GPUs and TPUs. Colab is especially well suited to
machine learning, data science, and education.

Facilities provided by Google Colab-


1. Create a new notebook
Go to file and select and create notebook in drive.

Page | 1
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

2. Rename notebook.

3. Write and execute python code.

Page | 2
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

4. Write a Mathematical equation.

5. We can put headings.

6. Move cells up and down.

7. Delete cell.

Page | 3
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

8. Change runtime.

9. Share notebook.

Page | 4
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

10. Upload files on GitHub.

Page | 5
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

11. Generate insights.

12. Cloud.
Colab notebooks execute code on Google’s Cloud servers, meaning you can leverage the
power of Google hardware , including GPUs and TPUs , regardless of the power of your
machine. All you need is a browser.

Advantages of Google Colab-

1. Free access to GPUs and TPUs


2. No installation required
3. Collaborative features
4. Integration with Google drive
5. Pre-install libraries
Page | 6
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

6. Easy access to resources


7. Support for markdown and latex
8. Interactive visualization

Disadvantages of Google colab

1. Limited resources
2. Session timeouts
3. Dependency management
4. Privacy and security
5. Limited customization
6. Performance variability
7. Storage limits
8. Learning curve

Page | 7
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

PRACTICAL-02

AIM: Execute 20 Linux commands on Google Colab and document their execution.

LIST OF 20 COMANDS:
1. Date - Displays the current date and time.
2. ls - Lists files and directories in the current directory.
3. pwd - Displays the current directory path.
4. whoami - Displays the current user.
5. cd - Changes the directory.
6. hostname - Prints the name of the machine (hostname).
7. mkdir - Creates a new directory.
8. du - Displays disk usage for files and directories.
9. top - Displays real-time system processes and resource usage
10. tree - Displays the structure of the directory as a tree
11. stat - Displays detailed information about the directory, including size
permissions and last modified time.
12. echo - Creates a file inside the directory and writes to it.
13. ls -R - list directories and their contents recursively.
14. ls -l - Lists files in a long format, displaying permissions, owner, size, and
modification time.
15. cat - Displays the contents of the file inside the directory.
16. grep - Searches for the word in the file.
17. mv - Renames the file inside the student directory.
18. zip - Compresses the directory into a zip file.
19. Unzip - Extracts the contents of the file back into the directory.
20. Find - Searches for the directory named in the current directory tree.

EXECUTION OF COMMANDS:
Command 1: date

• Description:
Displays the current date and time.
Page | 8
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

• Code:
!date

Command 2: ls

• Description:
The ls command lists all files and directories in the current working directory.
• Code:
!ls

Command 3: pwd

• Description:
The pwd command prints the absolute path of the current working directory.
• Code: !pwd

Command 4: whoami

• Description:
The whoami command displays the username of the current user.
• Code: !whoami

Page | 9
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

Command 5: cd
• Description:
The cd command is used to navigate between directories.
• Code:
!cd /content && ls

Command 6: hostname

• Description:
Prints the name of the machine (hostname).
• Code:
!hostname

Command 7: mkdir

• Description:
Creates a new directory.
• Code:
!mkdir student

Command 8: du

• Description:
Displays disk usage for files and directories.
• Code:
!du -h

Page | 10
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

Command 9: top

• Description:
Displays real-time system processes and resource usage (limited in Colab).
• Code:
!top -n

Command 10: tree

• Description:
Displays the structure of the directory as a tree (requires tree to be installed).
• Code:
!tree student

Page | 11
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

Command 11: stat

• Description:
Displays detailed information about the directory, including size, permissions, and
last modified time.

• Code:
!stat student

Command 12: echo

• Description:
Creates a file inside the directory and writes to it.
• Code:
!echo "Hello, Student!" > student/welcome.txt

Page | 12
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

Command 13: ls -R

• Description: Used to list directories and their contents recursively, meaning it will list
all files and subdirectories within a directory and continue to list the contents of any
subdirectories.
• Code:
!ls -R student

Command 14: ls -l

• Description:
The command !ls -l student is used in Linux to list the contents of the student
directory in a detailed format.
• Code:
!ls -l student

Page | 13
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

Command 15: du -sh

• Description:
Displays the total disk usage of the student directory in a human-readable format.
• Code:
!du -sh student

Command 16: cat

• Description:
Displays the contents of the file welcome.txt inside the student directory.
• Code:
!cat student/welcome.txt

Command 17: grep

• Description:
Searches for the word "Student" in the welcome.txt file.

• Code:

!grep "Student" student/welcome.txt

Page | 14
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

Command 18: mv

• Description:
Renames the file welcome.txt to hello.txt inside the student directory.
• Code:
!mv student/welcome.txt student/hello.txt

Command19: zip -r

• Description:
Compresses the student directory into a zip file named student.zip.
• Code:
!zip -r student.zip student

Command 20: unzip

• Description:
Extracts the contents of the student.zip file back into the student directory.
• Code:
!unzip student.zip -d extracted_student

Page | 15
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

CONCLUSION:
By executing the above 20 Linux commands on Google Colab, we learned how to interact
with the underlying Linux environment. These commands are essential for managing files,
directories, and system resources in colab or any Linux based system.

Page | 16
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

PRACTICAL NO-03
AIM: Using Divide and Conquer strategies to design a class for Concurrent Quick Sort
using python

Introduction to divide and conquer:

Divide and Conquer Algorithm is a problem-solving technique used to solve problems by


dividing the main problem into subproblems, solving them individually and then merging them
to find solution to the original problem. In this article, we are going to discuss how Divide and
Conquer Algorithm is helpful and how we can use it to solve problems.

Advantage of divide and conquer:

• Efficiency: Divide and conquer algorithms typically have a time complexity of O(n
logn), which is more efficient than many other algorithms for large datasets.

• Simplicity: Divide and conquer algorithms are often easy to understand and
implement.

• Parallelizability: Divide and conquer algorithms can be easily parallelized, as each


subproblem can be solved independently.

• Cache-friendliness: Divide and conquer algorithms tend to have good cache


performance, as they access data in a predictable pattern.

QUICK SORT :

Quick Sort is a divide-and-conquer algorithm that works by selecting a 'pivot' element and
partitioning the array into two sub-arrays, such that:

1. All elements less than the pivot are moved to its left.
2. All elements greater than the pivot are moved to its right.

The process is then recursively applied to the sub-arrays on the left and right of the pivot until
the entire array is sorted.

Page | 17
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

Steps of the Quick Sort Algorithm

1. Choose a Pivot: Select an element from the array. This element is called the "pivot".
There are different strategies for choosing the pivot, such as picking the first element,
last element, middle element, or a random element.

2. Partition the Array: Rearrange the array so that elements smaller than the pivot are on
its left, and elements greater than the pivot are on its right.

3. Recursively Sort Sub-arrays: Apply the same process to the left and right sub-arrays
(ignoring the pivot since it's already in its correct place).

4. Base Case: The recursion terminates when the sub-array has one or zero elements,
meaning it's already sorted.

Python Code Implementation:


#Quick sort Algorithm

def quick_sort(arr):

#Base case: if the array has one or zero elements its already sorted

if len(arr)<=1:

return arr

else:

#Choose a pivot element(we’re using the last element here)

pivot = arr[-1]

left = [x for x in arr[:-1] if x<=pivot] #Elements less than or equal to pivot

right = [x for x in arr[:-1] if x>pivot] #Elements greater than pivot

#Recursively sort the left and right parts , then concatenate the results

return quick_sort(left)+[pivot]+quick_sort(right)

#Test the quick sort function

if__name__== “__main__”:

#Example array

arr = [10,7,8,9,1,5]

Page | 18
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
FACULTY OF ENGINEERING AND TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
ENROLLMENT NO-2203031241422

print(“Original Array:”,arr)

#Apply quick sort

Sorted_arr = quick_sort(arr)

print(“Sorted Array:”,sorted_arr)

OUTPUT:

CONCLUSION:
Quick Sort’s average-case performance and efficiency have made it one of the most popular
sorting algorithms, especially for large datasets. It showcases the power of the Divide and
Conquer strategy, though careful consideration of pivot selection is important to avoid worst
case performance. Other sorting algorithms like Merge Sort or Heap Sort offer alternative
advantages, but Quick Sort continues to be a go-to solution for its combination of speed and
elegance in practical scenarios.

Page | 19

You might also like