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

Assignment 3-2

Uploaded by

142414003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Assignment 3-2

Uploaded by

142414003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DS5003 Data Engineering Lab

Assignment-3, Date: Aug 16, 2024


Timing: 2:00 to 4:45 PM Max Marks: 5

Instructions

1. Submit one .ipynb file containing all answers. The name should be
[student name]_assignment3.ipynb
2. Write questions in separate text blocks in Jupyter Notebook before the code blocks containing
answers.
3. Read the questions carefully before answering. It must be followed if a question asks to follow a
particular approach or use a specific data structure.

4. All questions need to be answered using sorting or searching methods.

1. Write a Python program that takes a list of integers and a list of target integers as input from

the user. Use linear search to find all occurrences of each target integer in the list. The program

should return a dictionary where the keys are the target integers and the values are lists of

indices where each target is found.

Input: main list = [4, 2, 7, 4, 8, 2, 5, 7, 4]

target list= [4, 7, 2]

Output: {4: [0, 3, 8], 7: [2, 7], 2: [1, 5]} 0.5

2. Implement the binary search algorithm to find the index of the target integer in the list.

a. Print whether the target is found and its index or a message if it’s not found.

b. Modify the above binary search function to find the closest value to a target integer in a

sorted list. Print the closest value and its index. 0.5

3. Write a program that receives an input array of distinct numbers in the range [1, n] and outputs

the single number in the range that is absent from the array.

Input: count = 5, Array = {4,3,1,5}, Output: 2 1

4. Write a program to do a binary search in a 2D List 1

5. Write a program that sorts a list of integers using bubble sort with an optimization that exits

early if no swaps are made during a pass. Print the number of passes made before sorting is

complete. 0.5
6. Implement a program that inputs a list of integers and an integer k. Use bubble sort to sort the

list and then find and print the kth largest element. Handle the case where k is greater than the

length of the list. 0.5

7. Given a semi-sorted array, find out how many elements need to change their position to make

sure the array is fully sorted. (Note: Use Insertion Sort)

Input : [1,1,4,2,1,3], Output: 3 (4,1,3 are not in place) 1

You might also like