Jump to content

Ediția 10 de Miss&Mister B-Zone a început. Aplicați aici

Recrutăm designeri audio și video. Aplicați aici


  • Content Count

  • Joined

  • Last visited

Community Reputation

86 Impressive

About Azain

  • Rank
    ★ Former Admin 3 RPG4 ★
  • Birthday 10/02/2000

Profile Information

  • Gender
  • Location
  • Hobbies
    Gaming & Coding

Previous Fields

  • Real name
    Azain Ayub
  • RPG1 Nickname
  • RPG2 Nickname

Contact Methods

  • Steam ID

Recent Profile Visitors

2028 profile views
  1. Nick: AzaiN Rank: 1 From what are you missing(meeting/training/activities/war): war Date: 23/02/2021 Reason: not at home Number of requests from this week: this is 2nd Other specifications: na
  2. Nick: AzaiN Rank: 1 From what are you missing(meeting/training/activities/war): war Date: 22/02/2021 Reason: Not at home Number of requests from this week: 1 Other specifications: Good luck for war!
  3. Azain

    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
  4. Nick: AzaiN Rank: 5 Mă învoiesc de la: War Data activităţii: 12.01.2021 Motivul: im busy A câta învoire pe această săptămână este?: 2/2 Alte precizări: - good luck
  5. Nick: AzaiN Rank: 5 Mă învoiesc de la: War Data activităţii: 11.01.2021 Motivul: I'm not at home A câta învoire pe această săptămână este?: 1/2 Alte precizări: bafta
  6. Azain

    In this Tutorial, I will show you how to perform Linear Search on an Array in Java, I assume that you know the basics of programming and Java language. What is Linear Search? In computer science, a linear search or sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched. Wikipedia Why Linear Search? Linear search is usually very simple to implement, and is practical when the list has only a few elements, or when performing a single search in an un-ordered list. When many values have to be searched in the same list, it often pays to pre-process the list in order to use a faster method. For example, one may sort the list and use binary search, or build an efficient search data structure from it. Should the content of the list change frequently, repeated re-organization may be more trouble than it is worth. As a result, even though in theory other search algorithms may be faster than linear search (for instance binary search), in practice even on medium-sized arrays (around 100 items or less) it might be infeasible to use anything else. On larger arrays, it only makes sense to use other, faster search methods if the data is large enough, because the initial time to prepare (sort) the data is comparable to many linear searches. Wikipedia How to do Linear Search? To do Linear Search on an array, we have to traverse through each element until we have found the element, we were searching for. 1. We'll create a method that takes an integer array and a key as input public static int linearSearch(int arr[], int key) { } 2. Declare two variables, one for storing the index and other for storing the length of the array //In Java, you can get length of an array by typing .length after the name of array int index, length = arr.length; 3. To traverse through each element of the array, we will use a for loop, initialize the index to 0 and keep incrementing by 1, inside the the loop there is a condition if indexth element of array is equal to the key then we'll return the index, otherwise if we have traversed through each element and have not found the key then we'll return -1; for (index = 0; index < arr.length; index++) { if (arr[index] == key) { return index; } } return -1; That's how you can do linear search on an array, following is the full code package com.azain.algorithms; /** * * @author Azain */ public class Search { //Linear Search public static int linearSearch(int arr[], int key) { int index, length = arr.length; for (index = 0; index < arr.length; index++) { if (arr[index] == key) { return index; } } return -1; } }
  7. Nick: AzaiN Rank:4 Mă învoiesc de la: War Data activităţii: 05.01.2021 Motivul: Im not feeling well A câta învoire pe această săptămână este?:1/2 Alte precizări: Succes
  8. Azain

    @Tupi For SFPlugins?
  9. Descriere problema: The problem is that I want to get documentation of SAMPFUNCS and I searched a lot on internet but couldn't found except some few things Poze / Video (optional): null Cod (sursa pe baza caruia sa ajutam, daca e cazul): null Alte precizări: null

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.