المشاركات

عرض الرسائل ذات التصنيف Searching Algorithms with javascript

Searching Algorithms with javascript

Searching Algorithms Linear Search it finds what we are searching for by brute force, making it easy to implement. we will use three different ways in javascript. first way : search with includes method. *example: Array.includes("something"); *includes method will return True or False. second way : search with indexOf method. *example: Array.indexOf("something"); *indexOf method will return number 'the index of the something' third way : search with Find method. *example: Array.find(item => item === "something"); *we write in this method a function and it will return something we search about. Binary Search Binary search only works on sorted arrays.O(log n) 'big o notation'. Example : [1,2,3,4,5,6,7,8,9,10] for example if we search for number 7 we have in this array three things the first thing is the left = 1 and second thing is a right = 10 and last thing is a mid = 5 so we will check the ...