Data Structures and Algorithms

Slides:



Advertisements
Similar presentations
Data Structures Using C++ 2E
Advertisements

Searching Kruse and Ryba Ch and 9.6. Problem: Search We are given a list of records. Each record has an associated key. Give efficient algorithm.
1 Hashing (Walls & Mirrors - end of Chapter 12). 2 I hate quotations. Tell me what you know. – Ralph Waldo Emerson.
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (excerpts) Advanced Implementation of Tables CS102 Sections 51 and 52 Marc Smith and.
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
IT 60101: Lecture #151 Foundation of Computing Systems Lecture 15 Searching Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (continued) Advanced Implementation of Tables.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
Starting at Binary Trees
Hashing 8 April Example Consider a situation where we want to make a list of records for students currently doing the BSU CS degree, with each.
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
Chapter 13 C Advanced Implementations of Tables – Hash Tables.
CISC220 Fall 2009 James Atlas Dec 07: Final Exam Review.
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
Prof. Amr Goneid, AUC1 CSCI 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 5. Dictionaries(2): Hash Tables.
DS.H.1 Hashing Chapter 5 Overview The General Idea Hash Functions Separate Chaining Open Addressing Rehashing Extendible Hashing Application Example: Geometric.
Algorithm Efficiency and Sorting
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
COMP261 Lecture 23 B Trees.
Data Structure By Amee Trivedi.
Data Structures and Algorithms
Top 50 Data Structures Interview Questions
Data Structures Using C++ 2E
Multiway Search Trees Data may not fit into main memory
Searching – Linear and Binary Searches
CSCI 210 Data Structures and Algorithms
Data Abstraction & Problem Solving with C++
Data Structures and Algorithms
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Data Structures and Algorithms
CS 332: Algorithms Hash Tables David Luebke /19/2018.
Sorting by Tammy Bailey
Database Management Systems (CS 564)
Data Structures Using C++ 2E
Hashing Exercises.
Cse 373 April 26th – Exam Review.
November 1st – Exam Review
Advanced Associative Structures
Searching.
Complexity Present sorting methods. Binary search. Other measures.
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Data Structures and Algorithms
Data structures and algorithms
Searching CLRS, Sections 9.1 – 9.3.
PAC Intro to “big o” Lists Professor: Evan Korth New York University
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
B-Trees CSE 373 Data Structures CSE AU B-Trees.
File Processing : Index and Hash
CS202 - Fundamental Structures of Computer Science II
Advanced Implementation of Tables
Database Design and Programming
Data Structures and Algorithms
Advanced Implementation of Tables
CSE 373, Copyright S. Tanimoto, 2002 B-Trees -
CPS216: Advanced Database Systems
Algorithm Efficiency and Sorting
Analysis of Algorithms
DATA STRUCTURE.
B-Trees CSE 373 Data Structures CSE AU B-Trees.
Data Structures and Algorithms
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
B-Trees.
Lecture-Hashing.
Presentation transcript:

Data Structures and Algorithms PLSD210 Key Points

Lectures 1 & 2 Data Structures and Algorithms The key to your professional reputation A much more dramatic effect can be made on the performance of a program by changing to a better algorithm than by hacking converting to assembler Buy a text for long-term reference! Professional software engineers have algorithms text(s) on their shelves Hackers have user manuals for the latest software package Which they’ll have to throw away next year anyway!

Lecture 2 Most algorithms operate on data collections, so define Collection Abstract Data Type (ADT) Methods Constructor / Destructor Add / Delete Find Sort (later) ….

Lecture 2 Array implementation Add method Find method Specify maximum size in Constructor Allocate array with sufficient space Add method Takes constant time Independent of current size of collection Find method Linear search Worst case time: n x constant Average time: n/2 x constant (if the key is always found!) è n x constant (depending on probability of finding the key) Worst case analysis preferred - easier and more relevant!

Searching Find method n < Binary search Sort the data into ascending (or descending) order Check the middle item If desired key is less, go left If match, finished! If desired key is greater, go right You can divide n in half: log2n times Therefore binary search takes time = c log2n In “big Oh”, this is O( log n ) n n 8 n 4 n 2 <

Binary Search vs Sequential Search Find method Sequential Worst case time: c1 n Binary search Worst case time: c2 log2n Small problems - we’re not interested! n Large problems - we’re interested in this gap! 4log2n Binary search More complex Higher constant factor

Binary Search vs Sequential Search Logs Base 2 is by far the most common in this course. Assume base 2 unless otherwise noted! Find method Sequential Worst case time: c1 n Binary search Worst case time: c2 log2n Small problems - we’re not interested! n Large problems - we’re interested in this gap! 4log2n Binary search More complex Higher constant factor

Lecture 3 - Key Points Linked Lists Dynamic allocation gives flexibility Use as much or as little space as needed Addition - constant time Searching - proportional to n Deletion - proportional to n Constant in doubly linked if given node Variants LIFO (simplest) FIFO (add tail pointer) Doubly linked Scan in either direction Circularly linked Scan entire list from any point

Lecture 4 - Key Points Stacks Recursion Just a collection with LIFO semantics Add, Delete usually named push, pop Recursion Stack frame to store function context Permits recursive calls Basis for some simple, elegant and efficient solutions! but, sometimes too simple Fibonacci - elegant but not efficient (explanation to come!)

Lecture 4 - Key Points Searching Trees O(logn) search time Binary search - but addition is expensive Trees Recursive Data Structure Sub-trees are themselves trees Searched recursively Search time proportional to height, O(logn)

Lecture 10 - Key Points The Sorting Repertoire Insertion O(n2) Guaranteed Bubble O(n2) Guaranteed Heap O(n log n) Guaranteed Quick O(n log n) Most of the time! O(n2) Bin O(n) Keys in small range O(n+m) Radix O(n) Bounded keys/duplicates O(nlog n) Bin and Radix sort Distinguished by ability to map the key to a small integer or calculate an address from the key Compare only capability -> O(n log n) Pathological case

Lecture 10 - Key Points Radix Sort Any suitable radix can be used Different bases can be used in each phase Memory management must be efficient to achieve O(n)

Lecture 13 - Key Points m-way trees Major use: databases m adjusted so that a node fits in a physical disc block Searching - O( log n ) B-trees m-way tree in which each node is at least half-full B+-trees No data in nodes Leaf nodes Contain pointers to data Linked together to enable fast in-order traversal of tree Insertion Split full nodes, promote a key if necessary

Lecture 13 - Key Points Hash Tables If we can derive an address from a key directly O(1) searching Constraints Limited range - table has to fit in memory Keys dense in range - otherwise too much space wasted Duplicates O(n) in worst case

Key Points - Lecture 14 Hash Tables O(1) searching complexity Address calculated directly from key with hash function Collisions Table Organisation Linked lists Overflow areas Re-hashing Use a second hash function Linear Susceptible to clustering Quadratic

Key Points - Lecture 14 Hash Functions Animations!! Assume we can construct a function to map keys to a range of integers Methods for reducing this range to (0,m] Division mod m Don’t use m = 2p Multiplication Multiply by A and extract p middle bits m = 2p OK Universal Hashing Animations!!