Binarne hrpe. Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

Size: px
Start display at page:

Download "Binarne hrpe. Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133"

Transcription

1 Binarne hrpe Potpuno binarno stablo binarno stablo u kojem svaki čvor koji nije list ima točno 2 nasljednika. Binarna hrpa potpuno binarno stablo u kojem svaki čvor koji nije list ima veću ključnu vrijednost nego čvorovi u njegovim podstablima Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

2 Binarna hrpa A implementirana kao polje: length[a] broj elemenata u polju A heap-size[a] broj elemenata u hrpi A korijen: A[1] roditelj dijete: Parent(i) 1 return i/2 Left(i) 1 return 2i Right(i) 1 return 2i + 1 Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

3 Svojstvo binarne hrpe max-heap svojstvo: min-heap svojstvo: A[Parent(i)] A[i], i > 1 A[Parent(i)] A[i], i > 1 Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

4 Zadatak Zadatak 10.1 Pokažite da hrpa od n elemenata ima visinu lg n. Zadatak 10.2 Čini li polje 23, 17, 14, 6, 13, 10, 1, 5, 7, 12 max-hrpu? Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

5 Čuvanje svojstva hrpe input: polje A i indeks i output: Left(i), Right(i) su hrpe podstablo od i je hrpa pretpostavka: podstabla u Max-Heapify(A, i) 1 l Left(i) 2 r Right(i) 3 if l heap-size[a] and A[l] > A[i] 4 then largest l 5 else largest i 6 if r heap-size[a] and A[r] > A[largest] 7 then largest r 8 if largest i 9 then A[i] A[largest] 10 Max-Heapify(A, largest) Vrijeme izvršavanja procedure: O(lg n) Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

6 Primjer Zadatak 10.3 Primjenite Max-Heapify(A, i) na dano potpuno binarno stablo A za i = 2. i Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

7 Zadaci Zadatak 10.4 Napišite pseudokod za Min-Heapify proceduru koja će raditi u O(lg n) vremenu. Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

8 Izgradivanje hrpe Koristimo proceduru Max-Heapify za pretvaranje polja A[1... n] u max-hrpu. Build-Max-Heap(A) 1 heap-size[a] length A 2 for i length[a]/2 downto 1 3 do Max-Heapify(A, i) Vremenska složenost algoritama: O(n lg n) Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

9 Zadaci Zadatak 10.5 Napišite algoritam u peudokodu koji će sortirati polje od n elemenata uz pomoć max-hrpe. Algoritam neka radi u O(n lg n) vremenu. Primjenite algoritam na polju A = 5, 13, 2, 25, 7, 17, 20, 8, 4 Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

10 Prioritetni red struktura podataka u kojoj je svakom elementu pridružena ključna vrijednost i omogućeno je efikasno nalaženje ključeva s minimalnom odnosno maksimalnom vrijendošću. Operacije nad max-prioritetnom redu: Insert(S, x) ubacivanje elementa u skup S. Maximum(S) vrati element iz skupa S koji ima maksimalnu vrijednost ključa. Extract-Max(S) vrati i obriši element iz skupa S koji ima maksimalnu vrijednost ključa. Increase-Key(S, x, k) uvećaj vrijednost ključa elementa x s key[x] na k. Prioritetni red ćemo implementirati uz pomoć max binarne hrpe. Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

11 Element s maksimalnom vrijednošću ključa: Maximum(S) 1 return S[1] Skidanje elementa s maksimalnom vrijednošću ključa: Extract-Max(S) 1 if heap-size[s] < 1 2 then error heap underflow 3 max S[1] 4 S[1] S[heap-size[S]] 5 heap-size[s] heap-size[s] 1 6 Max-Heapify(S, 1) 7 return max Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

12 Ubacivanje elementa u skup S: Insert(S, k) 1 heap-size[s] heap-size[s] S[heap-size[S]] 3 Increase-Key(S, heap-size[s], k) Povećavanje vrijednosti ključa na nekom elementu skupa S: Increase-Key(S, i, k) 1 if k < S[i] 2 then error key is smaller than current key 3 S[i] k 4 while i > 1 and S[Parent[i]] < S[i] 5 do exchange S[i] S[Parent(i)] 6 i Parent(i) Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

13 Primjer Neka je dan skup podataka A = 16, 14, 10, 8, 7, 9, 3, 2, 4, 1 max binarne hrpe. Primjenite sljedeće operacije Maximum(A), Extract-Max(A), Increase-Key(A, 5, 12), Insert(A, 11). Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

14 Primjena: Huffmanov kod Efikasna tehnika koja se koristi kod kompresije podataka: 20% 90% sažimanje ovisno o tipu podataka. Primjer: Datoteka C sadrži znakove iz alfabeta {a, b, c, d, e, f } i želimo predstaviti znakove (tipa char) preko proizvoljnog binarnog kodiranja. a b c d e f f FBC VBC ukupni broj bitova potrebno za prikaz znakova iz datoteke C: c C fc c CBR: c C fc c = relativno VBR: c C fc c = smanjenje: C CBR C VBR C CBR = 25, 3% Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

15 Ideja Na temelju frekvencija pojedinog znaka generirati njegov binarni kod čija će veličina varirati ovisno o frekvenciji. Dakle, generirat ćemo binarno stablo T koja će minimizirati vrijednost funkcije B(C) = c C f (c)d T (c) d T (c) predstavlja udaljenost znaka c od korijena stabla T. Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

