thane-mccullough
Uploaded by
7 SLIDES
213 VUES
70LIKES

Algorithm Time Analysis Examples

DESCRIPTION

This document presents examples of linear search algorithms and substring finding techniques, highlighting their implementations in Java. It dives into the functionalities of search and removal operations in data structures, examining the time complexity of linear searches and providing potential improvements. Additionally, it explores the challenges of removing elements from lists and suggests efficient solutions. Key algorithmic concepts like boolean searches, handling null inputs, and pattern matching string searches are discussed thoroughly to enhance understanding of algorithm performance.

1 / 7

Télécharger la présentation

Algorithm Time Analysis Examples

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithm Time Analysis Examples Salim Malakouti

  2. Linear Search • public int count(int[] array, int item) { • for (inti = 0; i < array.length; i++) { • if (array[i] == item) • returntrue; • } • returncount; • }

  3. Remove from the list? • public void remove(ArrayList<Integer> list,Integer item){ • for (int i = 0; i < list.size(); i++) { • if(list.get(i).equals(item)){ • list.remove(i); • } • } • }

  4. Removing from a list What is a better solution? What is its time complexity?

  5. Finding A substring • String source = “I hope you are not tired. home” • String pattern = “home” • Exists? • What is the algorithm?

  6. Finding sub pattern • public booleanfindSubString(String source, String pattern){ • if(pattern==null||source==null) • return false; • if(pattern.length()==0||source.length()==0) • return false; • for (inti = 0; i < source.length(); i++) { • if(source.charAt(i)==pattern.charAt(i)){ • boolean t=true; • for (int j = i; j < pattern.length(); j++) { • if(source.charAt(j)!=pattern.charAt(j-i)){ • t=false; • break; • } • } • if(t) • return true; • } • } • return false; • }

  7. Boolean search

More Related