noc20-cs26_Week_04_Assignment_02
noc20-cs26_Week_04_Assignment_02
(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)
reviewer4@nptel.iitm.ac.in
Announcements (announcements)
Week 3: Lists,
inductive 1. Write a Python function frequency(l) that takes as input a list of integers
function and returns a pair of the form (minfreqlist,maxfreqlist) where
definitions, minfreqlist is a list of numbers with minimum frequency in l, sorted in
sorting ascending order
maxfreqlist is a list of numbers with maximum frequency in l, sorted
Week 3 in ascending
Programming For instance
Assignment
>>> frequency([13,12,11,13,14,13,7,11,13,14,12])
https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=93 1/4
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course
([7], [13])
Week 4: Sorting,
Tuples,
>>> frequency([13,12,11,13,14,13,7,11,13,14,12,14,14])
Dictionaries,
Passing ([7], [13, 14])
Functions, List
Comprehension >>> frequency([13,12,11,13,14,13,7,11,13,14,12,14,14,7])
([7, 11, 12], [13, 14])
Week 4 Quiz
Week 4
Programming 2. An airline has assigned each city that it serves a unique numeric code. It
Assignment has collected information about all the direct flights it operates,
represented as a list of pairs of the form (i,j), where i is the code of the
Week 4 starting city and j is the code of the destination.
Programming
Assignment
It now wants to compute all pairs of cities connected by one intermediate
hop --- city i is connected to city j by one intermediate hop if there are
(/noc19_cs40/progassignment?
name=93) direct flights of the form (i,k) and (k,j) for some other city k. The airline is
only interested in one hop flights between different cities --- pairs of the
Week 5: form (i,i) are not useful.
Exception
handling, Write a Python function onehop(l) that takes as input a list of pairs
input/output, file representing direct flights, as described above, and returns a list of all
handling, string pairs (i,j), where i != j, such that i and j are connected by one hop. Note
processing that it may already be the case that there is a direct flight from i to j. So
long as there is an intermediate k with a flight from i to k and from k to j,
Week 5 the list returned by the function should include (i,j). The input list may be in
Programming any order. The pairs in the output list should be in lexicographic
Assignment (dictionary) order. Each pair should be listed exactly once.
For instance
Week 6:
Backtracking, >>> onehop([(2,3),(1,2)])
scope, data [(1, 3)]
structures;
stacks, queues
>>> onehop([(2,3),(1,2),(3,1),(1,3),(3,2),(2,4),(4,1)])
and heaps
[(1, 2), (1, 3), (1, 4), (2, 1), (3, 2), (3, 4), (4, 2), (4, 3)]
Week 6 Quiz
>>> onehop([(1,2),(3,4),(5,6)])
[]
Week 7:
Classes, objects
and user
defined
datatypes Sample Test Cases
Input Output
Week 7 Quiz
frequency([17322,271898,3
Week 8: Test 74,374,374,423432423,4234
Dynamic Case 32423,423432423,42343242 ([17322, 271898], [5325])
programming, 1 3,5325,5325,5325,5325,532
wrap-up 5])
Week 8 Test
frequency([17322,374,1732 ([374, 17322], [374, 1732
Programming Case
2,374,17322,374]) 2])
Assignment 2
https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=93 2/4
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course
Test
Download
Case frequency([9842]) ([9842], [9842])
videos
3
Test
Online frequency([-17322,-374,-1 ([-17322, -374], [-17322,
Programming Case
7322,-374,-17322,-374]) -374])
Test 1, 26 Sep 5
2019, 09:30- Test
onehop([(1,3),(1,2),(2, [(1, 2), (1, 3), (2, 1),
11:30 Case
3),(2,1),(3,2),(3,1)]) (2, 3), (3, 1), (3, 2)]
6
Online
onehop([(1, 2), (1, 3),
Programming [(1, 2), (1, 3), (1, 4),
Test 2, 26 Sep (1, 4), (1, 5), (1, 6),
(1, 5), (1, 6), (1, 7),
2019, 20:00- (1, 7), (1, 8), (1, 9),
(1, 8), (1, 9), (2, 1),
22:00 (2, 1), (2, 3), (2, 4),
(2, 3), (2, 4), (2, 5),
(2, 5), (2, 6), (2, 7),
(2, 6), (2, 7), (2, 8),
(2, 8), (2, 9), (3, 1),
(2, 9), (3, 1), (3, 2),
(3, 2), (3, 4), (3, 5),
(3, 4), (3, 5), (3, 6),
(3, 6), (3, 7), (3, 8),
(3, 7), (3, 8), (3, 9),
(3, 9), (4, 1), (4, 2),
(4, 1), (4, 2), (4, 3),
(4, 3), (4, 5), (4, 6),
(4, 5), (4, 6), (4, 7),
(4, 7), (4, 8), (4, 9),
(4, 8), (4, 9), (5, 1),
Test (5, 1), (5, 2), (5, 3),
(5, 2), (5, 3), (5, 4),
Case (5, 4), (5, 6), (5, 7),
(5, 6), (5, 7), (5, 8),
7 (5, 8), (5, 9), (6, 1),
(5, 9), (6, 1), (6, 2),
(6, 2), (6, 3), (6, 4),
(6, 3), (6, 4), (6, 5),
(6, 5), (6, 7), (6, 8),
(6, 7), (6, 8), (6, 9),
(6, 9), (7, 1), (7, 2),
(7, 1), (7, 2), (7, 3),
(7, 3), (7, 4), (7, 5),
(7, 4), (7, 5), (7, 6),
(7, 6), (7, 8), (7, 9),
(7, 8), (7, 9), (8, 1),
(8, 1), (8, 2), (8, 3),
(8, 2), (8, 3), (8, 4),
(8, 4), (8, 5), (8, 6),
(8, 5), (8, 6), (8, 7),
(8, 7), (8, 9), (9, 1),
(8, 9), (9, 1), (9, 2),
(9, 2), (9, 3), (9, 4),
(9, 3), (9, 4), (9, 5),
(9, 5), (9, 6), (9, 7),
(9, 6), (9, 7), (9, 8)]
(9, 8)])
Test
onehop([(1,2),(2,3),(3, [(1, 3), (2, 4), (3, 5),
Case
4),(4,5),(5,1)]) (4, 1), (5, 2)]
8
Test
onehop([(1,2),(2,1),(3,
Case []
4),(4,3)])
10
https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=93 3/4
02/07/2020 Programming, Data Structures And Algorithms Using Python - Course
Test
frequency([1,2,3,4,5,5,4,
Case ([1], [5])
3,2,3,4,5,5,4,5])
11
Test
frequency([4,4,4,1,1,2,2,
Case ([1, 3], [2, 4])
2,3,3])
12
Test
Case frequency([1,1,1,1,1]) ([1], [1])
13
Test
Case onehop([(1,2),(2,1)]) []
14
Test
Case onehop([(1,2)]) []
15
Test
onehop([(1,3),(1,2),(2, [(1, 2), (1, 3), (2, 1),
Case
3),(2,1),(3,2),(3,1)]) (2, 3), (3, 1), (3, 2)]
16
https://onlinecourses.nptel.ac.in/noc19_cs40/progassignment?name=93 4/4