16 Huffmanov algoritam Huffman(C) 1 Q C 2 for i 1 to C 1 3 do alociraj novi čvor z 4 left[z] x Extract-Min(Q) 5 right[z] y Extract-Min(Q) 6 key[z] key[x] + key[y] 7 Insert(Q, z) ubacujemo čvor z s ključem f [z] 8 return Extract-Min(Q) Vrijeme izvršenja algoritma: O(n lg n). Zašto? Primjer: Na temelju dane tablice generirajmo Huffmanov kod. Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

17 Zadaci Zadatak 11.1 Napišite Huffmanov kod na temelju riječi w = abacadabba Zadatak 11.2 Za dani skup frekvencija znakova {a : 4, b : 12, c : 12, d : 8, e : 9, f : 14} generirajte Huffmanov kod. Strukture podataka i algoritmi VJEŽBE 26. siječnja / 133

Heapsort. Heap data structure

Heapsort. Heap data structure Heapsort Heap data structure. Heap A (not garbage-collected storage) is a nearly complete binary tree.. Height of node = # of edges on a longest simple path from the node down to a leaf.. Height of heap

More information

The Heap Data Structure

The Heap Data Structure The Heap Data Structure Def: A heap is a nearly complete binary tree with the following two properties: Structural property: all levels are full, except possibly the last one, which is filled from left

More information

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya CS60020: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Special Types of Trees Def: Full binary tree = a binary tree in which each node is either a leaf or has degree exactly

More information

Heapsort. Algorithms.

Heapsort. Algorithms. Heapsort Algorithms www.srijon.softallybd.com Outline Heaps Maintaining the heap property Building a heap The heapsort algorithm Priority queues 2 The purpose of this chapter In this chapter, we introduce

More information

Heaps and Priority Queues

Heaps and Priority Queues Heaps and Priority Queues (A Data Structure Intermezzo) Frits Vaandrager Heapsort Running time is O(n lg n) Sorts in place Introduces an algorithm design technique» Create data structure (heap) to manage

More information

Introduction to Algorithms 3 rd edition

Introduction to Algorithms 3 rd edition Introduction to Algorithms 3 rd edition Heapsort Mohammad Heidari Faculty of Mathematics and Computer Khansar March 6, 2017 M.Heidari (Computer Science Khansar) Introduction to Algorithms March 6, 2017

More information

Algorithms, Spring 2014, CSE, OSU Lecture 2: Sorting

Algorithms, Spring 2014, CSE, OSU Lecture 2: Sorting 6331 - Algorithms, Spring 2014, CSE, OSU Lecture 2: Sorting Instructor: Anastasios Sidiropoulos January 10, 2014 Sorting Given an array of integers A[1... n], rearrange its elements so that A[1] A[2]...

More information

Comparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort?

Comparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort? So far we have studied: Comparisons Insertion Sort Merge Sort Worst case Θ(n 2 ) Θ(nlgn) Best case Θ(n) Θ(nlgn) Sorting Revisited So far we talked about two algorithms to sort an array of numbers What

More information

