1 views

Uploaded by Eric Leo Asiamah

Data Structure

- Kruskal Pascal
- D1-87-10
- Seminar on Image Segmentation(09501)
- 270-1034-1-PB
- CMSC 27100
- 0910SEM1-CS1231_2
- chap4 (1).ppt
- AN IMPROVED ALGORITHM FOR CALCULATING THE SUM-OF-FACTORIALS FUNCTION
- Recursive Algorithms
- Maple Worksheet
- UNIT_5
- Partitioning
- Data Structure and Algorithm
- arc
- MST_subhajit
- Sikimeti Ma'u- Quilted Strips, Graph Associahedra and A-Infinity n-Modules
- COM
- Syllabus for Computer Science and Information Technology (CS) _ GATE 2013
- Article About the Library of Babel (Parts 1 & 2 of 4)
- Bhn Kuliah 9 - Backtracking and Searching

You are on page 1of 6

Q1.

(a). What is a function?

A function is a group of statements that together perform a task. Every C program

has at least one function, which is main(), and all the most trivial programs can

define additional functions. You can divide up your code into separate functions.

(2marks)

A function is recursive if a statement in the body of the function calls itself. Recursion is the

process of defining something in terms of itself. For a computer language to be recursive, a

function must be able to call itself. (2marks)

For example, let us consider the function factr() shown below, which computers the factorial

of an integer. (6marks)

#include

<stdio.h>

int

factorial (int);

main()

