Question

In: Computer Science

CSCI4520Programing Project for algorithm analysis: Sorting, searching, and efficiency analysis Project introduction In the project, you...

CSCI4520Programing Project for algorithm analysis: Sorting, searching, and efficiency analysis

Project introduction In the project, you will apply the theory in the class to actual computer simulation to verify your results. Project Description You will simulate the procedure of search, sorting by programming and analyze the efficiency based on the computer simulation and theoretical result.

1.Generate 100000positive numbers between (0,150)

2.Search the position of the first “58”in the array

3.Count how many “58”inthe array

4.After you finished the first three steps,sort the array by the one required algorithm.

5.Repeat step 3 on the sorted array

6.Compute the time cost difference between the time from step 3 only, and time from step 4 and 5 together.

7.Run your program three times and calculate the time:

1)The time to generate 100000#

2)The time to search the element 58s

3)The time to count the 58’s

4)The time to sort the array

Project Learning Objectives • Students will be knowledgeable of the concepts and techniques of computation • Develop code and understanding software life cycle. • Familiar with algorithm efficiency analysis Computer Programming Learning Objectives Students will enhance knowledge in following areas: • Arrays (Bounded) • Algorithm design • Data structure • Interface design • Graphic user interface design Learning Objectives • Upon the successful completion of the project, the students will gain a better understanding of following course concepts • The efficiency analysis of algorithms • The student will enhance the knowledge and skills in writing a well-documented Java program with object oriented concepts involved Program structure The program should include the following sections: • Algorithms design: Describe the algorithm in pseudocode• Implementation of the algorithm: The code to realize the algorithms• The efficiency analysis of the algorithm: The time and space efficiency

Solutions

Expert Solution

import random
import time

def program(print_result=True):
        # ============== Generate numbers =========================
        numbers = [] #array to store the numbers
        
        # clock for generating numbers
        # start the clock....
        start1 = time.time()

        for _ in range(100000):
            numbers.append(random.randint(0, 150))
        
        end1 = time.time()   
        # end the clock 

        
        if print_result:
                print("Step1: First 20 numbers: ", numbers[:20])

        
        # Function to find Position of first 58 in array
        def find58(numbers):
            for index, num in enumerate(numbers):
                if num is 58:
                        return index

        # clock for searching....
        start2 = time.time()
        if print_result:
                print("Step2: Position of 58 is:", find58(numbers))
        end2 = time.time()



        # Function to Count numbers of 58:
        def count58(numbers):
            count = 0
            for num in numbers:
                if num is 58:
                    count += 1
                    
            return count

        if print_result:
                print("Step3: Total count of occurences of 58:", count58(numbers))


        # clock for counting the occurences of 58
        start3 = time.time()
        count58(numbers)
        end3 = time.time()


        # clock for sorting and counting
        start45 = time.time()
        
        # clock for sorting
        start4 = time.time()
        numbers.sort()
        end4 = time.time()
        # end clock for sorting  
        
        if print_result:
                print("Step5: count of 58 after sorting:", count58(numbers))
        end45 = time.time()
        # end clock for counting


        if print_result:
                print("Step6:")
                print("Runtime of step3",end3-start3)
                print("Combined runtime of step 4 and 5", end45-start45)
                if(end3-start3 > end45-start45):
                        print("step3 is faster")
                else:
                        print("step 4 and 5 is faster")

        return end1-start1, end2-start2, end3-start3, end4-start4


# Covers step1-step6
program()



print()
print("Step7")
# Running program for 3 times without printing results of step1-step6
for i in range(3):
        print("Iteration", i+1)
        time_generate, time_search, time_count, time_sort = program(print_result=False)
        print("Time to generate", time_generate)
        print("Time to search", time_search)
        print("Time to count", time_count)
        print("Time to sort", time_sort)
        print()

Screeshot of program:

Sample run:


Related Solutions

Please find and share one sorting/searching algorithm. Explain it, and discuss its efficiency with your friends!
Please find and share one sorting/searching algorithm. Explain it, and discuss its efficiency with your friends!
1) Please find and share one sorting/searching algorithm. Explain it, and discuss its efficiency 2) Please...
1) Please find and share one sorting/searching algorithm. Explain it, and discuss its efficiency 2) Please find and share algorithm about red/black trees. Explain it, give 2 real world usages and discuss its efficiency 3) Please find and share one algorithm about Binary Search Trees. Explain it, and discuss it's efficiency
Purpose This project is meant to give you experience with sorting, binary searching, and Big-Oh complexity....
Purpose This project is meant to give you experience with sorting, binary searching, and Big-Oh complexity. Objective "Write in Java please" Your goal is to take a book, as a large text file, and build a digital “concordance”. A concordance is like an index for a book in that it contains entries for words in the book, but it also includes passages from the book containing that word. For example, a query for the word Dormouse in Alice in Wonderland...
1.) (a) There exists a very popular sorting algorithm called Timsort, the default sorting algorithm in...
1.) (a) There exists a very popular sorting algorithm called Timsort, the default sorting algorithm in both Python and Java. This sort is a combination of two different sorting algorithms: Merge sort, and Insertion sort. Recall that the Big-O of Merge sort is O(nlogn) and the Big-O of Insertion sort is O(n 2 ). What advantage would Timsort have to combine the two algorithms if merge-sort has a better Big-O metric? (b) Consider two algorithms: f(n) and g(n). You run...
This is on python. 26.1 Lab 6 - Sorting and Runtime Analysis Introduction In this lab,...
This is on python. 26.1 Lab 6 - Sorting and Runtime Analysis Introduction In this lab, we will explore sorting algorithms and perform a practical analysis of algorithm runtimes. In lecture, we have introduced algorithm - or asymptotic - analysis. In theoretical analysis, we care about the behavior of our algorithms out at the asymptotes. Or in other words, as the problem sizes get larger and larger, what functions can we use to bound algorithmic runtime? Does an algorithm's runtime...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm being used) Requirements Choose one problem with an algorithm and implement it. You should show and explain the result whatever you got. I recommend using N-Queen problem (at least N=8 or more) or any simple perfect games. For example, - N-Queen problem with hill climbing - N-Queen problem with simulated annealing - N-Queen problem with genetic algorithm - Tic-Tac-Toe with Minimax
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm being used) N-Queen problem with genetic algorithm Please use the N-Queen problem (at least N=8 or more) or any simple perfect games. Please provide a screenshot of output and please heavily comment the code. Thanks!
Which Sorting algorithm are in place algorithm and which are not? Is it advantageous to design...
Which Sorting algorithm are in place algorithm and which are not? Is it advantageous to design in place sorting algorithm? How this in place term is related to the time complexity and space complexity of the program?
You are working as the software developer and need to identify the best sorting algorithm. You...
You are working as the software developer and need to identify the best sorting algorithm. You can pick any two-sorting algorithm. You need to determine which sorting algorithm is the best to sort the array of 10k elements. Use the following steps to help with your solution: Create C++ functions for any two-sorting algorithm. Write down the random array generation function to generate at least 10k elements. Pass the same array into both the sorting algorithm. Calculate the end transactiontime-start...
Recall the definition of stable sorting: a sorting algorithm is said to be stable when elements...
Recall the definition of stable sorting: a sorting algorithm is said to be stable when elements with equal keys (after the sorting is complete) remain in the same order as they were in the input (before the sorting). Answer the following: Is Radix Sort stable, and why? Show an example: start from 10 random integer numbers (of at least 2 digits per integer number) to be sorted, where at least 2 of those 10 elements need to have equal keys;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT