69 views

Uploaded by April Nop

Homework 4

- District1_2010
- Data Structures and Algorithms
- BSIT 41 Content
- 2004 ICDE Sy Nexsort
- Amcat Sample Questions 5
- quiz1.pdf
- IT111
- Data Structure Question Bank
- DS Unit 2
- Exam 2006
- CSCI2100B
- Big O cheat sheet
- Syllabus.ecs-302.Data Structure Using c
- DC (Common to ALL)
- Enumerations
- avs1
- Modeling, Simulation and Optimization - Focus on Applications
- Ai Book Unit i Final
- Ada Tutorials
- ADA_QB.pdf

You are on page 1of 4

Fall 2016

Homework 4

CHAPTER 7

3. What is the maximum number of nodes that can be stored in a binary tree with 10

levels?

= 2 ^ 10 1

=1024 1

=1023

4. What is the minimum number of levels in a binary tree containing 6023 nodes?

= ceiling [log2(N + 1)]

= ceiling [log2(6023 + 1)]

= ceiling [log2(6024)] 12.5

212 6023 213

4096 6023 8192

So at least 0-13 levels (= 14 levels)

5. What is the maximum number of levels in a tree containing 6023 nodes?

= 6023

6. What is the maximum number of nodes that can be stored in level 16 of a binary tree?

216 = 65,536

8. True or false:

a. The highest level of a complete binary tree contains more nodes than all of the

other levels combined.

False

b. The root node is always at the highest level of the tree.

False

c. Level 9 is the highest level in a 10 level tree.

True

11. Draw the binary search tree resulting from inserting the nodes with the integer key

values: 68, 23, 45, 90, 70, 21, and 55 into the tree. Assume key 68 is inserted first, then

key 23, etc.

6

8

2

3

2

1

9

0

4

5

7

0

5

5

20. Give the output produced by an NLR output scan of the tree shown in Figure 7.3f.

68-23-21-45-55-90-70

CHAPTER 8

4. Give three factors to be considered in selecting a sorting algorithm for a particular

application.

How much speed and memory you have available, the type of data that needs to be

stored, and the programmers capability

6. Give an expression for the minimum number of comparisons required to sort n items.

= O(nlog2n)

10. Under what conditions is the Binary Tree Sort fast?

Fast for random data, which produces a balanced tree

11. Calculate the minimum and maximum number of comparisons required to sort 1,000,000

items using the Binary Tree Sort.

Minimum

= O ((1,000,000) log2(1,000,000))

= 19,931,568.5693

Maximum

= O (1,000,000 ^2)

= 1,000,000,000,000

13. The integers 65, 80, 70, 18, 86, 6, and 37 are to be sorted using the Binary Tree Sort.

Assume the integers are processed by the algorithm in the order given.

a. Show the binary tree that results from sorting.

6

5

8

0

1

8

3

7

8

6

7

0

b. As the integers are placed in the tree, count the number of comparisons made.

What is the total number of comparisons?

10

A binary tree in which (the value of) each parent is greater than both of its

children

31. A 16 element array stores the integers 81, 16, 2, 89, 54, 23, 76, 25, 37, 107, 1, 74, 45,

16, 31, and 58 in elements 0 through 15, respectively. They are to be sorted using the

merge sort.

a. How many passes will be performed to complete the sort?

4

b. Show the contents of the array at the beginning of the sort and after each pass.

81, 16 2, 89 54, 23 76, 25 37, 107

1, 74 45, 16 31, 58

16, 81 2, 89

1, 74

16, 45 31, 58

1, 2, 16, 16, 23, 25, 31, 37, 45, 54, 58, 74, 76, 81, 89, 107

c. Count the number of comparisons that were made to sort the 16 items.

13

d. Count the number of swaps made to complete the sort of the 16 items.

47

e. Compare your answers in parts (c) and (d) of this question to results obtained

when the formulas presented in Table 8.6 are used.

SE (0.75n) log2n

= (0.75(16)) log2(16)

= 48

PMS = log2n

= log2(16)

=4

CAms = [(n/2) + (n-1)]/2

= [(16/2) + (16-1)]/2

= [(8) + (15)]/2

= [(8) + (15)]/2

=23/2

= 11.5

SEMS = PMS * CAms

= 4 * 11.5

=46

total swaps = 2nlog2n

= 128

=(2*SEMS)/0.75

= (2 * 46) /0.75

=122.67

32. What characteristic of a data set makes the Quicksort slow?

It does not perform quickly when input is sorted in reverse or nearly sorted in

reverse

- District1_2010Uploaded byTimmy Feng
- Data Structures and AlgorithmsUploaded byMohammed Jeelan
- BSIT 41 ContentUploaded bywarrior432
- 2004 ICDE Sy NexsortUploaded bymanuelq9
- Amcat Sample Questions 5Uploaded byYekanth Kola
- quiz1.pdfUploaded byPorkerriaCcdlv
- IT111Uploaded byThinesh Ravechandran
- Data Structure Question BankUploaded byamitukumar
- DS Unit 2Uploaded bySubathra Devi Mourougane
- Exam 2006Uploaded byavsiyer
- CSCI2100BUploaded byenergy0124
- Big O cheat sheetUploaded byArial96
- Syllabus.ecs-302.Data Structure Using cUploaded bykumawdhesh
- DC (Common to ALL)Uploaded byChindam Hari Prasad
- EnumerationsUploaded byHarshit Gupta
- avs1Uploaded bySuresh Kumar
- Modeling, Simulation and Optimization - Focus on ApplicationsUploaded byNichol Dimalanta
- Ai Book Unit i FinalUploaded bygopitheprince
- Ada TutorialsUploaded byYogenderBhardwaj
- ADA_QB.pdfUploaded bySai Harish
- bg-ksort-ieeetoc.PSUploaded byfarleyknight
- Chapter+7+-+Tree+-+2009-+2009Uploaded byThanh Bi Nguyen
- TreesUploaded byBasabdatta Das
- L9treeUploaded bymanjeet.kamboj13
- Data Structure Test PaperUploaded bydjahad
- Data StructureUploaded bySunil
- Coding_and_Crypto_HW1Uploaded bySonam Kumar
- Unplugged ActivityUploaded bypinocchio
- ADA_QBUploaded bysharma balwant
- A Solved Example Using Sankoff's AlgorithmUploaded byNoStrings8

- MELJUN CORTES DATA STRUCTURES GraphUploaded byMELJUN CORTES, MBA,MPA
- An Efficient Algorithm for 3D Rectangular Box PackingUploaded byAli Davut
- DsaUploaded byTiễn Dương
- daweqwUploaded byChillik Ardianto
- Informed-Search.pptxUploaded byMichael
- Matlab Solutions for Maxflow-mincut and Ford Fulkerston AlgorithmUploaded byboramil
- 20160912_Transform_and_Conquer.pdfUploaded byFyyrree
- Proforma Mte 3104 - Decision MathematicsUploaded byCikgu Madrid
- Efficient Projections onto the ℓ1-Ball for Learning in High DimensionsUploaded byKofi Deh
- Chapter 5 IntroductionUploaded byHeshsham Basit
- Bisection Method Algo & ExamplesUploaded byZunAib Ali
- Svmtrain.mUploaded bylizhi0007
- II Non-Linear EquationsUploaded byWinsle An
- Data Structure Through C Language V2Uploaded bysolvedcare
- 1378535228 Tree Travers Al 06Uploaded byshinde_jayesh2005
- Carmerini - A note on finding optimum branchingsUploaded byapi-3760049
- BacktrackingUploaded byshijinbgopal
- ch09solUploaded byEric Martin
- Advanced Data Structures NotesUploaded byChinkal Nagpal
- 02.1 Chapter2 Solving Linear Programs.pdfUploaded byAshoka Vanjare
- The Steps in Developing a Dynamic Programming AlgorithmUploaded byvasan
- Practical 1Uploaded byDravid Kumar
- Adaptive Filters 1Uploaded bylonlinness
- lec37-nov03Uploaded byMukesh Kumar Dewra
- Data StructuresUploaded byapi-3729436
- Simple Vlookup ExamplesUploaded byMohammad Kamruzzaman
- AlgoUploaded byhos-gh
- XML diff surveyUploaded bymicrodan8710
- MIT Introduction to Deep Learning Course Lecture 1Uploaded bytintojames
- Optimization[1]Uploaded byMaximiliano Salazar