Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Information of Technology, Exercises of Information Technology

Some lectures of Data Structures.

Typology: Exercises

2022/2023

Uploaded on 06/02/2023

ly-thanh-hao-fgw-ct
ly-thanh-hao-fgw-ct 🇻🇳

6 documents

Partial preview of the text

Download Information of Technology and more Exercises Information Technology in PDF only on Docsity! PART 1: RECURSIVE 1. Recursive Drawing Write a program that draws the figure below depending on n. Use recursion. Examples Input Output 2 ** * # ## 5 ***** **** *** ** * # ## ### #### ##### Hints Set the bottom of the recursion Define pre- and post- recursive behavior 2. Generating 0/1 Vectors Generate all n-bit vectors of zeroes and ones in lexicographic order. Examples Input Output 3 000 001 010 011 100 101 110 111 5 00000 00001 00010 … 11110 11111 Hints The method should receive as parameters the array which will be our vector and a current index Bottom of recursion should be when the index is outside of the vector To generate all combinations, create a for loop with a recursive call 3 23 1 0 3 1 2 3 0 12 0 3 12 1 3 2 1 23 0 0 123 0 a) Option 1: Solve it with recursive Hint: Use your SinglyLinkedList as a tower to store disks. b) Option 2: Solve it with non-recursive PART 2: RECURSIVE WITH BACKTRACKING 6. Find All Paths in a Labyrinth You are given a labyrinth. Your goal is to find all paths from the start (cell 0, 0) to the exit, marked with 'e'.  Empty cells are marked with a dash '-'  Walls are marked with a star '*' On the first line, you will receive the dimensions of the labyrinth. Next you will receive the actual labyrinth. The order of the paths does not matter. Examples Input Output 3 3 --- -*- --e RRDD DDRR 3 DRRRRU 5 -**-e ----- ***** DRRRUR Hints Create methods for reading and finding all paths in the labyrinth. Create a static list that will hold every direction (basically the path) Finding all paths should be recursive Implement all helper methods that are present in the code above. 7. Queens Puzzle In this lab we will implement a recursive algorithm to solve the "8 Queens" puzzle. Our goal is to write a program to find all possible placements of 8 chess queens on a chessboard, so that no two queens can attack each other (on a row, column or diagonal). Examples Input Output (no input) * - - - - - - - - - - - * - - - - - - - - - - * - - - - - * - - - - * - - - - - - - - - - - * - - * - - - - - - - - - * - - - - * - - - - - - - - - - - - * - - - - - - - - - * - - * - - - - - - - - - - - * - - - - * - - - - - * - - - - - - - - - - * - - - … (90 solutions more) 1. Learn about the "8 Queens" Puzzle Learn about the "8 Queens" puzzle, e.g. from Wikipedia: http://en.wikipedia.org/wiki/Eight_queens_puzzle.