{

int num, fact;

printf (Enter a positive integer value: ");

scanf (%d, &num);

fact = factorial

(num); printf ("\n Factorial of %d =%5d\n", num, fact);

}

int factorial (int n)

{

int result;

if (n == 0)

return (1);

else

result = n * factorial (n-1);

return (result);

}

Both involve a termination test. (1mark)

Both can occur infinitely. (1mark)

Iteration

Iteration explicitly user a repetition

structure.

Iteration terminates when the loop

continuation.

Iteration keeps modifying the counter

until the loop continuation condition

fails.

Iteration normally occurs within a loop

so the extra memory assigned is

omitted.

It reduces the processors operating

time.

Recursion

Recursion achieves repetition through

repeated function calls.

Recursion terminates when a base case

is recognized.

Recursion keeps producing simple

versions of the original problem until

the base case is reached.

Recursion causes another copy of the

function and hence a considerable

memory spaces occupied.

It increases the processors operating

time.

(7marks)

Q3.

(A) What is the importance of the stopping case in recursive functions?

When writing recursive functions, you must have a exit condition somewhere to force the

function to return without the recursive call being executed. If you do not have an exit

condition, the recursive function will recurse forever until you run out of stack space and

indicate error about lack of memory, or stack overflow.

(2marks)

For example, let us consider the function factr() shown below, which computers the factorial

of an integer.

#include

<stdio.h>

factorial (int);

main()

{

int

printf (Enter a positive integer value: ");

scanf (%d, &num);

fact = factorial

(num); printf ("\n Factorial of %d =%5d\n", num, fact);

}

int factorial (int n)

{

int result;

if (n == 0)

return (1);

else

result = n * factorial (n-1);

return (result);

}

(8marks)

Q4.( A) Explain the minimum Spanning Tree

(b) Construct the minimal spanning tree for the graph shown below:

10

1

30

25

4

20

50

45

40

55

35

5

15

(a) A spanning tree for a connected graph is a tree whose vertex set is the same as the

vertex set of the given graph, and whose edge set is a subset of the edge set of the

given graph. i.e., any connected graph will have a spanning tree. (4marks)

(b)

Cost

10

15

20

25

30

35

40

45

50

55

Edge (1, 2) (3, 6) (4, 6) (2, 6) (1, 4) (3, 5) (2, 5) (1, 5) (2, 3) (5, 6)

EDGE

COST

STAGES IN KRUSKALS

ALGORITHM

REMARKS

2)

(1,

10

2

3

the first edge selected. It is included in

the spanning tree.

5

6

(3, 6)

15

2

3

is selected and included in the tree.

5

6

(4, 6)

20

next included in the tree.

2

3

5

6

(2, 6)

25

2

3

considered next and included in the

tree.

5

6

(1, 4)

30

(3, 5)

35

Reject

3

5

is discarded as its inclusion creates a

cycle.

5 is considered and included in the tree

built. This completes the tree.

The cost of the minimal spanning tree is

105.

Q5. Traverse the following binary tree in pre, post, inorder and level order.

A

B

C

E

F

H

Ans:

A, B, D, C, E, G, F, H, I

D, B, G, E, H, I, F, C, A

D, B, A, E, G, C, H, F, I

Level order traversal yields:

A, B, C, D, E, F, G, H, I

(3marks)

Q6. Search for x=4, using binary search on the following 12 elements.

Index

Elements

1

4

2

7

3

8

4

9

5

16

6

20

7

24

8

38

9

39

Ans:

If we are searching for x = 4: (This needs 3 comparisons)

(low = 1, high = 12, mid = 13/2 = 6, check 20 low = 1,

high = 5, mid = 6/2 = 3, check 8

10

45

11

54

12

77

(10 marks)

- Kruskal PascalUploaded byIonut Marin
- D1-87-10Uploaded bypriyajv14
- Seminar on Image Segmentation(09501)Uploaded byHarivardhan Reddy Venumuddala
- 270-1034-1-PBUploaded byJay Bhavsar
- CMSC 27100Uploaded byKaushik Vasudevan
- 0910SEM1-CS1231_2Uploaded bythientrancong
- chap4 (1).pptUploaded bybharathkumar
- AN IMPROVED ALGORITHM FOR CALCULATING THE SUM-OF-FACTORIALS FUNCTIONUploaded byMia Amalia
- Recursive AlgorithmsUploaded byUlysses R. Gotera
- Maple WorksheetUploaded byJohn George
- UNIT_5Uploaded byrudra_mazumdar
- PartitioningUploaded bykavita4123
- Data Structure and AlgorithmUploaded bykarthikeyan50700HR
- arcUploaded byĐurđica Stanojković
- MST_subhajitUploaded bySubhajit Paul
- Sikimeti Ma'u- Quilted Strips, Graph Associahedra and A-Infinity n-ModulesUploaded bySwertyy
- COMUploaded byharpreetbly20101938
- Syllabus for Computer Science and Information Technology (CS) _ GATE 2013Uploaded byVijay Akula
- Article About the Library of Babel (Parts 1 & 2 of 4)Uploaded byMarco Ripà
- Bhn Kuliah 9 - Backtracking and SearchingUploaded byRisky Arisandy
- 2013 001 02 a New Method for Fast Computation of Factorials of NumbersUploaded bySamujjwal Bhowmick
- B55CPPUploaded byDushyant Singh
- Bsit May June 2014Uploaded byPiyush Priyank
- csc121Uploaded byIvan Chiu
- CSE-IInd_yr_lab_prog(1)Uploaded bykarthickamsec
- Chapter 11 MalikUploaded byDewi Agust Soe
- Application of Computer Based Simulation in Gas Network SystemUploaded byMartin Martin Martin
- 00 Course PlanUploaded byRaJu SinGh
- part1.1-3.pdfUploaded byJeetendra Kumar
- ABCUploaded bysheetal taneja

- Physical v Chemical ChangeUploaded byEric Leo Asiamah
- MICROPROCESSORSascheame.docxUploaded byEric Leo Asiamah
- Lab. N1Uploaded byEric Leo Asiamah
- Data Communication Bsc He a MeUploaded byEric Leo Asiamah
- 01_Basic Computer Structure(20070122)Uploaded byKanwar Deep
- Database Concept and Tech 1 Bsc He a MeUploaded byEric Leo Asiamah
- Networking 1 Bsc He a MeUploaded byEric Leo Asiamah
- Introduction to the Computer 1Uploaded byEric Leo Asiamah
- ivan bayross book.pdfUploaded byVivek Sharma
- Lesson 1(Ictelective)Uploaded byEric Leo Asiamah
- Bece Past Questions Answers 2010 Maths Part1 QustionsUploaded byEric Leo Asiamah
- Data Structure 2 b SchUploaded byEric Leo Asiamah
- Web Based TechascheameUploaded byEric Leo Asiamah
- Classical Control 1Uploaded byEric Leo Asiamah
- LESSON 10(ICTelective).pptxUploaded byEric Leo Asiamah
- CLASSICALCONTROL2scheame.docxUploaded byEric Leo Asiamah
- CLASSICALCONTROL2scheame.docxUploaded byEric Leo Asiamah
- Database Concept and Tech 1 Asche a MeUploaded byEric Leo Asiamah
- Database Concept and Tech 1 Asche a MeUploaded byEric Leo Asiamah
- Database Concept and Tech 1 Bsc He a MeUploaded byEric Leo Asiamah
- Networking 1 Bsc He a MeUploaded byEric Leo Asiamah
- Circuit TheorybscheameUploaded byEric Leo Asiamah
- Classical Control 1 Sche a MeUploaded byEric Leo Asiamah
- WEBTECHbSCHEAMEUploaded byEric Leo Asiamah
- Open Source Opers Ys Asche a MeUploaded byEric Leo Asiamah
- Intro to Computer Arch It u Rebs Che a MeUploaded byEric Leo Asiamah
- Data Structure 2 b SchUploaded byEric Leo Asiamah
- DATACOMMUNICATIONAscheame.docxUploaded byEric Leo Asiamah
- DATACOMMUNICATIONAscheame.docxUploaded byEric Leo Asiamah

- Standard Shoe Verification Rev_AUploaded byballisnothing
- 2014 SMC SolutionsUploaded bykingkumar5
- bfitUploaded bywaffle_copter
- Astable MultivibratorUploaded bysantovaron123
- Tichy Pavel-1976--CounterExample to the Stalnaker-Lewis Analysis of CounterfactualsUploaded byBankingLinguisticCheckmates
- Sasaki, H., Matsuyama, J., & Sako, K. (2013). the Macroeconomic Effects of the Wage Gap Between Regular and Non-regular Employment and of Minimum Wages. Structural Change and Economic Dynamics, 26, 61-72.Uploaded bylcr89
- 37184526 Bio TEch 2007 RegulationsUploaded bySanthana Krishnan
- 2 3 prime and composite numbersUploaded byapi-325053822
- 4-I ECE Radar Systems(9A04703) as Per NBA (1)Uploaded bySavalaNag
- hypoDD45Uploaded byblacklotus21
- Lesson #20 - Dividing Fraction by Fractions - Uncommon DenominatorsUploaded byMR.E
- Divisibility RulesUploaded byDhaniel Calungsod
- 3G RAN Parameter Testing R99Uploaded byNeelesh Kumar Marele
- Cracking in RC AnalysisUploaded bySaroj Kumar Sahu
- The Ultimate Value at RiskUploaded byDr. Jeff Lewis
- 4024_y18_syUploaded byjesudassaj
- 7a Hw-rational NumbersUploaded byEric Morales
- Simulation 062Uploaded bygurpinder.rajgarh1331
- 2004-224-finalUploaded bySuraj Kumar
- Profiling of Mandrel for Rotary ForgingUploaded byDastn
- ShootingMethodTutorialUploaded byashwin802
- Ampacities of underground cablesUploaded bysuzanamg
- Trapezoidal RuleUploaded byRicardo Wan Aguero
- Electrical Engineer; Computer EngineerUploaded byapi-79076860
- Orifices DischargingUploaded byKishan Madhoo
- Topology Optimization of an Additive Layer Manufactured Aerospace PartUploaded byAltairEnlighten
- Statprob Final Assignment 2015Uploaded byRaihan Alisha Nabila
- Uncertainty Analysis 2009Uploaded byMohamed Hamdy
- Basic Questions Related to Thermal EngineeringUploaded byfarukhali
- Salt: The Incremental Chemistry of Language AcquisitionUploaded byYuri Tarnopolsky