Data structure(Searching linear and binary)

Linear search :-इस Search सर्च में element को एक-एक करके search किया जाता है और जहां element  मिल जाता है search complete.
(Compare element one by one)
Time taking 
  •     Best Case = O(1)
  •     Average Case = O (n)
  •     Worst Case Complexity O(n)
Assume Find K = 41 



Program

# Linear Search in Python


def linearSearch(array, n, x):

    # Going through array sequencially
    for i in range(0, n):
        if (array[i] == x):
            return i
    return -1


array = [2, 4, 0, 1, 9]
x = 1
n = len(array)
result = linearSearch(array, n, x)
if(result == -1):
    print("Element not found")
else:
    print("Element found at index: ", result)
Binary seach :-( Worked with sorted Array)
हमारे पास elements (a+b/2)  को Check किया जाता है और उसके हिसाब से Half parts  को eleminate कर दिया जाता है और आगे के Parts  को ऐसे ही तरीके से सर्च किया जाता है.



Program for Binary Search by iteration and recursion method


Selection sort :- Selection सिलेक्शन Sort में सबसे पहला सबसे छोटा आइटम सर्च किया जाता है और उस छोटे आइटम को swap कर दिया जाता है first एलिमेंट से इसी प्रकार से 2nd smallest element एलिमेंट फिर 3,4 so on. और ऐसे करके elements को सही पोजीशन पर लगाया जाता है

Step 0


Step 1


Step 2


Step 3


Program for Selection sort
Bubble sort :- swap to nex element. (link for example and programs )

Insertion sort :- select any element and sorted fully (sort like 2elemt . 3 elements >..)

Comments

Popular posts from this blog

Jonita Gandhi

Current Affair 2023

Cyber Security (Syllabus )