Java Interview Guide: How to Build Confidence With a Solid Understanding of Core Java Principles pdfdrive com



Yüklə 0,53 Mb.
Pdf görüntüsü
səhifə25/47
tarix06.05.2023
ölçüsü0,53 Mb.
#108601
1   ...   21   22   23   24   25   26   27   28   ...   47
Java Interview Guide

Algorithms
Big O Notation
Big O notation measures the complexity of an operation relative to the size
of its input.
O(1)
describes an algorithm whose complexity is independent of the input,
such as accessing an element in an array by its index.
O(n)
describes an algorithm whose complexity increases linearly, such as
iterating through an array.
O(n^2)
describes an algorithm whose complexity increases quadratically,
such as comparing every element in an array to every other element in an array.
O(log n)
describes an algorithm whose complexity increases logarithmically,
such as dividing an array in half until only one element remains.
O(n log n)
describes an algorithm whose complexity increases
linearithmically, such as dividing an array in half and iterating through each half.


Binary Search
Binary search is an O(log n) algorithm that is used to find a value in a sorted
list of items. It works by searching for a value in the middle of a list,
and recursively discarding whichever half of the list is out of range. The result
of a binary search is undetermined if the list is unsorted. Binary search
is available in the Arrays and Collections classes.


Insertion Sort
Insertion sort is an O(n^2) average-case sorting algorithm. It works
by traversing through a list and sorting the previous elements by swapping them
in place. Insertion sort is a stable algorithm, which means equal values will
maintain their relative order. Insertion sort performs well for small data sets
despite its complexity because it’s efficient for partially sorted lists and
it requires no extra memory.



Yüklə 0,53 Mb.

Dostları ilə paylaş:
1   ...   21   22   23   24   25   26   27   28   ...   47




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin