1318.2 Marks

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

1.

Heaps
A binary tree has the heap property iff
a. it is empty or
b. the key in the root is larger than that in either child and both subtrees have the heap
property.
A heap can be used as a priority queue: the highest priority item is at the root and is trivially
extracted. But if the root is deleted, we are left with two sub-trees and we must efficiently re-
create a single tree with the heap property.
he value of the heap structure is that we can both extract the highest priority item and insert a
new one in O(logn) time.
2. PERIORITY QUEUES
!n computer science, a priority queue is an abstract data type which is like a regular queue or
stack data structure, but where additionally each element has a "priority" associated with it. !n a
priority queue, an element with high priority is served before an element with low priority. !f two
elements have the same priority, they are served according to their order in the queue.
A priority queue must at least support the following operations:
!nsert#with#priority: add an element to the queue with an associated priority
$ull#highest#priority#element: remove the element from the queue that has the highest
priority, and return it
. !y"a#i$ %e#ory %a"age#e"t
%hen memory is allocated during run&execution time, it is called '(ynamic )emory )anagement*. his
memory is not fixed and is allocated according to our requirements. hus in it there is no wastage of
memory. +o there is no need to know exact memory requirements in advance.
&. Tra$'s a"( Se$tors (storage (e)i$es)
A disk is divided into tra$'s, $yli"(ers, and se$tors. A tra$' is that portion of a disk which
passes under a single stationary head during a disk rotation, a ring , bit wide. A $yli"(er is
comprised of the set of tracks described by all the heads -on separate platters. at a single seek
position. /ach cylinder is equidistant from the center of the disk. A track is divided into segments
of se$tors, which is the basic unit of storage.
*. +o#ple,ity
he complexity of an algorithm is a function describing the efficiency of the algorithm in terms
of the amount of data the algorithm must process. 0sually there are natural units for the domain
and range of this function. here are two main complexity measures of the efficiency of an
algorithm:
Ti#e $o#ple,ity is a function describing the amount of time an algorithm takes in terms
of the amount of input to the algorithm. "ime" can mean the number of memory
accesses performed, the number of comparisons between integers, the number of times
some inner loop is executed, or some other natural unit related to the amount of real time
the algorithm will take.
Spa$e $o#ple,ity is a function describing the amount of memory -space. an algorithm
takes in terms of the amount of input to the algorithm. %e often speak of "extra" memory
needed, not counting the memory needed to store the input itself.
+o#ple,ity o- sear$hi"g a"( sorti"g algorith#
a. 1inear +earch 2-n.
b. Binary +earch 2-log n.
c. Bubble +ort 2-n3.
d. )erge +ort 2-n log n.

You might also like