Jump to content

Azain

Member
  • Posts

    894
  • Joined

  • Last visited

About Azain

  • Birthday October 2

Profile Information

  • Gender
    Male
  • Location
    Rawalpindi, Pakistan
  • Hobbies
    Videos Games, Reading History, & Programming

Previous Fields

  • Real name
    Azain Ayub
  • RPG1 Nickname
    AzaiN

Contact Methods

  • Steam ID
    azain69
  • Discord
    azain
  • Instagram
    azainayub

Recent Profile Visitors

2717 profile views

Azain's Achievements

Rising Star

Rising Star (9/14)

  • 15 Posts
  • 300 Posts Rare
  • 100 Posts
  • First Post
  • 2 Consecutive Logs

Recent Badges

89

Reputation

  1. Nick-name: AzaiN Rank: 2 Invoire pentru war-ul din data: 02.05.2022 Motivul pentru care nu pot veni la war: I have a match in another game Numarul invoirii din aceasta saptamana (x/2): 1/2 Alte precizari: - Good luck at war!
  2. Nick-name: AzaiN Rank: 1 Invoire pentru war-ul din data: 29.04.2022 Motivul pentru care nu pot veni la war: Not at home Numarul invoirii din aceasta saptamana (x/2): 1/2 Alte precizari: Good luck!
  3. Nick: AzaiN Rank: 2 Data warurilor la care nu poți ajunge: 5.11.2021 Numarul de invoiri pe aceasta saptamana: 1/2 Motivul învoirii: Not at home
  4. Nick: AzaiN Rank: 1 Data warurilor la care nu poți ajunge: 1.11.2021 Numarul de invoiri pe aceasta saptamana: 1/2 Motivul învoirii: Not at home Alte precizări: -
  5. Nick: AzaiN Rank: 1 Data warurilor la care nu poți ajunge: 26.10.2021 Numarul de invoiri pe aceasta saptamana: 1/2 Motivul învoirii: I have some important work to do Alte precizări: - Good luck!
  6. Azain

    Nick: AzaiNRank: 1 Data activitatii: September 07, 2021 Alte precizari: https://imgur.com/a/9jekl0S
  7. Nick-name: AzaiN Rank: 1 Invoire pentru war-ul din data: 09/06/2021 Motivul pentru care nu pot veni la war: Not at home Numarul invoirii din aceasta saptamana (x/2): 2/2 Alte precizari: na
  8. Nick-name: AzaiN Rank: 1 Invoire pentru war-ul din data: 07.06.2021 Motivul pentru care nu pot veni la war: Not at home Numarul invoirii din aceasta saptamana (x/2): 1 Alte precizari: - na
  9. Nick-name: AzaiN Rank: 1 Invoire pentru war-ul din data: 04.06.2021 Motivul pentru care nu pot veni la war: I have some work to do Numarul invoirii din aceasta saptamana (x/2): 1/2 Alte precizari: Good Luck!
  10. Nick: AzaiN Rank: 2 Data warurilor la care nu poți ajunge: 25.05.2021 Numarul de invoiri pe aceasta saptamana: 1 Motivul învoirii: not at home Alte precizări: bafta!
  11. 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
  12. 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; } }
  13. Azain

    @Tupi For SFPlugins?
×
×
  • 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.