Question: Hello everyone we were asked to make a project that compares 3 algorithms to each other using 3 diff data structures and ours is naive
Hello everyone
we were asked to make a project that compares 3 algorithms to each other using 3 diff data structures and ours is naive algorithm
we are supposed to read a csv file about covid data and then use that data in our algorithm this is the data we are using for comparison:
https://data.mendeley.com/datasets/b7zcgmmwx4/2
(download the pcr data )
we are supposed to save that data in 3 data structures and we chose list, tuple, and set but we dont know how to save the data in them so we are hoping that you can help us
also we tried saving it into a list but it saved a whole row into an index in that list so we couldnt iterate through the rows themselves and figure out a match
Thank you.
code:
import pandas as pd import time
path = r"C:\Users\PC\Desktop\RT-PCR\pcr_data.csv"
# Read the CSV file into a DataFrame df = pd.read_csv(path) df = df.astype(str)
# Join all the elements in each row with no separator df["joined_row"] = df.apply(lambda row: ''.join(row), axis=1)
#********************************************************************** #print(list(df["joined_row"])) #print(tuple(df["joined_row"])) #print(set(df["joined_row"])) #print(list(df.loc[1])) #**********************************************************************
# Python3 program for Naive Pattern # Searching algorithm #----------------------------------------------------------------------
def naive(s, target): M = len(target) N = len(s) # A loop to slide pat[] one by one */ for i in range(N - M + 1): j = 0 # For current index i, check # for pattern match */ while(j < M): if (s[i + j] != target[j]): break j += 1 if (j == M): print("Pattern found at index ", i) #----------------------------------------------------------------------
# Define the target string target = "1110111"
# Initialize a variable to store the result result = -1
# start time start=time.perf_counter()
# Iterate through the joined_row column of the DataFrame for i, s in enumerate(list(df["joined_row"])): # Compare the current string to the target string col = naive(s, target) if col != -1: # If a match is found, store the index in the result variable result = i break
# Print the result if result != -1: print("Match found at index", result,"at col",col) else: print("No match found.")
# end time end=time.perf_counter() print("Time Complixity is") print(end-start)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