Sortiranje pomoću u hrpe (heapsort( heapsort)

Sortiranje pomoću u hrpe (heapsort( heapsort) Sortiranje pomoću u hrpe (heapsort( heapsort) Na prijašnjim vježbama već smo radili dva algoritma sortiranja (sortiranje umetanjem - Insertion Sort i mjehuričasto sortiranje - Bubble Sort) ) koji su ulazni

More information

Comparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers

Comparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers So far we have studied: Comparisons Tree is completely filled on all levels except possibly the lowest, which is filled from the left up to a point Insertion Sort Merge Sort Worst case Θ(n ) Θ(nlgn) Best

More information

Lecture 5: Sorting Part A

Lecture 5: Sorting Part A Lecture 5: Sorting Part A Heapsort Running time O(n lg n), like merge sort Sorts in place (as insertion sort), only constant number of array elements are stored outside the input array at any time Combines

More information

Basic Data Structures and Heaps

Basic Data Structures and Heaps Basic Data Structures and Heaps David Kauchak Sorting demo (http://math.hws.edu/tmcm/java/xsortlab/) Data structures What is a data structure? Way of storing data that facilitates particular operations.

More information

Chapter 6 Heap and Its Application

Chapter 6 Heap and Its Application Chapter 6 Heap and Its Application We have already discussed two sorting algorithms: Insertion sort and Merge sort; and also witnessed both Bubble sort and Selection sort in a project. Insertion sort takes

More information

VRIJEDNOSTI ATRIBUTA

VRIJEDNOSTI ATRIBUTA VRIJEDNOSTI ATRIBUTA Svaki atribut (bilo da je primarni ključ, vanjski ključ ili običan atribut) može i ne mora imati ograničenja na svojim vrijednostima. Neka od ograničenja nad atributima: Null / Not

More information

Partha Sarathi Manal

Partha Sarathi Manal MA 515: Introduction to Algorithms & MA353 : Design and Analysis of Algorithms [3-0-0-6] Lecture 11 http://www.iitg.ernet.in/psm/indexing_ma353/y09/index.html Partha Sarathi Manal psm@iitg.ernet.in Dept.

More information

Lecture 3. Recurrences / Heapsort

Lecture 3. Recurrences / Heapsort Lecture 3. Recurrences / Heapsort T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright

More information

CS 241 Analysis of Algorithms

CS 241 Analysis of Algorithms CS 241 Analysis of Algorithms Professor Eric Aaron Lecture T Th 9:00am Lecture Meeting Location: OLB 205 Business HW4 out Due Tuesday, Nov. 5 For when should we schedule a make-up lecture? Exam: Tuesday

More information

Programiranje Programski jezik C. Sadržaj. Datoteke. prof.dr.sc. Ivo Ipšić 2009/2010

Programiranje Programski jezik C. Sadržaj. Datoteke. prof.dr.sc. Ivo Ipšić 2009/2010 Programiranje Programski jezik C prof.dr.sc. Ivo Ipšić 2009/2010 Sadržaj Ulazno-izlazne funkcije Datoteke Formatirane datoteke Funkcije za rad s datotekama Primjeri Datoteke komunikacija između programa

More information

Heaps, Heapsort, Priority Queues

Heaps, Heapsort, Priority Queues 9/8/208 Heaps, Heapsort, Priority Queues So Far Insertion Sort: O(n 2 ) worst case Linked List: O(n) search, some operations O(n 2 ) Heap: Data structure and associated algorithms, Not garbage collection

More information

Data Structure and Algorithm, Spring 2017 Final Examination

Data Structure and Algorithm, Spring 2017 Final Examination Data Structure and Algorithm, Spring 2017 Final Examination Date: Tuesday, June 20, 2017 Time: 13:20-16:20pm (180 minutes) 138 points Non-Programming problems Problem 1. In each of the following question,

More information

NAPREDNE STRUKTURE PODATAKA

NAPREDNE STRUKTURE PODATAKA SVEUČILIŠTE U ZAGREBU FAKULTET ORGANIZACIJE I INFORMATIKE V A R A Ţ D I N Filip Višić NAPREDNE STRUKTURE PODATAKA ZAVRŠNI RAD Varaţdin, 2011. SVEUČILIŠTE U ZAGREBU FAKULTET ORGANIZACIJE I INFORMATIKE V

More information

Topic: Heaps and priority queues

Topic: Heaps and priority queues David Keil Data Structures 8/05 1 Topic: Heaps and priority queues The priority-queue problem The heap solution Binary trees and complete binary trees Running time of heap operations Array implementation

More information

Osnove programskog jezika C# Čas 5. Delegati, događaji i interfejsi

Osnove programskog jezika C# Čas 5. Delegati, događaji i interfejsi Osnove programskog jezika C# Čas 5. Delegati, događaji i interfejsi DELEGATI Bezbedni pokazivači na funkcije Jer garantuju vrednost deklarisanog tipa. Prevodilac prijavljuje grešku ako pokušate da povežete

More information

403: Algorithms and Data Structures. Heaps. Fall 2016 UAlbany Computer Science. Some slides borrowed by David Luebke

403: Algorithms and Data Structures. Heaps. Fall 2016 UAlbany Computer Science. Some slides borrowed by David Luebke 403: Algorithms and Data Structures Heaps Fall 20 UAlbany Computer Science Some slides borrowed by David Luebke Birdseye view plan For the next several lectures we will be looking at sorting and related

More information

Sorting Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

Sorting Shabsi Walfish NYU - Fundamental Algorithms Summer 2006 Sorting The Sorting Problem Input is a sequence of n items (a 1, a 2,, a n ) The mapping we want is determined by a comparison operation, denoted by Output is a sequence (b 1, b 2,, b n ) such that: {

More information

Binarno stablo traženja

Binarno stablo traženja Binarno stablo traženja Binarno stablo T je binarno stablo traženja ako su ispunjeni sljedeći i uvjeti: čvorovi od T su označeni podacima nekog tipa na kojem je definiran totalni ureñaj. neka je i bilo

More information

Tirgul 4. Order statistics. Minimum & Maximum. Order Statistics. Heaps. minimum/maximum Selection. Overview Heapify Build-Heap

Tirgul 4. Order statistics. Minimum & Maximum. Order Statistics. Heaps. minimum/maximum Selection. Overview Heapify Build-Heap Tirgul 4 Order Statistics minimum/maximum Selection Heaps Overview Heapify Build-Heap Order statistics The i th order statistics of a set of n elements is the i th smallest element. For example the minimum

More information

Partha Sarathi Mandal

Partha Sarathi Mandal MA 252: Data Structures and Algorithms Lecture 12 http://www.iitg.ernet.in/psm/indexing_ma252/y12/index.html Partha Sarathi Mandal Dept. of Mathematics, IIT Guwahati Inserting Heap Elements Inserting an

More information

A data structure and associated algorithms, NOT GARBAGE COLLECTION

A data structure and associated algorithms, NOT GARBAGE COLLECTION CS4 Lecture Notes /30/0 Heaps, Heapsort, Priority Queues Sorting problem so far: Heap: Insertion Sort: In Place, O( n ) worst case Merge Sort : Not in place, O( n lg n) worst case Quicksort : In place,

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures CMPSC 465 LECTURES 11-12 Priority Queues and Heaps Adam Smith 1 Priority Queue ADT Dynamic set of pairs (key, data), called elements Supports operations: MakeNewPQ() Insert(S,x)

More information

Next. 1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms.

Next. 1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms. Next 1. Covered basics of a simple design technique (Divideand-conquer) Ch. 2 of the text. 2. Next, more sorting algorithms. Sorting Switch from design paradigms to applications. Sorting and order statistics

More information

(Ureñeno. eñeno) ) stablo. r je njihov roditelj. Lista: linearno ureñivanje podataka Stablo: hijerarhijsko ureñivanje podataka (podreñeni

(Ureñeno. eñeno) ) stablo. r je njihov roditelj. Lista: linearno ureñivanje podataka Stablo: hijerarhijsko ureñivanje podataka (podreñeni Stabla (Ureñeno eñeno) ) stablo Lista: linearno ureñivanje podataka Stablo: hijerarhijsko ureñivanje podataka (podreñeni nadreñeni ili dijete roditelj) Definicija: (ureñeno eñeno) ) stablo T je neprazni

More information

Data structures. Organize your data to support various queries using little time and/or space

Data structures. Organize your data to support various queries using little time and/or space Data structures Organize your data to support various queries using little time and/or space Given n elements A[1..n] Support SEARCH(A,x) := is x in A? Trivial solution: scan A. Takes time Θ(n) Best possible

More information

1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms.

1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms. Next 1. Covered basics of a simple design technique (Divideand-conquer) Ch. 2 of the text. 2. Next, more sorting algorithms. Sorting Switch from design paradigms to applications. Sorting and order statistics

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 Amarda Shehu Lecture: Analysis of Algorithms (CS583-002) Sorting in O(n lg n) Time: Heapsort 1 Outline of Today s Class Sorting in O(n

More information

CSS CSS. selector { property: value; } 3/20/2018. CSS: Cascading Style Sheets

CSS CSS. selector { property: value; } 3/20/2018. CSS: Cascading Style Sheets CSS CSS CSS: Cascading Style Sheets - Opisuje izgled (appearance) i raspored (layout) stranice - Sastoji se od CSS pravila, koji defini[u skup stilova selector { property: value; 1 Font face: font-family

More information

HEAP. Michael Tsai 2017/4/25

HEAP. Michael Tsai 2017/4/25 HEAP Michael Tsai 2017/4/25 2 Array Representation of Tree Tree 2 4 1 (a) Array 1 2 3 4 5 6 7 8 9 10 16 14 10 8 7 9 3 Parent(i) 1 return i/2 Left(i) 1 return 2i Right(i) 1 return 2i +1 1 2 3 4 5 6 7 8

More information

CSCE 750, Fall 2002 Notes 2 Page Bubble Sort // sort the array `a[*]' of length `count' // perform only the first `howmany' sort steps // keep t

CSCE 750, Fall 2002 Notes 2 Page Bubble Sort // sort the array `a[*]' of length `count' // perform only the first `howmany' sort steps // keep t CSCE 750, Fall 2002 Notes 2 Page 1 4 Sorting ffl Reasons for studying sorting is a big deal pedagogically useful Λ the application itself is easy to understand Λ a complete analysis can often be done Λ

More information

CSE 3101: Introduction to the Design and Analysis of Algorithms. Office hours: Wed 4-6 pm (CSEB 3043), or by appointment.

CSE 3101: Introduction to the Design and Analysis of Algorithms. Office hours: Wed 4-6 pm (CSEB 3043), or by appointment. CSE 3101: Introduction to the Design and Analysis of Algorithms Instructor: Suprakash Datta (datta[at]cse.yorku.ca) ext 77875 Lectures: Tues, BC 215, 7 10 PM Office hours: Wed 4-6 pm (CSEB 3043), or by

More information

Binary search trees. Support many dynamic-set operations, e.g. Search. Minimum. Maximum. Insert. Delete ...

Binary search trees. Support many dynamic-set operations, e.g. Search. Minimum. Maximum. Insert. Delete ... Binary search trees Support many dynamic-set operations, e.g. Search Minimum Maximum Insert Delete... Can be used as dictionary, priority queue... you name it Running time depends on height of tree: 1

More information

Binary Trees. Recursive definition. Is this a binary tree?

Binary Trees. Recursive definition. Is this a binary tree? Binary Search Trees Binary Trees Recursive definition 1. An empty tree is a binary tree 2. A node with two child subtrees is a binary tree 3. Only what you get from 1 by a finite number of applications

More information

UNIVERZITET U BEOGRADU ELEKTROTEHNIČKI FAKULTET

UNIVERZITET U BEOGRADU ELEKTROTEHNIČKI FAKULTET UNIVERZITET U BEOGRADU ELEKTROTEHNIČKI FAKULTET Katedra za elektroniku Računarska elektronika Grupa br. 11 Projekat br. 8 Studenti: Stefan Vukašinović 466/2013 Jelena Urošević 99/2013 Tekst projekta :

More information

Binary search trees :

Binary search trees : Binary search trees Binary search trees : Search trees are data structures that generally offer the following dynamic-set operations : SEARCH MINIMUM MAXIMUM PREDECESSOR SUCCESSOR INSERT DELETE Basic operations

More information

Heaps. (our first advanced data structure)

Heaps. (our first advanced data structure) Heaps (our first advanced data structure) Data Structures Used in essentially every single programming task that you can think of What are some examples of data structures? What are some example programs?

More information

overview use of max-heaps maxheapify: recall pseudo code heaps heapsort data structures and algorithms lecture 4 heap sort: more

overview use of max-heaps maxheapify: recall pseudo code heaps heapsort data structures and algorithms lecture 4 heap sort: more overview heaps data structures and algorithms 2017 09 14 lecture 4 heapsort heap sort: more priority queues use of max-heaps maxheapify: recall pseudo code as a data structure for heapsort as a data structure

More information

data structures and algorithms lecture 4

data structures and algorithms lecture 4 data structures and algorithms 2017 09 14 lecture 4 overview heaps heapsort heap sort: more priority queues material use of max-heaps as a data structure for heapsort as a data structure for storing a

More information

for i:=2 to n do if glasovi[i]>max then begin max:=glasovi[i]; k:=i {*promenljiva k ce cuvati indeks takmicara sa najvise glasova *} end;

for i:=2 to n do if glasovi[i]>max then begin max:=glasovi[i]; k:=i {*promenljiva k ce cuvati indeks takmicara sa najvise glasova *} end; {*Na Evroviziji je ucestvovalo n izvodjaca. Koji od njih je osvojio najvise glasova publike?*} program Evrovizija; glasovi:array[1..50] of integer; max,k:integer; writeln('unosi se broj izvodjaca:'); writeln('unose

More information

Nizovi. Programiranje 1

Nizovi. Programiranje 1 Nizovi Programiranje 1 VB Nizovi Zamislite da imate 10,000 šešira i da morate svakome od njih dati jedinstvenu oznaku. Kako biste to napravili? Bilo bi razumno svakom šeširu dati njegov broj. Sada možete

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Desgn and Analyss of Algorthms Heaps and Heapsort Reference: CLRS Chapter 6 Topcs: Heaps Heapsort Prorty queue Huo Hongwe Recap and overvew The story so far... Inserton sort runnng tme of Θ(n 2 ); sorts

More information

KLASIFIKACIJA JELENA JOVANOVIĆ. Web:

KLASIFIKACIJA JELENA JOVANOVIĆ.   Web: KLASIFIKACIJA JELENA JOVANOVIĆ Email: jeljov@gmail.com Web: http://jelenajovanovic.net PREGLED PREDAVANJA Šta je klasifikacija? Binarna i više-klasna klasifikacija Algoritmi klasifikacije Mere uspešnosti

More information

OUR KNOWLEDGE FOR YOUR SUCCESS. Iskustva u razvoju i implementaciji ADF aplikacije

OUR KNOWLEDGE FOR YOUR SUCCESS. Iskustva u razvoju i implementaciji ADF aplikacije Iskustva u razvoju i implementaciji ADF aplikacije Sadržaj Opis aplikacije za AZ Mirovinski Fond Internacionalizacija aplikacije Integracija sa Oracle Reports Iskorištenje postojeće PL/SQL logike Kreiranje

More information

Uputa: Zabranjeno je koristiti bilo kakva pomagala. Rje²enja pi²ete desno od zadatka. Predajete samo ovaj list.

Uputa: Zabranjeno je koristiti bilo kakva pomagala. Rje²enja pi²ete desno od zadatka. Predajete samo ovaj list. Ime i prezime: Asistent: Predava : Programiranje (C) 1. kolokvij 14. 4. 2003. 1. 2. 3. 4. 5. 6. 7. Uputa: Zabranjeno je koristiti bilo kakva pomagala. Rje²enja pi²ete desno od zadatka. Predajete samo ovaj

More information

Properties of a heap (represented by an array A)

Properties of a heap (represented by an array A) Chapter 6. HeapSort Sorting Problem Input: A sequence of n numbers < a1, a2,..., an > Output: A permutation (reordering) of the input sequence such that ' ' ' < a a a > 1 2... n HeapSort O(n lg n) worst

More information

BM267 - Introduction to Data Structures

BM267 - Introduction to Data Structures BM267 - Introduction to Data Structures 9. Heapsort Ankara University Computer Engineering Department Bulent Tugrul BLM 267 1 (Binary) Heap Structure The heap data structure is an array organized as a

More information

Izrada VI laboratorijske vježbe

Izrada VI laboratorijske vježbe Izrada VI laboratorijske vježbe 1. Programirati proceduru koja se aktivira sa Standard palete alatki klikom na button Fajlovi. Prilikom startovanja procedure prikazuje se forma koja sadrži jedan list box

More information

VHDLPrimeri Poglavlje5.doc

VHDLPrimeri Poglavlje5.doc 5. VHDL opis kola koja obavljaju osnovne aritmetičke funkcije Sabirači Jednobitni potpuni sabirač definisan je tablicom istinitosti iz Tabele 5.1. Tabela 5.1. cin a b sum cout 0 0 0 0 0 0 0 1 1 0 0 1 0

More information

Binary Search Trees. 1. Inorder tree walk visit the left subtree, the root, and right subtree.

Binary Search Trees. 1. Inorder tree walk visit the left subtree, the root, and right subtree. Binary Search Trees Search trees are data structures that support many dynamic set operations including Search, Minimum, Maximum, Predecessor, Successor, Insert, and Delete. Thus, a search tree can be

More information

Učitati cio broj n i štampati njegovu recipročnu vrijednost. Ako je učitan broj 0, štampati 1/0.

Učitati cio broj n i štampati njegovu recipročnu vrijednost. Ako je učitan broj 0, štampati 1/0. Kontrolne naredbe Primjeri: Opšti oblik razgranate strukture (if sa ) if (uslov) Naredba 1 ili blok naredbi1 Naredba 2 ili blok naredbi2 Učitati broj x i štampati vrijednost double x, z; Scanner in=new

More information

Algorithms Lab 3. (a) What is the minimum number of elements in the heap, as a function of h?

Algorithms Lab 3. (a) What is the minimum number of elements in the heap, as a function of h? Algorithms Lab 3 Review Topics covered this week: heaps and heapsort quicksort In lab exercises (collaboration level: 0) The in-lab problems are meant to be be solved during the lab and to generate discussion

More information

CSE5311 Design and Analysis of Algorithms. Administrivia Introduction Review of Basics IMPORTANT

CSE5311 Design and Analysis of Algorithms. Administrivia Introduction Review of Basics IMPORTANT CSE5311 Design and Analysis of Algorithms Administrivia Introduction Review of Basics 8/24/2004 CSE5311 Fall 2004 MKUMAR 1 IMPORTANT Americans With Disabilities Act The University of Texas at Arlington

More information

<A rel="stylesheet" B="mystylesheet.css" C="text/css" />

<A rel=stylesheet B=mystylesheet.css C=text/css /> 1 od 9 9.4.2013 7:18 EFOS_kol1_2011 - RJEŠENJA 16.4.2011. Uključivanje vanjske mystylesheet.css datoteke sa određenim stilovima, postiže se zadavanjem naredbe unutar HTML koda, koja izgleda ovako:

More information

quiz heapsort intuition overview Is an algorithm with a worst-case time complexity in O(n) data structures and algorithms lecture 3

quiz heapsort intuition overview Is an algorithm with a worst-case time complexity in O(n) data structures and algorithms lecture 3 quiz data structures and algorithms 2018 09 10 lecture 3 Is an algorithm with a worst-case time complexity in O(n) always faster than an algorithm with a worst-case time complexity in O(n 2 )? intuition

More information

Data Structures and Algorithms Week 4

Data Structures and Algorithms Week 4 Data Structures and Algorithms Week. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Week Divide and conquer Merge

More information

JavaScript i HTML DOM

JavaScript i HTML DOM 4. vježbe iz WEB programiranja četvrtak, 22. ožujka 2012. JavaScript 1. dio JavaScript i Što je DOM? Kako JS koristi DOM? Pristup elementima dokumenta Promjena i učitavanje vrijednosti tagova Primjer 1.

More information

Data Structures. Dynamic Sets

Data Structures. Dynamic Sets Data Structures Binary Search Tree Dynamic Sets Elements have a key and satellite data Dynamic sets support queries such as: Search(S, k) Minimum(S) Maximum(S) Successor(S, x) Predecessor(S, x) Insert(S,

More information

Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.

Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. R version 2.13.1 (2011-07-08) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY.

More information

2. Linijska algoritamska struktura

2. Linijska algoritamska struktura Univerzitet u Nišu Građevinsko-arhitektonski fakultet Informatika 2 2. Linijska algoritamska struktura Milica Ćirić Blokovi za prikaz algoritma Algoritam se vizuelno može prikazati pomoću blok dijagrama,

More information

Moja naslovnica / Sveučilište u Zagrebu / Fakultet prometnih znanosti / Baze podataka / Opći dio / Izvanredni studenti - test za potpis

Moja naslovnica / Sveučilište u Zagrebu / Fakultet prometnih znanosti / Baze podataka / Opći dio / Izvanredni studenti - test za potpis Moja naslovnica / Sveučilište u Zagrebu / Fakultet prometnih znanosti / Baze podataka / Opći dio / Izvanredni studenti - test za potpis Započeto Četvrtak, 27 Listopad 2016, 22:34 Stanje završen Završeno

More information

Univerzitet u Nišu Građevinsko-arhitektonski fakultet. 4. Ciklična algoritamska struktura 5. Jednodimenzionalno polje.

Univerzitet u Nišu Građevinsko-arhitektonski fakultet. 4. Ciklična algoritamska struktura 5. Jednodimenzionalno polje. Univerzitet u Nišu Građevinsko-arhitektonski fakultet Informatika 2 4. Ciklična algoritamska struktura 5. Jednodimenzionalno polje Milica Ćirić Ciklična algoritamska struktura Ciklična struktura (petlja)

More information

Mašinska vizija. Dr Nenad Jovičić tnt.etf.rs/~mv

Mašinska vizija. Dr Nenad Jovičić tnt.etf.rs/~mv Mašinska vizija Dr Nenad Jovičić 2017. tnt.etf.rs/~mv Linearne 2D geometrijske transformacije 2D geometrijske transformacije Pretpostavka: Objekti u 2D prostoru se sastoje iz tačaka i linija. Svaka tačka

More information

Informatika Uvod u C#,.NET Framework i Visual Studio... nastavak...

Informatika Uvod u C#,.NET Framework i Visual Studio... nastavak... Informatika Uvod u C#,.NET Framework i Visual Studio... nastavak... Prof. dr. sc. Tomislav Pribanić Izv. prof. dr. sc. Vedran Podobnik Doc. dr. sc. Marija Seder Sveučilište u Zagrebu Fakultet elektrotehnike

More information

Vjež ba 3-3: Ražvoj ASP.NET MVC 4 Pogleda s Ražor sintaksom

Vjež ba 3-3: Ražvoj ASP.NET MVC 4 Pogleda s Ražor sintaksom Vjež ba 3-3: Ražvoj ASP.NET MVC 4 Pogleda s Ražor sintaksom U ovoj vježbi trebate dodati sljedeće view-ove u OnlineVrijednosnice aplikaciju: Details view za Graf model objekte ovaj view će prikazivati

More information

Sveučilište u Zagrebu PMF Matematički odsjek. Mreže računala. Vježbe 08. Zvonimir Bujanović Slaven Kožić Vinko Petričević

Sveučilište u Zagrebu PMF Matematički odsjek. Mreže računala. Vježbe 08. Zvonimir Bujanović Slaven Kožić Vinko Petričević Sveučilište u Zagrebu PMF Matematički odsjek Mreže računala Vježbe 08 Zvonimir Bujanović Slaven Kožić Vinko Petričević Uvod: (X)HTML i CSS Na ovim i idućim vježbama naučit ćemo osnove jezika za opisivanje

More information

APSTRAKCIJE U PROGRAMIRANjU

APSTRAKCIJE U PROGRAMIRANjU APSTRAKCIJE U PROGRAMIRANjU Apstrakcije -Osnovni problem u programiranju je složenost problema. -Ne može se ceo problem posmatrati i rešavati odjednom. -Složenost se rešava apstrakcijama, kontrolisanim

More information

COSC Advanced Data Structures and Algorithm Analysis Lab 3: Heapsort

COSC Advanced Data Structures and Algorithm Analysis Lab 3: Heapsort COSC 320 - Advanced Data Structures and Algorithm Analysis Lab 3: Heapsort Dr. Joe Anderson Due: 21 February 2019 1 Objectives In this lab you will focus on the following objectives: 1. Develop familiarity

More information

Push(3,&S) 3 1 S Uvijek trebamo paziti da ne zovemo Pop nad praznim stogom.

Push(3,&S) 3 1 S Uvijek trebamo paziti da ne zovemo Pop nad praznim stogom. tog (tack) tog je posebna vrsta liste: od svih operacija dozvoljeno je ubacivanje, brisanje i gledanje sadržaja elementa samo na jednom kraju liste koji zovemo vrh stoga. tog zovemo i lifo last in first

More information

Algoritmi i strukture podataka

Algoritmi i strukture podataka Algoritmi i strukture podataka vežbe 7 Mirko Stojadinović 20. decembar 2015 1 1 Kviksort Složenost ovog algoritma je u najgorem sluǎju O(n 2 ) (kada se za pivot bira uvek najmanji element što je slučaj

More information

pojedinačnom elementu niza se pristupa imeniza[indeks] indeks od 0 do n-1

pojedinačnom elementu niza se pristupa imeniza[indeks] indeks od 0 do n-1 NIZOVI Niz deklarišemo navođenjemtipa elemenata za kojim sledi par srednjih zagrada[] i naziv niza. Ako je niz višedimenzionalni između zagrada[] se navode zarezi, čiji je broj za jedan manji od dimenzija

More information

Sveučilište u Zagrebu Fakultet strojarstva i brodogradnje. WEB programiranje HTML & CSS

Sveučilište u Zagrebu Fakultet strojarstva i brodogradnje. WEB programiranje HTML & CSS Sveučilište u Zagrebu Fakultet strojarstva i brodogradnje WEB programiranje HTML & CSS Autor/i: Juraj Benić 2018 1. Zadatak Kreirati stranicu kojoj će naslov biti Zadatak 1. i veličina teksta 20px te staviti

More information

namespace spojneice { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

namespace spojneice { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Spojnice using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO;

More information

Unit 1 Basics of Algorithms and Mathematics. Computer Engineering

Unit 1 Basics of Algorithms and Mathematics. Computer Engineering Unit 1 Basics of Algorithms and Mathematics (1) What is an algorithm? Explain various properties of an algorithm. OR What is an algorithm? Explain various characteristics of an algorithm. Algorithm An

More information

Data Structures and Algorithms Chapter 4

Data Structures and Algorithms Chapter 4 Data Structures and Algorithms Chapter. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Chapter Divide and conquer

More information

Uvod u relacione baze podataka

Uvod u relacione baze podataka Uvod u relacione baze podataka Ana Spasić 5. čas 1 Podupiti, operatori exists i in 1. Izdvojiti imena i prezimena studenata koji su položili predmet čiji je identifikator 2001. Rešenje korišćenjem spajanja

More information

Tutorial 6-7. Dynamic Programming and Greedy

Tutorial 6-7. Dynamic Programming and Greedy Tutorial 6-7 Dynamic Programming and Greedy Dynamic Programming Why DP? Natural Recursion may be expensive. For example, the Fibonacci: F(n)=F(n-1)+F(n-2) Recursive implementation memoryless : time= 1

More information

OPTIMIZACIJA UPITA U MICROSOFT SQL SERVER BAZI POMOĆU INDEKSA MICROSOFT SQL SERVER QUERY OPTIMIZATIONS USING INDEXES

OPTIMIZACIJA UPITA U MICROSOFT SQL SERVER BAZI POMOĆU INDEKSA MICROSOFT SQL SERVER QUERY OPTIMIZATIONS USING INDEXES OPTIMIZACIJA UPITA U MICROSOFT SQL SERVER BAZI POMOĆU INDEKSA MICROSOFT SQL SERVER QUERY OPTIMIZATIONS USING INDEXES Mario Knok 1, Željko Kovačević 2 1 Tehničko veleučilište u Zagrebu Vol. 4, No. 2, 2016.

More information

Jezik Baze Podataka SQL. Jennifer Widom

Jezik Baze Podataka SQL. Jennifer Widom Jezik Baze Podataka SQL SQL o Jezik koji se koristi u radu sa relacionim bazama podataka o Nije programski jezik i manje je kompleksan. o Koristi se isključivo u radu za bazama podataka. o SQL nije case

More information

CS 303 Design and Analysis of Algorithms

CS 303 Design and Analysis of Algorithms Mid-term CS 303 Design and Analysis of Algorithms Review For Midterm Dong Xu (Based on class note of David Luebke) 12:55-1:55pm, Friday, March 19 Close book Bring your calculator 30% of your final score

More information

/*#include <iostream> // Prvi zadatak sa integralnomg ispita

/*#include <iostream> // Prvi zadatak sa integralnomg ispita /*#include // Prvi zadatak sa integralnomg ispita 27.01.2015 #include using std::setw; using std::cout; const int red(5), kolona(4); void unos(int[]); void ispis(int[][kolona]); float

More information

PARALELNO PROGRAMIRANJE

PARALELNO PROGRAMIRANJE Predavanje 09 Odjel za matematiku 1 PARALELNO PROGRAMIRANJE POSIX threadovi za C++ Predavanje 09 Odjel za matematiku 2 Programske niti (thread) unutar procesa Danas ćemo se upoznati s POSIX thread bibliotekom

More information

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Dr. Chung- Wen Albert Tsao 1 Binary Search Trees Data structures that can support dynamic set operations. Search, Minimum, Maximum, Predecessor,

More information

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues.

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues. Outline Computer Science 33 Heap Sort Mike Jacobson Department of Computer Science University of Calgary Lectures #5- Definition Representation 3 5 References Mike Jacobson (University of Calgary) Computer

More information

Računarske osnove Interneta (SI3ROI, IR4ROI)

Računarske osnove Interneta (SI3ROI, IR4ROI) Računarske osnove terneta (SI3ROI, IR4ROI) Vežbe MPLS Predavač: 08.11.2011. Dražen Drašković, drazen.draskovic@etf.rs Autori: Dražen Drašković Naučili ste na predavanjima MPLS (Multi-Protocol Label Switching)

More information

Data Structures and Algorithms. Roberto Sebastiani

Data Structures and Algorithms. Roberto Sebastiani Data Structures and Algorithms Roberto Sebastiani roberto.sebastiani@disi.unitn.it http://www.disi.unitn.it/~rseba - Week 0 - B.S. In Applied Computer Science Free University of Bozen/Bolzano academic

More information

Lecture 5: Scheduling and Binary Search Trees

Lecture 5: Scheduling and Binary Search Trees Lecture 5: Scheduling and Binary Search Trees Lecture Overview Runway reservation system Definition How to solve with lists Binary Search Trees Readings Operations CLRS Chapter 10, 12.1-3 Runway Reservation

More information

Theory & Algorithms 15/01/04. Red-Black Trees. Nicolas Wack, Sylvain Le Groux

Theory & Algorithms 15/01/04. Red-Black Trees. Nicolas Wack, Sylvain Le Groux Theory & Algorithms Red-Black Trees 15/01/04 Nicolas Wack, Sylvain Le Groux Balanced search trees Balanced search tree: A search-tree data structure for which a height of O(lg n) is guaranteed when implementing

More information

External Sorting Methods

External Sorting Methods External Sorting Methods Assumptions: data is too large to be held in main memory; data is read or written in blocks; 1 or more external devices available for sorting Sorting in main memory is cheap or

More information

/463 Algorithms - Fall 2013 Solution to Assignment 3

/463 Algorithms - Fall 2013 Solution to Assignment 3 600.363/463 Algorithms - Fall 2013 Solution to Assignment 3 (120 points) I (30 points) (Hint: This problem is similar to parenthesization in matrix-chain multiplication, except the special treatment on

More information

Algoritmi za sortiranje u programskom jeziku C++

Algoritmi za sortiranje u programskom jeziku C++ SVEUČILIŠTE U RIJECI FILOZOFSKI FAKULTET U RIJECI ODSJEK ZA POLITEHNIKU Algoritmi za sortiranje u programskom jeziku C++ Završni rad Mentor završnog rada: doc. dr. sc. Marko Maliković Student: Alen Jakus

More information

QuickSort and Others. Data Structures and Algorithms Andrei Bulatov

QuickSort and Others. Data Structures and Algorithms Andrei Bulatov QuickSort and Others Data Structures and Algorithms Andrei Bulatov Algorithms Quicksort 5-2 Heap Property A heap is a nearly complete binary tree, satisfying an extra condition Let Parent(i) denote the

More information

Advanced algorithms. binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap. Jiří Vyskočil, Radek Mařík 2013

Advanced algorithms. binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap. Jiří Vyskočil, Radek Mařík 2013 binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap Jiří Vyskočil, Radek Mařík 2013 heap Heaps [haldy] a heap is a specialized data structure (usually tree-based) that satisfies

More information