Answer to Question #266209 in Python for Isabel Cortez

Question #266209

Create a program using the following features:

* Array

* Class

* Specific Sorting Algorithm

* Specific Searching Algorithm


What is "Specific Sorting Algorithm" and "Specific Searching Algorithm"?

* sorting code that uses a specific sorting process, here is the list of sorting algorithms that you will use

Bubble

Selection

Insertion

Merge

Shell

* searching code that uses a specific searching process, here is the list of searching algorithms that you will use

Linear

Binary

Fibonacci

Jump


1
Expert's answer
2021-11-15T17:29:55-0500
#demonstrating bubble sort
def bubble(array):
    number = len(array)
    for x in range(number):
        sortedE = True
        for m in range(number - x - 1):
            if array[m] > array[m + 1]:
                array[m], array[m + 1] = array[m + 1], array[m]
                sortedE = False
        if sortedE:
            break
    return array
#demonstrating insertion sort
def insertion(array):
    for x in range(1, len(array)):
        element = array[x]
        m = x - 1
        while m >= 0 and array[m] > element:
            array[m + 1] = array[m]
            m -= 1
        array[m + 1] = element


    return array
def mergeI(array):
    if len(array) < 2:
        return array


    center = len(array) // 2
    return merge(
        left=mergeI(array[:center]),
        right=mergeI(array[center:]))


def linear(values, SFor):
   SAt = 0
   Sres = False   
   while SAt < len(values) and Sres is False:
      if values[SAt] == SFor:
         Sres = True
      else:
         SAt = SAt + 1
   return Sres
l = [54, 24, 15, 2, 12, 1, 80]
print(linear(l, 2))
print(linear(l, 81))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS