Finding maximum element in an array - is it that you will call greedy algorithm or brute force algorithm or both? -
suppose array of integers given:
{1,3,2,4,6,5,2} - max: 6
using brute force, finding maximum element in observe every element (each element candidate solution), searching entire search space.
considering greedy approach, modify maximum element @ each element of array if necessary. local optimal choice lead global optimal choice.
are brute force , greedy approach similar here? exacty difference between 2 algos in general?
approach:
brute force - starting first element - 1 taking max. considering each , every next element in array - entire search space. choosing maximum @ each step if necessary. brute force.
greedy algorithm - starting nothing, taking first element - taking max 1. considering second element - 3, making local optimal choice between 1 , 3- taking 3 maximum. , on other elements. @ last, have 6 maximum element- global optimal choice.
how tell difference between 2 algos in general?
finding maximum element in unsorted array require brute-force approach.
there ways of minimizing complexity of operation using data-structures such heaps, sort data being added structure.
Comments
Post a Comment