You are on page 1of 2

Artificial Intelligence – Fall 2020

Lab 03: Searching and Sorting Algorithms

Duong Thuy Do
duongdt@hanu.edu.vn
This lab helps you to practice Python searching and sorting algorithms.
Exercise 1:
Let users input a list of numbers and an arbitrary number m, then write a Python program
to search for m in that list by implementing:
- Linear search
- Iterative Binary search
- Recursive Binary search
Exercise 2:
Write a Python program to sort a list of student names in class input by users. Let users
choose to sort by first name or last name, then sort names ascendingly by implementing:
- Bubble sort
- Insertion sort
- Selection sort
- Merge sort
Exercise 3:
Using Python built-in sort(), sorted() or lambda() method to sort the following:
3.1. Sort a dictionary by value ascendingly. If items have the same value, they are then
sorted by key. Note: The keys are unique within the dictionary while the values may be
not.
3.2. Sort a list of strings by the string length in descending order
3.3. Sort a list of strings in alphabetical order
3.4. Given phone book data in a list of dictionaries. Sort the phone book by the order:
last name (‘last’), then first name (‘first’).
E.g: The given phone book:
accounts = [{‘first’: ‘dong, ‘last’: ‘nguyen’, ‘email’: ‘nguyendong@gmail.com’},
{‘first’: ‘yen’, ‘last’: ‘do’, ‘email’: ‘doyen@yahoo.com’}, {‘first’: ‘linh’, ‘last’:
‘nguyen’, ‘email’: ‘nguyenlinh@hanu.edu.vn’}, {‘first’: ‘hung’, ‘last’: ‘trinh’, ‘email’:
‘trinhhung@hanu.edu.vn’}, {‘first’: ‘loan’, ‘last’: ‘cao’, ‘email’: ‘caoloan@gov.vn’}]

You might also like