Jump to content

Search the Community

Showing results for tags 'binary search'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • B-Zone
    • Announcements
    • B-Zone Clips
    • Community
    • Forum Suggestions
    • Market
    • Questions and Answers
  • San Andreas Multiplayer
    • RPG.B-Zone.Ro:7777 Roleplay
    • Wiki Website
  • Rage Multiplayer
    • V.B-ZONE.RO
  • B-Zone Online
    • B-Zone Championships
    • B-Zone Clans & Clubs
    • B-Zone Radios
    • Counter-Strike 1.6
    • Discord
    • Metin2
    • Minecraft
  • IT Zone
    • Design
    • Gadgets
    • Programming
    • Software & Hardware
    • Video Games
  • Real life
    • Entertainment
    • History
    • Juridic
    • Lifestyle
    • Politics
    • Sport
    • Vehicles
  • Trash Can
    • Trash Can
  • The Last Generation [TLG]'s The Last Generation
  • Very Important Person [VIP]'s [VIP] - Topic
  • zero Limits [zL]'s Topics
  • Sons of Anarchy MC [SoA]'s Club Matters
  • Unheard Spirits [END]'s Topics
  • The First Generation [TFG]'s General
  • United Blood Nation [UBN]'s DSICUTII LIBERE MEMBRII!
  • Wild Balkans [WB]'s Informatii
  • True Silent Aimbot [TSA]'s Topics
  • Alliance [A]'s General
  • Merry Weather [MW]'s Prezenta activitati
  • Merry Weather [MW]'s Anunturi Importante
  • Merry Weather [MW]'s Giveaway
  • Merry Weather [MW]'s Giveaway
  • Dangerous Life [dL]'s General
  • Elite Squad [eS]'s Discord
  • InLineSIX [L6]'s Topicurile Clanului # Clan Topics
  • InLineSIX [L6]'s InLineSIX [L6] # Regulament / Rules
  • InLineSIX [L6]'s InLineSIX [L6] # Sistem Promovare / Rank-UP
  • Hunters [H]'s Regulament
  • The Royal Family [RF]'s The Royal Family [RF]
  • Royal Shadows [RS]'s Rank up % Salarii

Calendars

  • Community Calendar
  • Merry Weather [MW]'s Events

Product Groups

There are no results to display.

Categories

  • MODURI
    • CLEO/SAMPFUNCS
    • Vehicles
    • Skins
    • Sounds
    • Effects
    • Weapons
    • Others
    • Modpacks
  • True Silent Aimbot [TSA]'s Files
  • Merry Weather [MW]'s Event

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Skype


Steam ID


Discord


Instagram


Location


Hobbies


Real name


RPG Nickname

Found 2 results

  1. Binary Search What is Binary Search? In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array. If they are not equal, the half in which the target cannot lie is eliminated and the search continues on the remaining half, again taking the middle element to compare to the target value, and repeating this until the target value is found. If the search ends with the remaining half being empty, the target is not in the array. Binary search runs in logarithmic time in the worst case, making O(log n) comparisons, where n is the number of elements in the array. Binary search is faster than linear search except for small arrays. However, the array must be sorted first to be able to apply binary search. There are specialized data structures designed for fast searching, such as hash tables, that can be searched more efficiently than binary search. However, binary search can be used to solve a wider range of problems, such as finding the next-smallest or next-largest element in the array relative to the target even if it is absent from the array. How to do Binary Search? Given an array A of n elements with values sorted such that A{0} <= A{1} <= A{2} <= ..... A{n-1} and target value T, the following subroutine uses binary search to find the index of T in A. Set L to 0 and R to n-1. If L > R, the search terminates as unsuccessful. Set m (the position of the middle element) to the floor of L + R / 2 , which is the greatest integer less than or equal to L + R / 2. If A[m] < T, set L to m+1 and go to step 2. If A[m] > T, set R to m-1 and go to step 2. Now A[m] = T, the search is done; return m. Code: package binarysearch; /** * * @author Azain */ public class BinarySearch { /* Recursive method to do binary search on an array, takes an integer array left index, right index and key to find as arguments, array should be sorted otherwise result will not be accurate */ public static int binarySearch(int arr[], int left, int right, int key) { //continue searching for the key until right index is greater then left index if (right >= left) { //middle index of left and right index int mid = left + (right - left) / 2; //Base case, if array middle element is equal to key, the index is returned if (arr[mid] == key) return mid; //when the middle element is greater than the key, search the left if (arr[mid] > key) return binarySearch(arr, left, mid - 1, key); //when the middle element is less than the key, search the right return binarySearch(arr, mid + 1, right, key); } //returning -1, when the key is not found in the array return -1; } public static void main(String[] args) { int arr[] = {1, 2 , 3 , 4, 5, 6, 7, 8 , 9}; int key = 7; int result = binarySearch(arr, 0, arr.length - 1, key); //if key is found if (result == -1) System.out.println(key + " not found!"); else System.out.println(key + " found at index " + result); } } Sources: https://en.wikipedia.org/wiki/Binary_search_algorithm
  2. Cautare binara - Varianta clasica #include <iostream> #include <algorithm> using namespace std; int N, x; struct element { int val, ord; } V[100]; int bin_search(int b, int e, int x); bool cmp(element a, element b) { return a.val < b.val; } int main() { cout << "N = ";cin >> N; for(int i = 1; i <= N; ++i) { cout << "V[" << i << "] = ";cin >> V[i].val; V[i].ord = i; } sort(V + 1, V + 1 + N, cmp); cout << "x = ";cin >> x; cout << V[bin_search(1, N, x)].ord << '\n'; return 0; } int bin_search(int b, int e, int x) { if(b > e) { return 0; } int mij = (b + e) / 2; if(V[mij].val > x) { return bin_search(b, mij - 1, x); } else { if(V[mij].val < x) { return bin_search(mij + 1, e, x); } else { return mij; } } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.